c-mdui-a
Version:
A fast way to build an application based on Material Design UI(MDUI).
67 lines (62 loc) • 1.73 kB
JavaScript
/**
* @file cli.js
* @author S·c
* @copyright MIT License
*/
//================================================================
//useful funcions
copyDir = ()=>{};
/**
*
* @param source {string} dir/file to copy
* @param target {string} destination
* @function copyDir
*/
copyDir = (source,target)=>{
if (fs.statSync(source).isFile()){
fs.copyFileSync(source,target);
return;
}else if(fs.statSync(source).isDirectory()){
if(!fs.existsSync(target)){
fs.mkdirSync(target, 777);
}
fs.readdirSync(source).forEach((value,index) =>{
copyDir(`${source}/${value}`,`${target}/${value}`);
})
}
};
const {exec} = require("child_process");
/**
* @param url {string} the url to open in browser
* @function oprnFile
*/
openFile = url=> {
switch (process.platform) {
case "darwin":
exec(`open ${url}`);
break;
case "win32":
exec(`start ${url}`);
break;
default:
exec(`xdg-open ${url}`);
}
}
//================================================================
//import statments
const fs = require('fs');
const path = require('path');
/**
* @function main The entry point of cli
*/
(function main(){
const working_dir = process.cwd();
const package_dir = __dirname;
const s = [];
console.log(`Creating MDUI Web Application in ${working_dir}...\n`);
copyDir(`${package_dir}/docs`,`${working_dir}/docs`);
copyDir(`${package_dir}/template`,`${working_dir}/`);
openFile(`${working_dir}/docs/index.html`);
console.log(`Finished\n`);
})();