not-node 6.1.5 → 6.1.6
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/playground/.env +2 -2
- package/playground/nginx/development.conf +4 -12
- package/playground/nginx/production.conf +1 -9
- package/playground/nginx/stage.conf +1 -9
- package/playground/pm2/development.json +6 -6
- package/playground/pm2/production.json +5 -5
- package/playground/pm2/stage.json +5 -5
- package/playground/site/app/front/build/admin.js +1 -45
- package/playground/site/app/front/build/client.js +1 -45
- package/playground/site/app/front/build/guest.js +1 -45
- package/playground/site/app/front/build/root.js +1 -45
- package/playground/site/app/front/build/user.js +1 -45
- package/playground/site/app/front/src/admin/notNodeModule/index.js +25 -0
- package/playground/site/app/front/src/client/notNodeModule/index.js +25 -0
- package/playground/site/app/front/src/common/index.js +0 -15
- package/playground/site/app/front/src/guest/notNodeModule/index.js +25 -0
- package/playground/site/app/front/src/root/notNodeModule/index.js +25 -0
- package/playground/site/app/front/src/user/notNodeModule/index.js +25 -0
- package/playground/site/app/server/config/common.json +83 -117
- package/playground/site/app/server/config/development.json +32 -31
- package/playground/site/app/server/modules/notNodeModule/index.js +8 -0
- package/playground/site/app/server/modules/notNodeModule/src/const.js +1 -0
- package/playground/site/app/server/modules/notNodeModule/src/controllers/admin/index.js +29 -0
- package/playground/site/app/server/modules/notNodeModule/src/controllers/admin/ncNewModel.js +11 -0
- package/playground/site/app/server/modules/notNodeModule/src/controllers/admin/ncTester.js +11 -0
- package/playground/site/app/server/modules/notNodeModule/src/controllers/client/index.js +29 -0
- package/playground/site/app/server/modules/notNodeModule/src/controllers/client/ncNewModel.js +11 -0
- package/playground/site/app/server/modules/notNodeModule/src/controllers/client/ncTester.js +11 -0
- package/playground/site/app/server/modules/notNodeModule/src/controllers/common/ncNewModelCommon.js +103 -0
- package/playground/site/app/server/modules/notNodeModule/src/controllers/common/validators.js +44 -0
- package/playground/site/app/server/modules/notNodeModule/src/controllers/common/ws.client.js +25 -0
- package/playground/site/app/server/modules/notNodeModule/src/controllers/guest/index.js +29 -0
- package/playground/site/app/server/modules/notNodeModule/src/controllers/guest/ncNewModel.js +11 -0
- package/playground/site/app/server/modules/notNodeModule/src/controllers/guest/ncTester.js +11 -0
- package/playground/site/app/server/modules/notNodeModule/src/controllers/root/index.js +29 -0
- package/playground/site/app/server/modules/notNodeModule/src/controllers/root/ncNewModel.js +11 -0
- package/playground/site/app/server/modules/notNodeModule/src/controllers/root/ncTester.js +11 -0
- package/playground/site/app/server/modules/notNodeModule/src/controllers/user/index.js +29 -0
- package/playground/site/app/server/modules/notNodeModule/src/controllers/user/ncNewModel.js +11 -0
- package/playground/site/app/server/modules/notNodeModule/src/controllers/user/ncTester.js +11 -0
- package/playground/site/app/server/modules/notNodeModule/src/forms/_newModel_data.js +35 -0
- package/playground/site/app/server/modules/notNodeModule/src/forms/_tester_data.js +36 -0
- package/playground/site/app/server/modules/notNodeModule/src/forms/newModel.create.js +49 -0
- package/playground/site/app/server/modules/notNodeModule/src/forms/newModel.delete.js +8 -0
- package/playground/site/app/server/modules/notNodeModule/src/forms/newModel.get.js +8 -0
- package/playground/site/app/server/modules/notNodeModule/src/forms/newModel.getRaw.js +8 -0
- package/playground/site/app/server/modules/notNodeModule/src/forms/newModel.listAll.js +8 -0
- package/playground/site/app/server/modules/notNodeModule/src/forms/newModel.listAndCount.js +8 -0
- package/playground/site/app/server/modules/notNodeModule/src/forms/newModel.update.js +40 -0
- package/playground/site/app/server/modules/notNodeModule/src/forms/tester.create.js +52 -0
- package/playground/site/app/server/modules/notNodeModule/src/forms/tester.delete.js +8 -0
- package/playground/site/app/server/modules/notNodeModule/src/forms/tester.get.js +8 -0
- package/playground/site/app/server/modules/notNodeModule/src/forms/tester.getRaw.js +8 -0
- package/playground/site/app/server/modules/notNodeModule/src/forms/tester.listAll.js +8 -0
- package/playground/site/app/server/modules/notNodeModule/src/forms/tester.listAndCount.js +8 -0
- package/playground/site/app/server/modules/notNodeModule/src/forms/tester.update.js +41 -0
- package/playground/site/app/server/modules/notNodeModule/src/logics/newModel.js +229 -0
- package/playground/site/app/server/modules/notNodeModule/src/logics/tester.js +229 -0
- package/playground/site/app/server/modules/notNodeModule/src/models/newModel.js +64 -0
- package/playground/site/app/server/modules/notNodeModule/src/models/tester.js +66 -0
- package/playground/site/app/server/modules/notNodeModule/src/routes/newModel.js +124 -0
- package/playground/site/app/server/modules/notNodeModule/src/routes/newModel.manifest.js +213 -0
- package/playground/site/app/server/modules/notNodeModule/src/routes/newModel.ws.js +29 -0
- package/playground/site/app/server/modules/notNodeModule/src/routes/tester.js +92 -0
- package/playground/site/app/server/modules/notNodeModule/src/routes/tester.manifest.js +215 -0
- package/playground/site/app/server/modules/notNodeModule/src/routes/tester.ws.js +29 -0
- package/playground/site/app/server/routes/site.js +71 -59
- 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/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
package/playground/.env
CHANGED
|
@@ -4,14 +4,14 @@ map $http_upgrade $connection_upgrade {
|
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
upstream websocket2 {
|
|
7
|
-
server
|
|
7
|
+
server :;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
server {
|
|
11
11
|
listen 80 ssl http2 ;
|
|
12
12
|
root /var/server/nn/playground/site/app/static;
|
|
13
13
|
index index.html index.htm;
|
|
14
|
-
server_name
|
|
14
|
+
server_name not-node-application.local;
|
|
15
15
|
|
|
16
16
|
location /assets/{expires 365d; alias /var/server/nn/playground/site/app/static/assets/;}
|
|
17
17
|
location /css/{ expires 365d; alias /var/server/nn/playground/site/app/static/css/;}
|
|
@@ -32,18 +32,10 @@ server {
|
|
|
32
32
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
33
33
|
proxy_set_header X-FILENAME $http_x_filename;
|
|
34
34
|
proxy_set_header SessionID $http_SessionID;
|
|
35
|
-
proxy_pass http://
|
|
35
|
+
proxy_pass http://not-node-application.local:3000/api;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
|
|
39
|
-
location /websocket {
|
|
40
|
-
proxy_pass http://websocket2;
|
|
41
|
-
proxy_http_version 1.1;
|
|
42
|
-
proxy_set_header Upgrade $http_upgrade;
|
|
43
|
-
proxy_set_header Connection $connection_upgrade;
|
|
44
|
-
proxy_set_header Host $host;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
39
|
|
|
48
40
|
|
|
49
41
|
location / {
|
|
@@ -54,7 +46,7 @@ server {
|
|
|
54
46
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
55
47
|
proxy_set_header X-FILENAME $http_x_filename;
|
|
56
48
|
proxy_set_header SessionID $http_SessionID;
|
|
57
|
-
proxy_pass http://
|
|
49
|
+
proxy_pass http://not-node-application.local:3000/;
|
|
58
50
|
}
|
|
59
51
|
|
|
60
52
|
|
|
@@ -4,7 +4,7 @@ map $http_upgrade $connection_upgrade {
|
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
upstream websocket2 {
|
|
7
|
-
server
|
|
7
|
+
server :;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
server {
|
|
@@ -36,14 +36,6 @@ server {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
|
|
39
|
-
location /websocket {
|
|
40
|
-
proxy_pass http://websocket2;
|
|
41
|
-
proxy_http_version 1.1;
|
|
42
|
-
proxy_set_header Upgrade $http_upgrade;
|
|
43
|
-
proxy_set_header Connection $connection_upgrade;
|
|
44
|
-
proxy_set_header Host $host;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
39
|
|
|
48
40
|
|
|
49
41
|
location / {
|
|
@@ -4,7 +4,7 @@ map $http_upgrade $connection_upgrade {
|
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
upstream websocket2 {
|
|
7
|
-
server
|
|
7
|
+
server :;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
server {
|
|
@@ -36,14 +36,6 @@ server {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
|
|
39
|
-
location /websocket {
|
|
40
|
-
proxy_pass http://websocket2;
|
|
41
|
-
proxy_http_version 1.1;
|
|
42
|
-
proxy_set_header Upgrade $http_upgrade;
|
|
43
|
-
proxy_set_header Connection $connection_upgrade;
|
|
44
|
-
proxy_set_header Host $host;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
39
|
|
|
48
40
|
|
|
49
41
|
location / {
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
],
|
|
20
20
|
"exec_mode": "fork",
|
|
21
21
|
"env": {
|
|
22
|
-
"hostname": "https://
|
|
22
|
+
"hostname": "https://not-node-application.local",
|
|
23
23
|
"NODE_ENV": "development",
|
|
24
24
|
|
|
25
25
|
"NOT_NODE_ERROR_KEY": "123456",
|
|
@@ -33,11 +33,11 @@
|
|
|
33
33
|
"NOT_NODE_MONITOR_REPORT_URL": "https://appmon.ru/api/key/collect"
|
|
34
34
|
|
|
35
35
|
|
|
36
|
-
"db__mongoose__uri": "mongodb
|
|
37
|
-
"db__mongoose__options__host": "
|
|
38
|
-
"db__mongoose__options__user": "
|
|
39
|
-
"db__mongoose__options__pass": "
|
|
40
|
-
"db__mongoose__options__db": "
|
|
36
|
+
"db__mongoose__uri": "mongodb:///test?authSource=admin",
|
|
37
|
+
"db__mongoose__options__host": "",
|
|
38
|
+
"db__mongoose__options__user": "tester",
|
|
39
|
+
"db__mongoose__options__pass": "test",
|
|
40
|
+
"db__mongoose__options__db": "test",
|
|
41
41
|
|
|
42
42
|
|
|
43
43
|
}
|
|
@@ -33,11 +33,11 @@
|
|
|
33
33
|
"NOT_NODE_MONITOR_REPORT_URL": "https://appmon.ru/api/key/collect"
|
|
34
34
|
|
|
35
35
|
|
|
36
|
-
"db__mongoose__uri": "mongodb
|
|
37
|
-
"db__mongoose__options__host": "
|
|
38
|
-
"db__mongoose__options__user": "
|
|
39
|
-
"db__mongoose__options__pass": "
|
|
40
|
-
"db__mongoose__options__db": "
|
|
36
|
+
"db__mongoose__uri": "mongodb:///test?authSource=admin",
|
|
37
|
+
"db__mongoose__options__host": "",
|
|
38
|
+
"db__mongoose__options__user": "tester",
|
|
39
|
+
"db__mongoose__options__pass": "test",
|
|
40
|
+
"db__mongoose__options__db": "test",
|
|
41
41
|
|
|
42
42
|
|
|
43
43
|
}
|