1 | #!/usr/bin/env node
|
2 |
|
3 | let os = require('os');
|
4 | let fs = require('fs');
|
5 | let ncp = require('ncp').ncp;
|
6 | let path = require('path');
|
7 | let term = require('terminal-kit').terminal;
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | let app_path = process.argv[1].split('/');
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | let destination = process.argv[2];
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | if(!destination)
|
23 | {
|
24 |
|
25 |
|
26 |
|
27 | term.brightWhite("Missing argument!\n");
|
28 | term.brightWhite('\n');
|
29 | term.yellow("\tExample: express-generator-dg DESTINATION_FOLDER \n");
|
30 | term.brightWhite('\n');
|
31 |
|
32 |
|
33 |
|
34 |
|
35 | process.exit(1);
|
36 | }
|
37 |
|
38 |
|
39 |
|
40 |
|
41 | term.yellow('\n');
|
42 | term.yellow('Which template should I deploy?\n');
|
43 |
|
44 |
|
45 |
|
46 |
|
47 | let items = [
|
48 | '1. Website',
|
49 | '2. API'
|
50 | ];
|
51 |
|
52 |
|
53 |
|
54 |
|
55 | let folder_names = ['website', 'api'];
|
56 |
|
57 |
|
58 |
|
59 |
|
60 | term.singleColumnMenu(items, function(error, response) {
|
61 |
|
62 |
|
63 |
|
64 |
|
65 | let seelcted_folder = folder_names[response.selectedIndex]
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 | let source = "/usr/local/lib/node_modules/express-generator-dg/source/" + seelcted_folder;
|
73 |
|
74 |
|
75 |
|
76 |
|
77 | if(os.platform() == 'linux')
|
78 | {
|
79 | source = "/usr/lib/node_modules/express-generator-dg/source/" + seelcted_folder;
|
80 | }
|
81 |
|
82 |
|
83 |
|
84 |
|
85 | let target = process.cwd() + "/" + destination
|
86 |
|
87 |
|
88 |
|
89 |
|
90 | ncp(source, target, function(error) {
|
91 |
|
92 |
|
93 |
|
94 |
|
95 | if(error)
|
96 | {
|
97 |
|
98 |
|
99 |
|
100 | term.red('\n');
|
101 | term.red(error[0]);
|
102 | term.red('\n');
|
103 | term.red('\n');
|
104 |
|
105 |
|
106 |
|
107 |
|
108 | process.exit();
|
109 | }
|
110 |
|
111 |
|
112 |
|
113 |
|
114 | term.yellow('\n');
|
115 | term.yellow('Done!');
|
116 | term.yellow('\n');
|
117 | term.yellow('\n');
|
118 |
|
119 |
|
120 |
|
121 |
|
122 | process.exit();
|
123 |
|
124 | });
|
125 |
|
126 | });
|