99 lines
2.6 KiB
JavaScript
99 lines
2.6 KiB
JavaScript
|
import * as cp from 'child_process';
|
||
|
import * as fs from 'fs';
|
||
|
import * as path from 'path';
|
||
|
import * as url from 'url';
|
||
|
|
||
|
async function runCommand(command, args) {
|
||
|
return new Promise((resolve, reject) => {
|
||
|
const child = cp.spawn(command, args, {
|
||
|
stdio: 'inherit',
|
||
|
shell: true,
|
||
|
});
|
||
|
|
||
|
console.log(`Running command: ${command} ${args.join(' ')}`);
|
||
|
|
||
|
child.on('exit', (code) => {
|
||
|
if (code === 0) {
|
||
|
resolve();
|
||
|
} else {
|
||
|
reject(new Error(`Command failed with code ${code}`));
|
||
|
}
|
||
|
});
|
||
|
|
||
|
child.on('error', (err) => {
|
||
|
console.error(`Failed to start child process: ${err}`);
|
||
|
reject(err);
|
||
|
});
|
||
|
});
|
||
|
}
|
||
|
|
||
|
|
||
|
class PackageStep {
|
||
|
constructor(folder) {
|
||
|
this.folder = folder;
|
||
|
this.packageJson = path.join(folder, 'package.json');
|
||
|
this.packageJsonData = JSON.parse(fs.readFileSync(this.packageJson));
|
||
|
}
|
||
|
|
||
|
modifyPackageJson() { }
|
||
|
|
||
|
async vscePackage() { }
|
||
|
|
||
|
async postSetup() {
|
||
|
console.log('restore workspace...');
|
||
|
await runCommand('git', ['restore', '.']);
|
||
|
await runCommand('git', ['clean', '-fdx', '-e', '*.vsix', '-e', 'node_modules']);
|
||
|
}
|
||
|
|
||
|
async run() {
|
||
|
console.log('modify package.json...');
|
||
|
this.modifyPackageJson();
|
||
|
fs.writeFileSync(this.packageJson, JSON.stringify(this.packageJsonData, null, 2));
|
||
|
await this.vscePackage();
|
||
|
await this.postSetup();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
class KylinIdePackage extends PackageStep {
|
||
|
constructor(folder) {
|
||
|
super(folder);
|
||
|
}
|
||
|
|
||
|
async vscePackage() {
|
||
|
await runCommand('vsce', [
|
||
|
'package',
|
||
|
'-o',
|
||
|
`${this.packageJsonData.name}-Kylin-IDE-${this.packageJsonData.version}.vsix`
|
||
|
]);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
class VSCodePackage extends PackageStep {
|
||
|
constructor(folder) {
|
||
|
super(folder);
|
||
|
}
|
||
|
|
||
|
modifyPackageJson() {
|
||
|
this.packageJsonData.name = 'kylin-debug';
|
||
|
}
|
||
|
|
||
|
async vscePackage() {
|
||
|
await runCommand('vsce', [
|
||
|
'package',
|
||
|
'-o',
|
||
|
`${this.packageJsonData.name}-VSCode-${this.packageJsonData.version}.vsix`
|
||
|
]);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
console.log('clean workspace...');
|
||
|
await runCommand('git', ['clean', '-fdx']);
|
||
|
await runCommand('npm', ['i',]);
|
||
|
const workspace = url.fileURLToPath(new URL('.', import.meta.url));
|
||
|
console.log('run Kylin-IDE package...');
|
||
|
let packageTool = new KylinIdePackage(workspace);
|
||
|
await packageTool.run();
|
||
|
console.log('run VSCode package...');
|
||
|
packageTool = new VSCodePackage(workspace);
|
||
|
await packageTool.run();
|