Skip to content

Commit

Permalink
moving from exec to node:fs (#348)
Browse files Browse the repository at this point in the history
* moving from exec to node:fs
fixes #291

* eslint fixes
  • Loading branch information
Idrinth authored Feb 22, 2024
1 parent 842f0ec commit 59690e8
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 4 deletions.
3 changes: 2 additions & 1 deletion tools/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
import {
EXIT_FAILURE,
EXIT_SUCCESS,
INDENTATION,
} from './src/constants.js';

const rl = readline.createInterface({
Expand Down Expand Up @@ -38,7 +39,7 @@ rl.question(
writeFileSync(
process.cwd() + file,
// eslint-disable-next-line no-undefined
JSON.stringify(data, undefined, 2,),
JSON.stringify(data, undefined, INDENTATION,),
);
}
exec(
Expand Down
51 changes: 48 additions & 3 deletions tools/regression.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,58 @@
import exec from './src/exec.js';
import {
readdirSync,
readFileSync,
writeFileSync,
unlinkSync,
rmdirSync,
mkdirSync,
statSync,
existsSync,
} from 'fs';

const copy = (from, to,) => {
if (! existsSync(process.cwd() + to,)) {
mkdirSync(process.cwd() + to,);
}
for (const file of readdirSync(process.cwd() + from, {
encoding: 'utf8',
},)) {
const data = statSync(process.cwd() + from,);
if (data.isDirectory()) {
copy(from + '/' + file, to + '/' + file,);
} else {
writeFileSync(
process.cwd() + to + '/' + file,
readFileSync(process.cwd() + from + '/' + file, 'utf8',),
'utf8',
);
}
}
};
const rm = (dir,) => {
if (! existsSync(process.cwd() + dir,)) {
return;
}
for (const file of readdirSync(process.cwd() + dir, {
encoding: 'utf8',
},)) {
const data = statSync(process.cwd() + dir,);
if (data.isDirectory()) {
rm(dir + '/' + file,);
} else {
unlinkSync(process.cwd() + dir + '/' + file,);
}
}
rmdirSync(process.cwd() + dir,);
};

exec('cd framework && npm install && npm run tsc', true,);
for (const folder of readdirSync(process.cwd() + '/examples')) {
for (const folder of readdirSync(process.cwd() + '/examples', {
encoding: 'utf8',
},)) {
if (folder !== '.eslintrc.yml') {
exec(`cd examples/${ folder } && npm install`, true,);
exec(`cp -r ${ process.cwd() }/framework/* ${ process.cwd() }/examples/${ folder }/node_modules/@idrinth/api-bench/`, true,);
exec(`rm -r ${ process.cwd() }/examples/${ folder }/node_modules/@idrinth/api-bench/node_modules`, true,);
rm(`/examples/${ folder }/node_modules/@idrinth/api-bench`,);
copy('/framework', `/examples/${ folder }`,);
}
}
1 change: 1 addition & 0 deletions tools/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export const ARRAY_FIRST = 0;
export const ARRAY_SECOND = 1;
export const EXIT_SUCCESS = 0;
export const EXIT_FAILURE = 1;
export const INDENTATION = 2;

0 comments on commit 59690e8

Please sign in to comment.