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