UNPKG

1.79 kBJavaScriptView Raw
1#!/usr/bin/env node
2const fs = require('fs');
3const path = require('path');
4const chalk = require('chalk');
5const ora = require('ora');
6const projectSetup = require('./lib/setup');
7const codeTools = require('./lib/code-tools');
8const executeTools = require('./lib/execute-tool');
9
10const createProject = async (configData,workRootPath)=> {
11 let result = true;
12 if (!configData.name){
13 console.log(' *** application name not found!')
14 return "";
15 }
16 const appliationName = configData.name;
17 const templateName = configData.templateName;
18
19 //const USER_HOME = process.env.HOME || process.env.USERPROFILE;
20 const tempPath = path.join(getTempWorkPath(),"/projects");
21
22 if(!workRootPath){
23 workRootPath = path.join(tempPath,appliationName);
24 }
25 if (fs.existsSync(workRootPath)) {
26 console.log('***WARNING!*** Target directory is existed! ');
27 let removeFiles = 'rm -rf ' + workRootPath;
28 if(!executeTools.executeCommand(removeFiles,'remove old files')){
29 return false;
30 };
31 }
32
33 const template = await projectSetup.fetchTemplateConfig(templateName);
34 await projectSetup.initProjectByTemplate(template,configData,workRootPath);
35 return workRootPath;
36
37}
38const getTempWorkPath = () =>{
39 const USER_HOME = process.env.HOME || process.env.USERPROFILE;
40 const tempPath = path.join(USER_HOME,".temp/simple-coder");
41 if (!fs.existsSync(tempPath)) {
42 codeTools.createDirectoryEx(tempPath);
43 }
44 return tempPath;
45}
46const getSupportApplications = async() =>{
47 return projectSetup.getSupportApplications();
48}
49module.exports.getSupportApplications = getSupportApplications;
50module.exports.getTempWorkPath = getTempWorkPath;
51module.exports.createProject = createProject;