scripts: convert to ESM and deduplicate #290
8 changed files with 93 additions and 82 deletions
|
@ -18,7 +18,7 @@
|
|||
"migrateandstart": "yarn migrate && yarn start",
|
||||
"gulp": "gulp build",
|
||||
"watch": "yarn dev",
|
||||
"dev": "node ./scripts/dev.js",
|
||||
"dev": "node ./scripts/dev.mjs",
|
||||
"lint": "yarn workspaces foreach run lint",
|
||||
"cy:open": "cypress open --browser --e2e --config-file=cypress.config.ts",
|
||||
"cy:run": "cypress run",
|
||||
|
@ -26,8 +26,8 @@
|
|||
"mocha": "yarn workspace backend run mocha",
|
||||
"test": "yarn mocha",
|
||||
"format": "gulp format",
|
||||
"clean": "node ./scripts/clean.js",
|
||||
"clean-all": "node ./scripts/clean-all.js",
|
||||
"clean": "node ./scripts/clean.mjs",
|
||||
"clean-all": "node ./scripts/clean-all.mjs",
|
||||
"cleanall": "yarn clean-all"
|
||||
},
|
||||
"resolutions": {
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
const fs = require('fs');
|
||||
|
||||
fs.rmSync(__dirname + '/../packages/backend/built', { recursive: true, force: true });
|
||||
fs.rmSync(__dirname + '/../packages/backend/tsconfig.tsbuildinfo', { force: true });
|
||||
fs.rmSync(__dirname + '/../packages/backend/node_modules', { recursive: true, force: true });
|
||||
|
||||
fs.rmSync(__dirname + '/../packages/client/built', { recursive: true, force: true });
|
||||
fs.rmSync(__dirname + '/../packages/client/node_modules', { recursive: true, force: true });
|
||||
|
||||
fs.rmSync(__dirname + '/../packages/foundkey-js/built', { recursive: true, force: true });
|
||||
fs.rmSync(__dirname + '/../packages/foundkey-js/node_modules', { recursive: true, force: true });
|
||||
|
||||
fs.rmSync(__dirname + '/../packages/sw/built', { recursive: true, force: true });
|
||||
fs.rmSync(__dirname + '/../packages/sw/node_modules', { recursive: true, force: true });
|
||||
|
||||
fs.rmSync(__dirname + '/../built', { recursive: true, force: true });
|
||||
fs.rmSync(__dirname + '/../node_modules', { recursive: true, force: true });
|
14
scripts/clean-all.mjs
Normal file
14
scripts/clean-all.mjs
Normal file
|
@ -0,0 +1,14 @@
|
|||
import { files, clean } from './clean.mjs';
|
||||
|
||||
const allFiles = [
|
||||
...files,
|
||||
'/../packages/backend/node_modules',
|
||||
'/../packages/client/node_modules',
|
||||
'/../packages/foundkey-js/node_modules',
|
||||
'/../packages/sw/node_modules',
|
||||
'/../node_modules',
|
||||
];
|
||||
|
||||
for (const file of allFiles) {
|
||||
clean(file);
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
const fs = require('fs');
|
||||
|
||||
fs.rmSync(__dirname + '/../packages/backend/built', { recursive: true, force: true });
|
||||
fs.rmSync(__dirname + '/../packages/backend/tsconfig.tsbuildinfo', { force: true });
|
||||
fs.rmSync(__dirname + '/../packages/client/built', { recursive: true, force: true });
|
||||
fs.rmSync(__dirname + '/../packages/foundkey-js/built', { recursive: true, force: true });
|
||||
fs.rmSync(__dirname + '/../packages/sw/built', { recursive: true, force: true });
|
||||
fs.rmSync(__dirname + '/../built', { recursive: true, force: true });
|
19
scripts/clean.mjs
Normal file
19
scripts/clean.mjs
Normal file
|
@ -0,0 +1,19 @@
|
|||
import { rmSync } from 'fs';
|
||||
import { __dirname } from './common.mjs';
|
||||
|
||||
export const files = [
|
||||
'/../packages/backend/built',
|
||||
'/../packages/backend/tsconfig.tsbuildinfo',
|
||||
'/../packages/client/built',
|
||||
'/../packages/foundkey-js/built',
|
||||
'/../packages/sw/built',
|
||||
'/../built',
|
||||
];
|
||||
|
||||
export function clean(filename) {
|
||||
rmSync(__dirname + filename, { recursive: true, force: true });
|
||||
}
|
||||
|
||||
for (const file of files) {
|
||||
clean(file);
|
||||
}
|
5
scripts/common.mjs
Normal file
5
scripts/common.mjs
Normal file
|
@ -0,0 +1,5 @@
|
|||
import { fileURLToPath } from 'node:url';
|
||||
import { dirname } from 'node:path';
|
||||
|
||||
export const __filename = fileURLToPath(import.meta.url);
|
||||
export const __dirname = dirname(__filename);
|
|
@ -1,54 +0,0 @@
|
|||
const execa = require('execa');
|
||||
|
||||
(async () => {
|
||||
await execa('npm', ['run', 'clean'], {
|
||||
cwd: __dirname + '/../',
|
||||
stdout: process.stdout,
|
||||
stderr: process.stderr,
|
||||
});
|
||||
|
||||
await execa('npm', ['run', 'build'], {
|
||||
cwd: __dirname + '/../packages/foundkey-js',
|
||||
stdout: process.stdout,
|
||||
stderr: process.stderr,
|
||||
});
|
||||
|
||||
execa('npx', ['gulp', 'watch'], {
|
||||
cwd: __dirname + '/../',
|
||||
stdout: process.stdout,
|
||||
stderr: process.stderr,
|
||||
});
|
||||
|
||||
execa('npm', ['run', 'watch'], {
|
||||
cwd: __dirname + '/../packages/backend',
|
||||
stdout: process.stdout,
|
||||
stderr: process.stderr,
|
||||
});
|
||||
|
||||
execa('npm', ['run', 'watch'], {
|
||||
cwd: __dirname + '/../packages/client',
|
||||
stdout: process.stdout,
|
||||
stderr: process.stderr,
|
||||
});
|
||||
|
||||
execa('npm', ['run', 'watch'], {
|
||||
cwd: __dirname + '/../packages/sw',
|
||||
stdout: process.stdout,
|
||||
stderr: process.stderr,
|
||||
});
|
||||
|
||||
const start = async () => {
|
||||
try {
|
||||
await execa('npm', ['run', 'start'], {
|
||||
cwd: __dirname + '/../',
|
||||
stdout: process.stdout,
|
||||
stderr: process.stderr,
|
||||
});
|
||||
} catch (e) {
|
||||
await new Promise(resolve => setTimeout(resolve, 3000));
|
||||
start();
|
||||
}
|
||||
};
|
||||
|
||||
start();
|
||||
})();
|
52
scripts/dev.mjs
Normal file
52
scripts/dev.mjs
Normal file
|
@ -0,0 +1,52 @@
|
|||
import execa from 'execa';
|
||||
import { __dirname } from './common.mjs';
|
||||
|
||||
await execa('npm', ['run', 'clean'], {
|
||||
cwd: __dirname + '/../',
|
||||
stdout: process.stdout,
|
||||
stderr: process.stderr,
|
||||
});
|
||||
|
||||
await execa('npm', ['run', 'build'], {
|
||||
cwd: __dirname + '/../packages/foundkey-js',
|
||||
stdout: process.stdout,
|
||||
stderr: process.stderr,
|
||||
});
|
||||
|
||||
execa('npx', ['gulp', 'watch'], {
|
||||
Johann150 marked this conversation as resolved
|
||||
cwd: __dirname + '/../',
|
||||
stdout: process.stdout,
|
||||
stderr: process.stderr,
|
||||
});
|
||||
|
||||
execa('npm', ['run', 'watch'], {
|
||||
cwd: __dirname + '/../packages/backend',
|
||||
stdout: process.stdout,
|
||||
stderr: process.stderr,
|
||||
});
|
||||
|
||||
execa('npm', ['run', 'watch'], {
|
||||
cwd: __dirname + '/../packages/client',
|
||||
stdout: process.stdout,
|
||||
stderr: process.stderr,
|
||||
});
|
||||
|
||||
execa('npm', ['run', 'watch'], {
|
||||
cwd: __dirname + '/../packages/sw',
|
||||
stdout: process.stdout,
|
||||
stderr: process.stderr,
|
||||
});
|
||||
|
||||
const start = async () => {
|
||||
try {
|
||||
await execa('npm', ['run', 'start'], {
|
||||
cwd: __dirname + '/../',
|
||||
stdout: process.stdout,
|
||||
stderr: process.stderr,
|
||||
});
|
||||
} catch (e) {
|
||||
setTimeout(start, 3000);
|
||||
}
|
||||
norm marked this conversation as resolved
Johann150
commented
Can't this be simplified to just Can't this be simplified to just `setTimeout(start, 3000);` ?
Johann150
commented
Hmm I'm not so sure any more but I think the change was fine because Hmm I'm not so sure any more but I think the change was fine because `start` isn't awaited on anyway...
|
||||
};
|
||||
|
||||
start();
|
Loading…
Reference in a new issue
Why are some of these
await
ed and some not?These were the case in the original
dev.js
script, not sure if we should just run all of these processes asynchronously.I think the first two do need the
await
since it doesn't make sense to clean asynchronously and pretty much every package depends onfoundkey-js
being built.The first two produce a result (cleaning out stuff, building things), the non-awaited commands are watchers, where you probably will have a hard time waiting for a result being returned.