not-node 6.1.5 → 6.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/not-cli.mjs +3 -521
- package/package.json +1 -1
- package/src/cli/actions/entity.mjs +33 -0
- package/src/cli/actions/env.mjs +1 -0
- package/src/cli/actions/index.mjs +23 -0
- package/src/cli/actions/module.front.mjs +35 -0
- package/src/cli/actions/module.server.mjs +33 -0
- package/src/cli/actions/nginx.mjs +1 -0
- package/src/cli/actions/pm2.mjs +1 -0
- package/src/cli/actions/project.mjs +146 -0
- package/src/cli/lib/args.mjs +72 -0
- package/src/cli/lib/entity.mjs +46 -0
- package/src/cli/lib/fs.mjs +176 -0
- package/src/cli/lib/log.mjs +25 -0
- package/src/cli/lib/messages.mjs +29 -0
- package/src/cli/lib/module.front.mjs +57 -0
- package/src/cli/lib/module.server.mjs +128 -0
- package/src/cli/lib/opts.mjs +33 -0
- package/src/cli/lib/project.mjs +16 -0
- package/src/cli/lib/structures.mjs +37 -0
- package/src/cli/readers/roles.mjs +2 -2
- package/src/cli/renderers/controllersIndex.mjs +1 -0
- package/playground/.env +0 -16
- package/playground/deploy/production.sh +0 -13
- package/playground/deploy/stage.sh +0 -13
- package/playground/nginx/development.conf +0 -63
- package/playground/nginx/production.conf +0 -63
- package/playground/nginx/stage.conf +0 -63
- package/playground/pm2/development.json +0 -46
- package/playground/pm2/production.json +0 -46
- package/playground/pm2/stage.json +0 -46
- package/playground/site/.babelrc +0 -11
- package/playground/site/.eslintignore +0 -4
- package/playground/site/.eslintrc.json +0 -23
- package/playground/site/app/front/build/admin.css +0 -2
- package/playground/site/app/front/build/admin.js +0 -52420
- package/playground/site/app/front/build/client.css +0 -2
- package/playground/site/app/front/build/client.js +0 -52420
- package/playground/site/app/front/build/guest.css +0 -2
- package/playground/site/app/front/build/guest.js +0 -50916
- package/playground/site/app/front/build/root.css +0 -2
- package/playground/site/app/front/build/root.js +0 -60016
- package/playground/site/app/front/build/user.css +0 -2
- package/playground/site/app/front/build/user.js +0 -52418
- package/playground/site/app/front/build.env.js +0 -15
- package/playground/site/app/front/index.!.js +0 -66
- package/playground/site/app/front/index.admin.js +0 -162
- package/playground/site/app/front/index.client.js +0 -162
- package/playground/site/app/front/index.guest.js +0 -162
- package/playground/site/app/front/index.root.js +0 -226
- package/playground/site/app/front/index.user.js +0 -162
- package/playground/site/app/front/rollup.!.js +0 -70
- package/playground/site/app/front/rollup.admin.js +0 -70
- package/playground/site/app/front/rollup.client.js +0 -70
- package/playground/site/app/front/rollup.guest.js +0 -70
- package/playground/site/app/front/rollup.root.js +0 -70
- package/playground/site/app/front/rollup.user.js +0 -70
- package/playground/site/app/front/src/admin/main/index.js +0 -34
- package/playground/site/app/front/src/client/main/index.js +0 -34
- package/playground/site/app/front/src/common/index.js +0 -40
- package/playground/site/app/front/src/common/ncInit.js +0 -18
- package/playground/site/app/front/src/common/ws.client.main.js +0 -34
- package/playground/site/app/front/src/guest/main/index.js +0 -45
- package/playground/site/app/front/src/root/main/index.js +0 -34
- package/playground/site/app/front/src/user/main/index.js +0 -34
- package/playground/site/app/server/app.js +0 -25
- package/playground/site/app/server/config/common.json +0 -126
- package/playground/site/app/server/config/development.json +0 -33
- package/playground/site/app/server/config/production.json +0 -34
- package/playground/site/app/server/config/stage.json +0 -34
- package/playground/site/app/server/index.js +0 -20
- package/playground/site/app/server/routes/index.js +0 -34
- package/playground/site/app/server/routes/site.js +0 -71
- package/playground/site/app/server/views/admin/foot.pug +0 -1
- package/playground/site/app/server/views/admin/head.pug +0 -7
- package/playground/site/app/server/views/admin/menu.pug +0 -2
- package/playground/site/app/server/views/admin.pug +0 -19
- package/playground/site/app/server/views/dashboard.pug +0 -20
- package/playground/site/app/server/views/index.pug +0 -15
- package/playground/site/app/server/views/parts/header.android.pug +0 -6
- package/playground/site/app/server/views/parts/header.ios.pug +0 -5
- package/playground/site/app/server/views/parts/header.pug +0 -18
- package/playground/site/app/server/views/parts/menu.pug +0 -1
- package/playground/site/app/server/views/parts/overview.pug +0 -2
- package/playground/site/app/server/ws/auth.js +0 -41
- package/playground/site/app/server/ws/index.js +0 -84
- package/playground/site/bin/build.sh +0 -8
- package/playground/site/package.json +0 -85
- package/playground/site/project.manifest.json +0 -37
package/bin/not-cli.mjs
CHANGED
|
@@ -1,528 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const VAR_PREFIX = "__";
|
|
5
|
-
import ejs from "ejs";
|
|
6
|
-
|
|
7
|
-
import { isAbsolute, resolve, join } from "node:path";
|
|
8
|
-
|
|
9
|
-
import { copyFile, constants, mkdir, writeFile } from "node:fs/promises";
|
|
10
|
-
|
|
2
|
+
import { Command } from "commander";
|
|
11
3
|
import { cwd } from "node:process";
|
|
12
4
|
const CWD = cwd();
|
|
13
|
-
import { spawn } from "node:child_process";
|
|
14
5
|
|
|
15
|
-
import
|
|
16
|
-
const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
|
|
6
|
+
import Actions from "../src/cli/actions/index.mjs";
|
|
17
7
|
|
|
18
|
-
import inquirer from "inquirer";
|
|
19
|
-
import { Command, Option } from "commander";
|
|
20
8
|
const program = new Command();
|
|
21
|
-
|
|
22
|
-
//reads vars from user input, provides defaults
|
|
23
|
-
import * as Readers from "../src/cli/readers/index.mjs";
|
|
24
|
-
|
|
25
|
-
import * as Renderers from "../src/cli/renderers/index.mjs";
|
|
26
|
-
//file system structure
|
|
27
|
-
//directories
|
|
28
|
-
//files and information how to render them from which template and with what args with readers names
|
|
29
|
-
import ProjectStructure from "../tmpl/dirs/project.mjs";
|
|
30
|
-
import ApplicationStructure from "../tmpl/dirs/app.mjs";
|
|
31
|
-
import ApplicationServerStructure from "../tmpl/dirs/server.mjs";
|
|
32
|
-
import ApplicationFrontStructure from "../tmpl/dirs/front.mjs";
|
|
33
|
-
import ApplicationStaticStructure from "../tmpl/dirs/static.mjs";
|
|
34
|
-
|
|
35
|
-
import ApplicationModuleServerStructure from "../tmpl/dirs/module.server.mjs";
|
|
36
|
-
import ApplicationModuleServerControllersCommonStructure from "../tmpl/dirs/module.server.controllers.common.mjs";
|
|
37
|
-
|
|
38
|
-
import ApplicationModuleFrontStructure from "../tmpl/dirs/module.front.mjs";
|
|
39
|
-
|
|
40
|
-
import { firstLetterToLower } from "../src/common.js";
|
|
41
|
-
|
|
42
|
-
const ProjectSubStructures = {
|
|
43
|
-
app: ApplicationStructure,
|
|
44
|
-
server: ApplicationServerStructure,
|
|
45
|
-
front: ApplicationFrontStructure,
|
|
46
|
-
static: ApplicationStaticStructure,
|
|
47
|
-
"module.server": ApplicationModuleServerStructure,
|
|
48
|
-
"module.server.controllers.common":
|
|
49
|
-
ApplicationModuleServerControllersCommonStructure,
|
|
50
|
-
"module.front": ApplicationModuleFrontStructure,
|
|
51
|
-
};
|
|
52
|
-
//path to various templates
|
|
53
|
-
const PATH_TMPL = resolve(__dirname, "../tmpl/files");
|
|
54
|
-
const DEFAULT_SERVER_MODULES_SUB_PATH = "./site/app/server/modules";
|
|
55
|
-
const DEFAULT_FRONT_MODULES_SUB_PATH = "./site/app/front/src";
|
|
56
|
-
|
|
57
|
-
let silent = true;
|
|
58
|
-
|
|
59
|
-
async function readArgs(structure, config) {
|
|
60
|
-
let result = {};
|
|
61
|
-
if (Object.hasOwn(structure, "args")) {
|
|
62
|
-
for (let entry of structure.args) {
|
|
63
|
-
if (!Object.hasOwn(config, entry)) {
|
|
64
|
-
!silent &&
|
|
65
|
-
console.log(
|
|
66
|
-
`no ${entry} in config, reading data from user input`
|
|
67
|
-
);
|
|
68
|
-
config[entry] = await Readers[entry](inquirer, config);
|
|
69
|
-
}
|
|
70
|
-
result[entry] = config[entry];
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
//console.log(JSON.stringify(result, null, 4));
|
|
74
|
-
if (Object.hasOwn(structure, "options")) {
|
|
75
|
-
result[TEMPLATE_OPTIONS] = structure.options;
|
|
76
|
-
}
|
|
77
|
-
return result;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
async function renderFile(input, dest, data) {
|
|
81
|
-
!silent && console.log("render", dest);
|
|
82
|
-
const renderedFileContent = await ejs.renderFile(input, data, {
|
|
83
|
-
async: true,
|
|
84
|
-
});
|
|
85
|
-
await writeFile(dest, renderedFileContent);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
async function createFileContent(filePath, structure, config) {
|
|
89
|
-
if (typeof structure == "string") {
|
|
90
|
-
await copyTmplFile(resolve(PATH_TMPL, structure), filePath);
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
if (Object.hasOwn(structure, "tmpl")) {
|
|
94
|
-
const tmplFilePath = resolve(PATH_TMPL, structure.tmpl);
|
|
95
|
-
const data = await readArgs(structure, config);
|
|
96
|
-
await renderFile(tmplFilePath, filePath, data);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
async function copyTmplFile(from, to) {
|
|
101
|
-
try {
|
|
102
|
-
// console.log("cp", from, to);
|
|
103
|
-
await copyFile(from, to, constants.COPYFILE_EXCL);
|
|
104
|
-
} catch {
|
|
105
|
-
//console.error("The file could not be copied", from, to);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
async function createDir(dirPath) {
|
|
110
|
-
try {
|
|
111
|
-
//console.log("mkdir", dirPath);
|
|
112
|
-
await mkdir(dirPath, { recursive: true });
|
|
113
|
-
} catch {
|
|
114
|
-
// console.error("Can't create directory", dirPath);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
function isFilename(name, descr) {
|
|
119
|
-
if (descr.type === "file") {
|
|
120
|
-
return true;
|
|
121
|
-
}
|
|
122
|
-
if (name.startsWith(VAR_PREFIX) && name.endsWith(VAR_PREFIX)) {
|
|
123
|
-
return false;
|
|
124
|
-
}
|
|
125
|
-
return name.indexOf(".") > -1;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
function isVariable(name) {
|
|
129
|
-
return name.startsWith(VAR_PREFIX) && name.endsWith(VAR_PREFIX);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
function getVariableName(name) {
|
|
133
|
-
return name.replace(new RegExp(VAR_PREFIX, "g"), "");
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
function dirRequiresAbsentModules(subStructure, config) {
|
|
137
|
-
return (
|
|
138
|
-
Object.hasOwn(subStructure, "ifModules") &&
|
|
139
|
-
Array.isArray(subStructure.ifModules) &&
|
|
140
|
-
!subStructure.ifModules.every((entry) => config.modules.includes(entry))
|
|
141
|
-
);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
function dirRequiresNotNullArgs(subStructure, config) {
|
|
145
|
-
return (
|
|
146
|
-
Object.hasOwn(subStructure, "ifArgs") &&
|
|
147
|
-
Array.isArray(subStructure.ifArgs) &&
|
|
148
|
-
!subStructure.ifArgs.every((entry) => {
|
|
149
|
-
return Object.hasOwn(config, entry) && config[entry];
|
|
150
|
-
})
|
|
151
|
-
);
|
|
152
|
-
}
|
|
153
|
-
async function createDirContent(dest, structure = {}, config = {}) {
|
|
154
|
-
if (typeof structure === "string") {
|
|
155
|
-
//console.log("need to create sub structure", structure);
|
|
156
|
-
await createDirContent(dest, ProjectSubStructures[structure], config);
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
const dirs = {};
|
|
160
|
-
//creating files first
|
|
161
|
-
for (let entry in structure) {
|
|
162
|
-
const subStructure = structure[entry];
|
|
163
|
-
if (isVariable(entry)) {
|
|
164
|
-
entry = config[getVariableName(entry)];
|
|
165
|
-
}
|
|
166
|
-
if (isFilename(entry, subStructure)) {
|
|
167
|
-
// console.log(dest, entry);
|
|
168
|
-
const filePath = join(dest, entry);
|
|
169
|
-
await createFileContent(filePath, subStructure, config);
|
|
170
|
-
} else {
|
|
171
|
-
dirs[entry] = subStructure;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
//then going deeper
|
|
175
|
-
for (let entry in dirs) {
|
|
176
|
-
const subStructure = dirs[entry];
|
|
177
|
-
const directoryPath = join(dest, entry);
|
|
178
|
-
if (dirRequiresAbsentModules(subStructure, config)) {
|
|
179
|
-
continue;
|
|
180
|
-
}
|
|
181
|
-
if (dirRequiresNotNullArgs(subStructure, config)) {
|
|
182
|
-
continue;
|
|
183
|
-
}
|
|
184
|
-
await createDir(directoryPath);
|
|
185
|
-
if (Object.hasOwn(subStructure, "content")) {
|
|
186
|
-
await createDirContent(directoryPath, subStructure.content, config);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
function entitiesInLayers(layersList = []) {
|
|
192
|
-
return (
|
|
193
|
-
layersList.includes("models") ||
|
|
194
|
-
layersList.includes("routes") ||
|
|
195
|
-
layersList.includes("logics")
|
|
196
|
-
);
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
async function createLayersDirs(modules_dir, layersList, ModuleName) {
|
|
200
|
-
if (layersList.length) {
|
|
201
|
-
await createDir(resolve(modules_dir, ModuleName, "./src"));
|
|
202
|
-
}
|
|
203
|
-
for (let layer of layersList) {
|
|
204
|
-
await createDir(resolve(modules_dir, ModuleName, "./src", layer));
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
async function createServerModule(modules_dir, config) {
|
|
209
|
-
//read module name
|
|
210
|
-
const ModuleName = await Readers.ModuleName(inquirer);
|
|
211
|
-
const moduleName = firstLetterToLower(ModuleName);
|
|
212
|
-
const moduleDir = resolve(modules_dir, ModuleName);
|
|
213
|
-
const moduleConfig = { ...config, moduleName, ModuleName };
|
|
214
|
-
await createDir(moduleDir);
|
|
215
|
-
//console.log(JSON.stringify(moduleConfig, null, 4));
|
|
216
|
-
await createDirContent(
|
|
217
|
-
moduleDir,
|
|
218
|
-
ProjectSubStructures["module.server"],
|
|
219
|
-
moduleConfig
|
|
220
|
-
);
|
|
221
|
-
const layersList = moduleConfig.moduleLayers;
|
|
222
|
-
await createLayersDirs(modules_dir, layersList, ModuleName);
|
|
223
|
-
//list of entities and its presence thru all selected layers
|
|
224
|
-
let entitiesList = [];
|
|
225
|
-
if (entitiesInLayers(layersList)) {
|
|
226
|
-
//should collect all first, to have full list of items for index files imports
|
|
227
|
-
while (await Readers.isUserNeedCreateEntity(inquirer)) {
|
|
228
|
-
const entityData = await Readers.entityData(
|
|
229
|
-
inquirer,
|
|
230
|
-
config,
|
|
231
|
-
layersList
|
|
232
|
-
);
|
|
233
|
-
entitiesList.push(entityData);
|
|
234
|
-
}
|
|
235
|
-
for (let entityData of entitiesList) {
|
|
236
|
-
await renderEntityFiles(
|
|
237
|
-
resolve(moduleDir, "./src"),
|
|
238
|
-
entityData,
|
|
239
|
-
moduleConfig
|
|
240
|
-
);
|
|
241
|
-
}
|
|
242
|
-
if (layersList.includes("controllers")) {
|
|
243
|
-
await renderServerContollersIndexes(
|
|
244
|
-
resolve(moduleDir, "./src"),
|
|
245
|
-
entitiesList,
|
|
246
|
-
moduleConfig
|
|
247
|
-
);
|
|
248
|
-
await renderServerControllersCommons(
|
|
249
|
-
resolve(moduleDir, "./src/controllers"),
|
|
250
|
-
entitiesList,
|
|
251
|
-
moduleConfig
|
|
252
|
-
);
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
async function renderEntityFiles(module_src_dir, data, config) {
|
|
258
|
-
for (let layerName of data.layers) {
|
|
259
|
-
if (Object.hasOwn(Renderers, layerName)) {
|
|
260
|
-
await Renderers[layerName](
|
|
261
|
-
resolve(module_src_dir, `./${layerName}`),
|
|
262
|
-
data,
|
|
263
|
-
config,
|
|
264
|
-
renderFile,
|
|
265
|
-
PATH_TMPL,
|
|
266
|
-
createDir
|
|
267
|
-
);
|
|
268
|
-
} else {
|
|
269
|
-
console.error("No renderer for layer: ", layerName);
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
async function renderServerContollersIndexes(
|
|
275
|
-
module_src_dir,
|
|
276
|
-
entitiesData,
|
|
277
|
-
config
|
|
278
|
-
) {
|
|
279
|
-
const subDirList = [...config.roles];
|
|
280
|
-
for (let dirName of subDirList) {
|
|
281
|
-
await Renderers.controllersIndex(
|
|
282
|
-
resolve(module_src_dir, `./controllers/${dirName}`),
|
|
283
|
-
entitiesData,
|
|
284
|
-
config,
|
|
285
|
-
renderFile,
|
|
286
|
-
PATH_TMPL,
|
|
287
|
-
createDir
|
|
288
|
-
);
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
async function renderServerControllersCommons(
|
|
293
|
-
module_src_dir,
|
|
294
|
-
entitiesData,
|
|
295
|
-
config
|
|
296
|
-
) {
|
|
297
|
-
const dirPath = resolve(module_src_dir, `./common`);
|
|
298
|
-
await createDir(dirPath);
|
|
299
|
-
await createDirContent(
|
|
300
|
-
dirPath,
|
|
301
|
-
ApplicationModuleServerControllersCommonStructure,
|
|
302
|
-
{}
|
|
303
|
-
);
|
|
304
|
-
await Renderers.controllersCommons(
|
|
305
|
-
dirPath,
|
|
306
|
-
entitiesData,
|
|
307
|
-
config,
|
|
308
|
-
renderFile,
|
|
309
|
-
PATH_TMPL
|
|
310
|
-
);
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
async function createBootstrapFrontModule(modules_dir, config) {
|
|
314
|
-
await createDir(modules_dir);
|
|
315
|
-
await createDirContent(
|
|
316
|
-
modules_dir,
|
|
317
|
-
ProjectSubStructures["module.front"],
|
|
318
|
-
config
|
|
319
|
-
);
|
|
320
|
-
for (let role of config.roles) {
|
|
321
|
-
await createDir(resolve(modules_dir, role));
|
|
322
|
-
const targetFrontModuleDir = resolve(modules_dir, role, "main");
|
|
323
|
-
await createDir(targetFrontModuleDir);
|
|
324
|
-
if (role === "guest") {
|
|
325
|
-
await Renderers.frontModuleGuestMain(
|
|
326
|
-
targetFrontModuleDir,
|
|
327
|
-
{ ...config, roleName: role },
|
|
328
|
-
renderFile,
|
|
329
|
-
PATH_TMPL
|
|
330
|
-
);
|
|
331
|
-
} else {
|
|
332
|
-
await Renderers.frontModuleRoleMain(
|
|
333
|
-
targetFrontModuleDir,
|
|
334
|
-
{ ...config, roleName: role },
|
|
335
|
-
renderFile,
|
|
336
|
-
PATH_TMPL
|
|
337
|
-
);
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
function installPackages(siteDir) {
|
|
343
|
-
return new Promise((resolve, reject) => {
|
|
344
|
-
console.log("installing packages...");
|
|
345
|
-
let npmInstall = spawn(`npm`, ["i"], {
|
|
346
|
-
cwd: siteDir,
|
|
347
|
-
});
|
|
348
|
-
|
|
349
|
-
npmInstall.stderr.on("data", (data) => {
|
|
350
|
-
!silent && console.error(data.toString());
|
|
351
|
-
});
|
|
352
|
-
npmInstall.on("exit", (code) => {
|
|
353
|
-
if (code == 0) {
|
|
354
|
-
resolve();
|
|
355
|
-
} else {
|
|
356
|
-
reject(`NPM install exited with code ${code}`);
|
|
357
|
-
}
|
|
358
|
-
});
|
|
359
|
-
});
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
function buildClientSideScripts(siteDir) {
|
|
363
|
-
return new Promise((resolve, reject) => {
|
|
364
|
-
console.log("building client side scripts...");
|
|
365
|
-
let npmInstall = spawn(`npm`, ["run", "build"], {
|
|
366
|
-
cwd: siteDir,
|
|
367
|
-
});
|
|
368
|
-
|
|
369
|
-
npmInstall.stderr.on("data", (data) => {
|
|
370
|
-
!silent && console.error(data.toString());
|
|
371
|
-
});
|
|
372
|
-
npmInstall.on("exit", (code) => {
|
|
373
|
-
if (code == 0) {
|
|
374
|
-
resolve();
|
|
375
|
-
} else {
|
|
376
|
-
reject(`npm run build job exited with code ${code}`);
|
|
377
|
-
}
|
|
378
|
-
});
|
|
379
|
-
});
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
function postStartupInstructions(siteDir, config) {
|
|
383
|
-
console.log(
|
|
384
|
-
"Generation of source code, configurations, toolchain and installation of packages successfully finished."
|
|
385
|
-
);
|
|
386
|
-
if (config.nginx) {
|
|
387
|
-
console.log("To enable NGINX reverse proxy:");
|
|
388
|
-
console.log(
|
|
389
|
-
"1. Copy config file for desired envrionment to NGINX directory and enable it"
|
|
390
|
-
);
|
|
391
|
-
for (let env of ["development", "stage", "production"]) {
|
|
392
|
-
console.log(
|
|
393
|
-
`For '${env}' environment exec while in project directory:`
|
|
394
|
-
);
|
|
395
|
-
console.log(
|
|
396
|
-
`$ sudo cp nginx/${env}.conf to /var/nginx/sites-available/${config.hostname[env]}.conf`
|
|
397
|
-
);
|
|
398
|
-
console.log(
|
|
399
|
-
`$ sudo ln -s /var/nginx/sites-available/${config.hostname[env]}.conf /var/nginx/sites-enabled/${config.hostname[env]}.conf`
|
|
400
|
-
);
|
|
401
|
-
}
|
|
402
|
-
console.log("2. Restart NGINX server");
|
|
403
|
-
console.log("$ sudo systemctl restart nginx");
|
|
404
|
-
}
|
|
405
|
-
console.log(
|
|
406
|
-
`To start server navigate to [project]/site directory (cd '${siteDir}') and run 'npm start'`
|
|
407
|
-
);
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
function makeScriptExecutable(pathToTargetScript) {
|
|
411
|
-
return new Promise((resolve, reject) => {
|
|
412
|
-
console.log(`chmod`, "+x", pathToTargetScript);
|
|
413
|
-
let npmInstall = spawn(`chmod`, ["+x", pathToTargetScript]);
|
|
414
|
-
npmInstall.stderr.on("data", (data) => {
|
|
415
|
-
!silent && console.error(data.toString());
|
|
416
|
-
});
|
|
417
|
-
npmInstall.on("exit", (code) => {
|
|
418
|
-
if (code == 0) {
|
|
419
|
-
resolve();
|
|
420
|
-
} else {
|
|
421
|
-
reject(`chmod +x ${pathToTargetScript} ${code}`);
|
|
422
|
-
}
|
|
423
|
-
});
|
|
424
|
-
});
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
async function createProjectToolsAndConfigs(projectDir, projectConfig) {
|
|
428
|
-
console.log(projectDir);
|
|
429
|
-
if (projectConfig.pm2) {
|
|
430
|
-
console.log("Rendering PM2 configs");
|
|
431
|
-
await Renderers.pm2(projectDir, {}, projectConfig, createFileContent);
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
if (projectConfig.nginx) {
|
|
435
|
-
console.log("Rendering NGINX configs");
|
|
436
|
-
await Renderers.nginx(projectDir, {}, projectConfig, createFileContent);
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
if (projectConfig.deploy) {
|
|
440
|
-
console.log("Rendering deployment scripts");
|
|
441
|
-
await Renderers.deploy(
|
|
442
|
-
projectDir,
|
|
443
|
-
{},
|
|
444
|
-
projectConfig,
|
|
445
|
-
createFileContent,
|
|
446
|
-
makeScriptExecutable
|
|
447
|
-
);
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
program
|
|
452
|
-
.command("create")
|
|
453
|
-
.addOption(
|
|
454
|
-
new Option("-d, --dir <dir>").default(CWD, "current working directory")
|
|
455
|
-
)
|
|
456
|
-
.addOption(new Option("-v, --verbose").default(false, "extensive output"))
|
|
457
|
-
.description(
|
|
458
|
-
"create application in target directory (create -d [pathToDir])"
|
|
459
|
-
)
|
|
460
|
-
.action(async (opts) => {
|
|
461
|
-
// console.log("create command called :" + opts.dir);
|
|
462
|
-
if (!isAbsolute(opts.dir)) {
|
|
463
|
-
opts.dir = resolve(CWD, opts.dir);
|
|
464
|
-
}
|
|
465
|
-
const siteDir = resolve(opts.dir, "./site");
|
|
466
|
-
if (opts.v) {
|
|
467
|
-
silent = false;
|
|
468
|
-
}
|
|
469
|
-
console.log("creating project in", opts.dir);
|
|
470
|
-
console.log("creating site in", siteDir);
|
|
471
|
-
const ProjectConfig = {
|
|
472
|
-
path: opts.dir,
|
|
473
|
-
};
|
|
474
|
-
//
|
|
475
|
-
ProjectConfig.AppName = await Readers.AppName(inquirer, ProjectConfig);
|
|
476
|
-
ProjectConfig.appName = await Readers.appName(inquirer, ProjectConfig);
|
|
477
|
-
ProjectConfig.hostname = await Readers.hostname(
|
|
478
|
-
inquirer,
|
|
479
|
-
ProjectConfig
|
|
480
|
-
);
|
|
481
|
-
ProjectConfig.roles = await Readers.roles(inquirer, ProjectConfig);
|
|
482
|
-
ProjectConfig.rolesSecondary = await Readers.rolesSecondary(
|
|
483
|
-
inquirer,
|
|
484
|
-
ProjectConfig
|
|
485
|
-
);
|
|
486
|
-
ProjectConfig.modules = await Readers.modules(inquirer, ProjectConfig);
|
|
487
|
-
ProjectConfig.nginx = await Readers.nginx(inquirer, ProjectConfig);
|
|
488
|
-
ProjectConfig.pm2 = await Readers.pm2(inquirer, ProjectConfig);
|
|
489
|
-
ProjectConfig.deploy = await Readers.deploy(inquirer, ProjectConfig);
|
|
490
|
-
ProjectConfig.port = await Readers.port(inquirer, ProjectConfig);
|
|
491
|
-
ProjectConfig.debugPort = await Readers.debugPort(
|
|
492
|
-
inquirer,
|
|
493
|
-
ProjectConfig
|
|
494
|
-
);
|
|
495
|
-
ProjectConfig.not_node_monitor = await Readers.not_node_monitor(
|
|
496
|
-
inquirer,
|
|
497
|
-
ProjectConfig
|
|
498
|
-
);
|
|
499
|
-
ProjectConfig.not_node_reporter = await Readers.not_node_reporter(
|
|
500
|
-
inquirer,
|
|
501
|
-
ProjectConfig
|
|
502
|
-
);
|
|
503
|
-
await createDir(opts.dir);
|
|
504
|
-
await createDirContent(opts.dir, ProjectStructure, ProjectConfig);
|
|
505
|
-
await createProjectToolsAndConfigs(opts.dir, ProjectConfig);
|
|
506
|
-
const PATH_MODULES_SERVER = resolve(
|
|
507
|
-
opts.dir,
|
|
508
|
-
DEFAULT_SERVER_MODULES_SUB_PATH
|
|
509
|
-
);
|
|
510
|
-
const PATH_MODULES_FRONT = resolve(
|
|
511
|
-
opts.dir,
|
|
512
|
-
DEFAULT_FRONT_MODULES_SUB_PATH
|
|
513
|
-
);
|
|
514
|
-
while (await Readers.isUserNeedCreateServerModule(inquirer)) {
|
|
515
|
-
await createServerModule(PATH_MODULES_SERVER, ProjectConfig);
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
if (await Readers.isUserNeedFrontModuleBootstrap(inquirer)) {
|
|
519
|
-
await createBootstrapFrontModule(PATH_MODULES_FRONT, ProjectConfig);
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
console.log("siteDir", siteDir);
|
|
523
|
-
await installPackages(siteDir);
|
|
524
|
-
await buildClientSideScripts(siteDir);
|
|
525
|
-
postStartupInstructions(siteDir, ProjectConfig);
|
|
526
|
-
});
|
|
527
|
-
|
|
9
|
+
Actions(program, { CWD });
|
|
528
10
|
program.parse();
|
package/package.json
CHANGED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Option } from "commander";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { createEntity } from "../lib/entity.mjs";
|
|
4
|
+
import Logger from "../lib/log.mjs";
|
|
5
|
+
import { loadProjectConfig } from "../lib/project.mjs";
|
|
6
|
+
|
|
7
|
+
export default (program, { CWD }) => {
|
|
8
|
+
program
|
|
9
|
+
.command("entity")
|
|
10
|
+
.addOption(
|
|
11
|
+
new Option("-v, --verbose").default(false, "extensive output")
|
|
12
|
+
)
|
|
13
|
+
.description("adds entity to existing module of project")
|
|
14
|
+
.action(async (opts) => {
|
|
15
|
+
console.log(CWD);
|
|
16
|
+
const siteDir = resolve(CWD, "./site");
|
|
17
|
+
if (opts.v) {
|
|
18
|
+
Logger.setSilent(false);
|
|
19
|
+
}
|
|
20
|
+
console.log("project in", opts.dir);
|
|
21
|
+
const infoFromManifest = await loadProjectConfig(siteDir);
|
|
22
|
+
const modulesDir = resolve(
|
|
23
|
+
siteDir,
|
|
24
|
+
infoFromManifest.serverModulesDir
|
|
25
|
+
);
|
|
26
|
+
console.log("creating server module in", modulesDir);
|
|
27
|
+
const ProjectConfig = {
|
|
28
|
+
path: opts.dir,
|
|
29
|
+
...infoFromManifest,
|
|
30
|
+
};
|
|
31
|
+
await createEntity(modulesDir, ProjectConfig);
|
|
32
|
+
});
|
|
33
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default (program, { CWD }) => {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import Entity from "./entity.mjs";
|
|
2
|
+
import Env from "./env.mjs";
|
|
3
|
+
import ModuleFront from "./module.front.mjs";
|
|
4
|
+
import ModuleServer from "./module.server.mjs";
|
|
5
|
+
import Nginx from "./nginx.mjs";
|
|
6
|
+
import PM2 from "./pm2.mjs";
|
|
7
|
+
import Project from "./project.mjs";
|
|
8
|
+
|
|
9
|
+
const ACTIONS = {
|
|
10
|
+
Entity,
|
|
11
|
+
Env,
|
|
12
|
+
ModuleFront,
|
|
13
|
+
ModuleServer,
|
|
14
|
+
Nginx,
|
|
15
|
+
PM2,
|
|
16
|
+
Project,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export default (program, options) => {
|
|
20
|
+
Object.values(ACTIONS).forEach((action) => {
|
|
21
|
+
action(program, options);
|
|
22
|
+
});
|
|
23
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Option } from "commander";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import Logger from "../lib/log.mjs";
|
|
4
|
+
import { createFrontModule } from "../lib/module.front.mjs";
|
|
5
|
+
import { loadProjectConfig } from "../lib/project.mjs";
|
|
6
|
+
import Options from "../lib/opts.mjs";
|
|
7
|
+
|
|
8
|
+
export default (program, { CWD }) => {
|
|
9
|
+
program
|
|
10
|
+
.command("front")
|
|
11
|
+
.addOption(
|
|
12
|
+
new Option("-v, --verbose").default(false, "extensive output")
|
|
13
|
+
)
|
|
14
|
+
.description("adds new front module to existing project")
|
|
15
|
+
.action(async (opts) => {
|
|
16
|
+
console.log(CWD);
|
|
17
|
+
const siteDir = resolve(CWD, "./site");
|
|
18
|
+
if (opts.v) {
|
|
19
|
+
Logger.setSilent(false);
|
|
20
|
+
}
|
|
21
|
+
console.log("project in", opts.dir);
|
|
22
|
+
const infoFromManifest = await loadProjectConfig(siteDir);
|
|
23
|
+
const modulesDir = resolve(
|
|
24
|
+
siteDir,
|
|
25
|
+
infoFromManifest.frontModulesDir
|
|
26
|
+
);
|
|
27
|
+
Options.roles = infoFromManifest.roles;
|
|
28
|
+
console.log("creating server module in", modulesDir);
|
|
29
|
+
const ProjectConfig = {
|
|
30
|
+
path: opts.dir,
|
|
31
|
+
...infoFromManifest,
|
|
32
|
+
}; //
|
|
33
|
+
await createFrontModule(modulesDir, ProjectConfig);
|
|
34
|
+
});
|
|
35
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Option } from "commander";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import Logger from "../lib/log.mjs";
|
|
4
|
+
import { createServerModule } from "../lib/module.server.mjs";
|
|
5
|
+
import { loadProjectConfig } from "../lib/project.mjs";
|
|
6
|
+
|
|
7
|
+
export default (program, { CWD }) => {
|
|
8
|
+
program
|
|
9
|
+
.command("server")
|
|
10
|
+
.addOption(
|
|
11
|
+
new Option("-v, --verbose").default(false, "extensive output")
|
|
12
|
+
)
|
|
13
|
+
.description("adds new server module to existing project")
|
|
14
|
+
.action(async (opts) => {
|
|
15
|
+
console.log(CWD);
|
|
16
|
+
const siteDir = resolve(CWD, "./site");
|
|
17
|
+
if (opts.v) {
|
|
18
|
+
Logger.setSilent(false);
|
|
19
|
+
}
|
|
20
|
+
console.log("project in", opts.dir);
|
|
21
|
+
const infoFromManifest = await loadProjectConfig(siteDir);
|
|
22
|
+
const modulesDir = resolve(
|
|
23
|
+
siteDir,
|
|
24
|
+
infoFromManifest.serverModulesDir
|
|
25
|
+
);
|
|
26
|
+
console.log("creating server module in", modulesDir);
|
|
27
|
+
const ProjectConfig = {
|
|
28
|
+
path: opts.dir,
|
|
29
|
+
...infoFromManifest,
|
|
30
|
+
};
|
|
31
|
+
await createServerModule(modulesDir, ProjectConfig);
|
|
32
|
+
});
|
|
33
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default (program, { CWD }) => {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default (program, { CWD }) => {};
|