index.js
//Create a project following the template in the working directory with the specified name
Create a project following the template in the working directory with the specified name
Create a project following the template in the working directory with the specified name
function createProject(projectName) {
        if (projectName === undefined) {
            console.log("No name was specified for the project");
            return;
        }
        function createFolder(path, folder) {
            path = path + "/" + folder.name;
            try {
                fs.mkdirSync(rootPath + path);
            } catch (e) {
            }
            if (folder.folders) {
                folder.folders.forEach(createFolder.bind(null, path));
            }
        }
        var newProject = require('./template/newProject.js');
        newProject.folders.forEach(createFolder.bind(null, ""));
        newProject.files.forEach(function (file) {
            fs.readFile(__dirname + "/" + file.file, 'base64', function (err, data) {
                if (err) {
                    return console.log(err);
                }
                if (file.template) {
                    var b = new Buffer(data, 'base64');
                    var content = b.toString().replace("#projectName#", projectName);
                    b = new Buffer(content);
                    data = b.toString('base64');
                }
                fs.writeFile(rootPath + file.name, data, 'base64', function (err) {
                    if (err) throw err;
                });
            });
        });
    }
function createProject ( projectName ) { if ( projectName === undefined ) { console . log ( "No name was specified for the project" ) ; return ; } function createFolder ( path , folder ) { path = path + "/" + folder . name ; try { fs . mkdirSync ( rootPath + path ) ; } catch ( e ) { } if ( folder . folders ) { folder . folders . forEach ( createFolder . bind ( null , path ) ) ; } } var newProject = require ( './template/newProject.js' ) ; newProject . folders . forEach ( createFolder . bind ( null , "" ) ) ; newProject . files . forEach ( function ( file ) { fs . readFile ( __dirname + "/" + file . file , 'base64' , function ( err , data ) { if ( err ) { return console . log ( err ) ; } if ( file . template ) { var b = new Buffer ( data , 'base64' ) ; var content = b . toString ( ) . replace ( "#projectName#" , projectName ) ; b = new Buffer ( content ) ; data = b . toString ( 'base64' ) ; } fs . writeFile ( rootPath + file . name , data , 'base64' , function ( err ) { if ( err ) throw err ; } ) ; } ) ; } ) ; }
Create a project following the template in the working directory with the specified name
Create a project following the template in the working directory with the specified name