Skip to content

Commit

Permalink
Use TS for scripts
Browse files Browse the repository at this point in the history
Signed-off-by: Yevhen Vydolob <[email protected]>
  • Loading branch information
evidolob committed May 18, 2023
1 parent 771e38e commit b5dee93
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 24 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
44 changes: 23 additions & 21 deletions scripts/run.mjs → scripts/run.mts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
return new Promise((resolve, reject) => {
if(os.platform() === 'win32'){
if(!options) {
if (os.platform() === 'win32') {
if (!options) {
options = {};
}

Expand All @@ -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;
}
Expand All @@ -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...');
}
Expand All @@ -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() {
Expand All @@ -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;
Expand All @@ -119,7 +121,7 @@ switch(firstArg) {
await debug();
break;

case 'prepare' :
case 'prepare':
default:
await prepareDev();
}

0 comments on commit b5dee93

Please sign in to comment.