UNPKG

2.31 kBJavaScriptView Raw
1#!/usr/bin/env node
2
3let os = require('os');
4let fs = require('fs');
5let ncp = require('ncp').ncp;
6let path = require('path');
7let term = require('terminal-kit').terminal;
8
9//
10// 1. Get the full path of the app being executed
11//
12let app_path = process.argv[1].split('/');
13
14//
15// 2. The first provided argument by the user is the destination
16//
17let destination = process.argv[2];
18
19//
20// 3. Make sure the destination was provided by the user
21//
22if(!destination)
23{
24 //
25 // 1. Give the user an example how to use the app.
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 // -> Exit the app if error.
34 //
35 process.exit(1);
36}
37
38//
39// 4. Tell the user what to do.
40//
41term.yellow('\n');
42term.yellow('Which template should I deploy?\n');
43
44//
45// 5. A list of all the templates that we support
46//
47let items = [
48 '1. Website',
49 '2. API'
50];
51
52//
53// 6. The real names of the folders inside the Source folder
54//
55let folder_names = ['website', 'api'];
56
57//
58// 7. React to what the user selected
59//
60term.singleColumnMenu(items, function(error, response) {
61
62 //
63 // 1. Get the folder name based on the user selection
64 //
65 let seelcted_folder = folder_names[response.selectedIndex]
66
67 //
68 // 2. Create the path to the source folder to be copied
69 //
70 // https://docs.npmjs.com/files/folders
71 //
72 let source = "/usr/local/lib/node_modules/express-generator-dg/source/" + seelcted_folder;
73
74 //
75 // 3. We change the path accordingly to the system the app is running
76 //
77 if(os.platform() == 'linux')
78 {
79 source = "/usr/lib/node_modules/express-generator-dg/source/" + seelcted_folder;
80 }
81
82 //
83 // 4. Make the path to the destination location
84 //
85 let target = process.cwd() + "/" + destination
86
87 //
88 // 5. Start copying
89 //
90 ncp(source, target, function(error) {
91
92 //
93 // 1. Check if an error occurred
94 //
95 if(error)
96 {
97 //
98 // 1. Show the error
99 //
100 term.red('\n');
101 term.red(error[0]);
102 term.red('\n');
103 term.red('\n');
104
105 //
106 // -> Exit the app
107 //
108 process.exit();
109 }
110
111 //
112 // 2. Let the user know the process of coping finished
113 //
114 term.yellow('\n');
115 term.yellow('Done!');
116 term.yellow('\n');
117 term.yellow('\n');
118
119 //
120 // -> Exit the app
121 //
122 process.exit();
123
124 });
125
126});