UNPKG

2.87 kBJavaScriptView Raw
1const cpr = require('cpr')
2const path = require('path')
3const fs = require('fs')
4
5const hbsTemplatePath = path.join(__dirname, '../tiresias-hbs-template')
6const customTemplatePath = path.join(__dirname, '../tiresias-custom-template')
7const createDirPath = path.join(process.cwd(), './tiresias-hbs-project-template')
8
9function copyProjectFiles (config, callback) {
10 console.log('copying project files...')
11 cpr(config.rootDir || hbsTemplatePath, config.distDir, {
12 deleteFirst: true, //Delete "to" before
13 overwrite: true, //If the file exists, overwrite it
14 confirm: true //After the copy, stat all the copied files to make sure they are there
15 }, (err, files) => {
16 if (typeof callback === 'function') {
17 callback(err, files)
18 }
19 })
20}
21
22function createProject (action, projectConfig, callback) {
23 var config = {}
24 config.rootDir = hbsTemplatePath
25 config.distDir = createDirPath
26 if (typeof action !== 'string') {
27 callback = projectConfig
28 projectConfig = action
29 }
30 config = Object.assign({}, config, projectConfig)
31
32 if (typeof action === 'string') {
33 if (action === 'hbs') {
34 copyProjectFiles(config, (err, files) => {
35 callback && callback(err, files)
36 if (err) {
37 throw err
38 } else {
39 console.log(files.join(',\n'))
40 console.log('proejct [hbs] files copied!')
41 }
42 })
43 }
44
45 if (action === 'custom') {
46 config.rootDir = customTemplatePath
47
48 var newConfig = Object.assign({}, config)
49 newConfig.rootDir = path.join(config.rootDir, './tiresias-custom-server')
50 newConfig.distDir = path.join(config.distDir, './tiresias-custom-server')
51
52 copyProjectFiles(newConfig, (err, files) => {
53 callback && callback(err, files)
54 if (err) {
55 throw err
56 } else {
57 console.log(files.join(',\n'))
58 console.log('proejct [custom] server files copied!')
59
60 var newConfig = Object.assign({}, config)
61 newConfig.rootDir = path.join(config.rootDir, './tiresias-custom-webpack')
62 newConfig.distDir = path.join(config.distDir, './tiresias-custom-webpack')
63
64 copyProjectFiles(newConfig, (err, files) => {
65 callback && callback(err, files)
66 if (err) {
67 throw err
68 } else {
69 console.log(files.join(',\n'))
70 console.log('proejct [custom] webpack files copied!')
71 console.log('proejct [custom] ready!')
72 }
73 })
74
75
76
77 }
78 })
79 }
80 } else {
81 copyProjectFiles(config, (err, files) => {
82 callback && callback(err, files)
83 if (err) {
84 throw err
85 } else {
86 console.log(files.join(',\n'))
87 console.log('proejct files copied!')
88 }
89 })
90 }
91}
92
93module.exports = createProject
94
95