1 | #!/usr/bin/env node
|
2 | const fs = require('fs');
|
3 | const path = require('path');
|
4 | const chalk = require('chalk');
|
5 | const ora = require('ora');
|
6 | const projectSetup = require('./lib/setup');
|
7 | const codeTools = require('./lib/code-tools');
|
8 | const executeTools = require('./lib/execute-tool');
|
9 |
|
10 | const 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 |
|
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 | }
|
38 | const 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 | }
|
46 | const getSupportApplications = async() =>{
|
47 | return projectSetup.getSupportApplications();
|
48 | }
|
49 | module.exports.getSupportApplications = getSupportApplications;
|
50 | module.exports.getTempWorkPath = getTempWorkPath;
|
51 | module.exports.createProject = createProject;
|