Created
February 21, 2020 03:51
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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