UNPKG

project-init-folder

Version:

A package helpful for creating project/File structure for your project.

62 lines (59 loc) 1.64 kB
#!/usr/bin/env node var fs = require('fs') let arr = require('./data') function create() { let c = (err, x) => { if (err) throw err console.log(`Created ${x.FolderName} Succesfully`) } try { console.log('Creating Project at', process.cwd()) let path = process.cwd() for (let x of arr) { if (!fs.existsSync(path + '/' + x.FolderName)) { fs.mkdirSync(path + '/' + x.FolderName) fs.writeFileSync(`${path}/${x.FolderName}/info.txt`, `${x.description}`, (err) => { c(err, x) }) } } console.log('Creating index.js File ....') let description = '//Entry point for your Project' fs.writeFileSync(`${path}/index.js`, `${description}`, (err) => { c(err, x) }) } catch (err) { console.log(err) } } function destroy() { try { console.log('Removing Project at', process.cwd()) let path = process.cwd() fs.rmdir(path, { recursive: true }, err => { if (err) throw err console.log('Project Deleted') }) } catch (err) { console.log(err) } } try { let action = process.argv.splice(2) switch (action[0]) { case 'create': create() break case 'destroy': destroy() break default: console.log('Wrong action passed. Please choose create / destroy') break } } catch (err) { console.log(err) }