diff --git a/package.json b/package.json index 0653ccd..6275c5a 100644 --- a/package.json +++ b/package.json @@ -70,9 +70,9 @@ "lint:fix": "eslint . --fix --ext js,ts", "format:check": "prettier --check src/**", "format:fix": "prettier --write src/**", - "desk:build": "node ./scripts/run.mjs build", - "desk:prepare": "node ./scripts/run.mjs prepare", - "desk:run": "node ./scripts/run.mjs run" + "desk:build": "ts-node-esm ./scripts/run.mts build", + "desk:prepare": "ts-node-esm ./scripts/run.mts prepare", + "desk:run": "ts-node-esm ./scripts/run.mts run" }, "dependencies": {}, "devDependencies": { diff --git a/scripts/run.mjs b/scripts/run.mts similarity index 66% rename from scripts/run.mjs rename to scripts/run.mts index 4c1e918..f829cff 100644 --- a/scripts/run.mjs +++ b/scripts/run.mts @@ -28,14 +28,14 @@ const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); const pack = await fs.promises.readFile(path.resolve(__dirname, '../package.json')); -const packageJson = JSON.parse(pack); +const packageJson = JSON.parse(pack.toString()); const desktopPath = path.join(__dirname, '..', '..', 'podman-desktop'); -async function exec(command, args, options) { +async function exec(command:string, args: string[] | undefined, options:cp.SpawnOptionsWithoutStdio): Promise { return new Promise((resolve, reject) => { - if(os.platform() === 'win32'){ - if(!options) { + if (os.platform() === 'win32') { + if (!options) { options = {}; } @@ -44,8 +44,8 @@ async function exec(command, args, options) { const proc = cp.spawn(command, args, options); proc.stderr.pipe(process.stderr); proc.stdout.pipe(process.stdout); - proc.on('close', (code) => { - if(code !== 0){ + proc.on('close', code => { + if (code !== 0) { reject(code); return; } @@ -59,9 +59,11 @@ async function exec(command, args, options) { } async function checkAndCloneDesktopRepo() { - if(!fs.existsSync(desktopPath)) { + if (!fs.existsSync(desktopPath)) { console.log('Cloning podman-desktop repository...'); - await exec('git', ['clone', 'https://github.com/containers/podman-desktop.git'], {cwd: path.join(__dirname, '..', '..')}); + await exec('git', ['clone', 'https://github.com/containers/podman-desktop.git'], { + cwd: path.join(__dirname, '..', '..'), + }); } else { console.log('desktop repo already exist...'); } @@ -70,24 +72,24 @@ async function checkAndCloneDesktopRepo() { async function prepareDev() { await checkAndCloneDesktopRepo(); - await exec('yarn',undefined, {cwd: desktopPath }); - await exec('yarn',[], {cwd: path.join(__dirname, '..')}); + await exec('yarn', undefined, { cwd: desktopPath }); + await exec('yarn', [], { cwd: path.join(__dirname, '..') }); } async function buildPD() { - await exec('yarn',['compile:current'], {cwd: desktopPath}); + await exec('yarn', ['compile:current'], { cwd: desktopPath }); } async function buildCrc() { - await exec('yarn',['build'], {cwd: path.join(__dirname, '..')}); + await exec('yarn', ['build'], { cwd: path.join(__dirname, '..') }); const pluginsPath = path.resolve(os.homedir(), `.local/share/containers/podman-desktop/plugins/${packageJson.name}/`); fs.rmSync(pluginsPath, { recursive: true, force: true }); - fs.mkdirSync(pluginsPath, {recursive: true}); - fs.cpSync(path.resolve(__dirname,'..', 'package.json'), pluginsPath + '/package.json'); - fs.cpSync(path.resolve(__dirname,'..', 'dist'), pluginsPath + '/dist', {recursive: true}); - fs.cpSync(path.resolve(__dirname,'..', 'icon.png'), pluginsPath + '/icon.png'); + fs.mkdirSync(pluginsPath, { recursive: true }); + fs.cpSync(path.resolve(__dirname, '..', 'package.json'), pluginsPath + '/package.json'); + fs.cpSync(path.resolve(__dirname, '..', 'dist'), pluginsPath + '/dist', { recursive: true }); + fs.cpSync(path.resolve(__dirname, '..', 'icon.png'), pluginsPath + '/icon.png'); } async function build() { @@ -97,17 +99,17 @@ async function build() { async function run() { await buildCrc(); - await exec('yarn', ['watch'], {cwd: desktopPath}); + await exec('yarn', ['watch'], { cwd: desktopPath }); } async function debug() { - exec('yarn', ['watch'], {cwd: path.join(__dirname, '..')}); - await exec('yarn', ['watch', '--extension-folder', path.join(__dirname, '..')], {cwd: desktopPath}); + exec('yarn', ['watch'], { cwd: path.join(__dirname, '..') }); + await exec('yarn', ['watch', '--extension-folder', path.join(__dirname, '..')], { cwd: desktopPath }); } const firstArg = process.argv[2]; -switch(firstArg) { +switch (firstArg) { case 'build': await build(); break; @@ -119,7 +121,7 @@ switch(firstArg) { await debug(); break; - case 'prepare' : + case 'prepare': default: await prepareDev(); }