Skip to content

Commit af2beda

Browse files
committed
generate versionCode for idp
1 parent 0d94be9 commit af2beda

1 file changed

Lines changed: 35 additions & 5 deletions

File tree

packages/vscode-extension/src/packager.ts

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,17 @@ export default class Packager {
8585
return JSON.parse(jsonText);
8686
}
8787

88+
#getVersionCode(): number {
89+
const pkgVersion = this.#packageJson.version;
90+
if (!pkgVersion) {
91+
throw new TypeError(`package.json must contain a "version" field.`);
92+
}
93+
const [ major, minor, patch ] = pkgVersion.split('.')
94+
.map(v => parseInt(v))
95+
.map(v => isNaN(v) ? 0 : v);
96+
return major * 1000000 + minor * 1000 + patch;
97+
}
98+
8899
async pack(onProgressChange?: (progress: number, message: string) => void) {
89100
if (typeof onProgressChange !== 'function') {
90101
onProgressChange = () => { };
@@ -127,11 +138,30 @@ export default class Packager {
127138
const fileOrDir = await fs.promises.stat(filename);
128139
const name = filename.replace(this.#projectRoot, '');
129140
if (fileOrDir.isFile()) {
130-
// append the file.
131-
this.#outArchive.file(filename, {
132-
name,
133-
stats: fileOrDir,
134-
});
141+
if (name === '/package.json') {
142+
// append the package.json.
143+
this.#outArchive.append(
144+
JSON.stringify(
145+
{
146+
...packageJson,
147+
jsar: {
148+
versionCode: this.#getVersionCode(),
149+
},
150+
},
151+
null,
152+
2
153+
),
154+
{
155+
name,
156+
stats: fileOrDir,
157+
});
158+
} else {
159+
// append the file.
160+
this.#outArchive.file(filename, {
161+
name,
162+
stats: fileOrDir,
163+
});
164+
}
135165

136166
// append the md5 hash of this file.
137167
const fileMD5 = await this.#calculateFileMD5(filename);

0 commit comments

Comments
 (0)