Skip to content

Instantly share code, notes, and snippets.

@RinatValiullov
Created February 21, 2020 03:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RinatValiullov/4bb8a1d40d823d93306c593fba35cae1 to your computer and use it in GitHub Desktop.
Save RinatValiullov/4bb8a1d40d823d93306c593fba35cae1 to your computer and use it in GitHub Desktop.
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