Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Move compiled(tsc) js files in parent directories next to `src` dirs. And delete `dist` folder created after compilation in the root directory
const fs = require('fs');
const path = require('path');
const exec = require('child_process').exec;
/*
const createDirectory = dirPath => {
const targetFolder = '/dist';
fs.mkdirSync(process.cwd() + (dirPath + targetFolder), { recursive: true }, (error) => {
if(error) {
console.error(error.message);
} else {
console.log('Done');
}
});
};
const currentDir = path.dirname(__filename);
createDirectory(currentDir);
fs.mkdirSync(`${currentDir}\\dist`);
*/
const buildProjects = (dir) => {
const files = fs.readdirSync(dir)
for (const i in files) {
const name = dir + '/' + files[i];
if (fs.statSync(name).isDirectory() && (name !== './dist' && name !== './node_modules')) {
fs.mkdirSync(`${name}/dist`);
exec(`tsc -b && mv ./dist/${name}/src/app.js ${name}/dist/app.js`, (err, stdout, stderr) => {
if (err) {
console.error(err.message);
return;
}
console.log(`${name} ${stdout || ' - OK'}`);
});
}
}
};
buildProjects('.');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.