not-node 6.3.93 → 6.3.94
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/package.json +1 -1
- package/src/cli/actions/entity.mjs +3 -2
- package/src/cli/lib/entity.mjs +11 -2
- package/src/cli/lib/module.server.mjs +12 -2
- package/src/cli/readers/fields.mjs +4 -1
- package/src/cli/renderers/controllersCommons.mjs +21 -2
- package/src/common.js +21 -0
- package/tmpl/files/module.server/layers/controllers/common/crud.ejs +55 -56
- package/tmpl/files/module.server/layers/controllers/common/index.ejs +2 -1
- package/tmpl/files/module.server/layers/controllers/common/service.ejs +23 -0
- package/tmpl/files/module.server/layers/controllers/role/index.ejs +4 -1
- package/tmpl/files/notComponent.ejs +0 -57
- package/tmpl/files/notService.ejs +0 -39
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@ import { resolve } from "node:path";
|
|
|
3
3
|
import { createEntity } from "../lib/entity.mjs";
|
|
4
4
|
import Logger from "../lib/log.mjs";
|
|
5
5
|
import { loadProjectConfig } from "../lib/project.mjs";
|
|
6
|
-
import { getProjectSiteDir } from "../lib/fs.mjs";
|
|
6
|
+
import { getProjectSiteDir, findAllFields } from "../lib/fs.mjs";
|
|
7
7
|
|
|
8
8
|
export default (program, { CWD }) => {
|
|
9
9
|
program
|
|
@@ -27,11 +27,12 @@ export default (program, { CWD }) => {
|
|
|
27
27
|
siteDir,
|
|
28
28
|
infoFromManifest.serverModulesDir
|
|
29
29
|
);
|
|
30
|
+
const allFields = await findAllFields(siteDir, modulesDir);
|
|
30
31
|
console.log("creating server module in", modulesDir);
|
|
31
32
|
const ProjectConfig = {
|
|
32
33
|
path: opts.dir,
|
|
33
34
|
...infoFromManifest,
|
|
34
35
|
};
|
|
35
|
-
await createEntity(modulesDir, ProjectConfig);
|
|
36
|
+
await createEntity(modulesDir, ProjectConfig, allFields);
|
|
36
37
|
});
|
|
37
38
|
};
|
package/src/cli/lib/entity.mjs
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { firstLetterToLower } from "../../../src/common.js";
|
|
2
2
|
import { resolve } from "node:path";
|
|
3
3
|
import inquirer from "inquirer";
|
|
4
|
+
import inquirerPrompt from "inquirer-autocomplete-prompt";
|
|
5
|
+
|
|
6
|
+
inquirer.registerPrompt("autocomplete", inquirerPrompt);
|
|
4
7
|
import * as Readers from "../readers/index.mjs";
|
|
5
8
|
import * as Renderers from "../renderers/index.mjs";
|
|
6
9
|
import { renderFile, createDir } from "./fs.mjs";
|
|
@@ -33,12 +36,18 @@ async function renderEntityFiles(module_src_dir, data, config) {
|
|
|
33
36
|
}
|
|
34
37
|
}
|
|
35
38
|
|
|
36
|
-
async function createEntity(modules_dir, config) {
|
|
39
|
+
async function createEntity(modules_dir, config, availableFields) {
|
|
37
40
|
const ModuleName = await Readers.ModuleName(inquirer);
|
|
38
41
|
const moduleName = firstLetterToLower(ModuleName);
|
|
39
42
|
const moduleDir = resolve(modules_dir, ModuleName);
|
|
40
43
|
const moduleLayers = await Readers.moduleLayers(inquirer);
|
|
41
|
-
const moduleConfig = {
|
|
44
|
+
const moduleConfig = {
|
|
45
|
+
...config,
|
|
46
|
+
moduleName,
|
|
47
|
+
ModuleName,
|
|
48
|
+
moduleLayers,
|
|
49
|
+
availableFields,
|
|
50
|
+
};
|
|
42
51
|
// console.log("moduleConfig", moduleConfig);
|
|
43
52
|
const entityData = await Readers.entityData(
|
|
44
53
|
inquirer,
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
firstLetterToLower,
|
|
3
|
+
moduleNameTransformer,
|
|
4
|
+
} from "../../../src/common.js";
|
|
2
5
|
import { join } from "node:path";
|
|
3
6
|
import inquirer from "inquirer";
|
|
4
7
|
import inquirerPrompt from "inquirer-autocomplete-prompt";
|
|
@@ -75,9 +78,16 @@ async function renderServerContollersIndexes(
|
|
|
75
78
|
async function createServerModule(modules_dir, config, availableFields) {
|
|
76
79
|
//read module name
|
|
77
80
|
const ModuleName = await Readers.ModuleName(inquirer);
|
|
81
|
+
const ModuleNameHumanReadable = moduleNameTransformer(ModuleName);
|
|
78
82
|
const moduleName = firstLetterToLower(ModuleName);
|
|
79
83
|
const moduleDir = join(modules_dir, ModuleName);
|
|
80
|
-
const moduleConfig = {
|
|
84
|
+
const moduleConfig = {
|
|
85
|
+
...config,
|
|
86
|
+
moduleName,
|
|
87
|
+
ModuleName,
|
|
88
|
+
ModuleNameHumanReadable,
|
|
89
|
+
availableFields,
|
|
90
|
+
};
|
|
81
91
|
await createDir(moduleDir);
|
|
82
92
|
//console.log(JSON.stringify(moduleConfig, null, 4));
|
|
83
93
|
await createDirContent(
|
|
@@ -57,12 +57,15 @@ export default async (inquirer, config) => {
|
|
|
57
57
|
fieldname = answer.fieldname.trim();
|
|
58
58
|
});
|
|
59
59
|
result.push([fieldname, fieldtype]);
|
|
60
|
+
const selectedFields = result.map(
|
|
61
|
+
(itm) => `${itm[1]} as ${itm[0]}`
|
|
62
|
+
);
|
|
60
63
|
finished = await inquirer
|
|
61
64
|
.prompt([
|
|
62
65
|
{
|
|
63
66
|
type: "confirm",
|
|
64
67
|
name: "oneMore",
|
|
65
|
-
message: `Add another one field to [${
|
|
68
|
+
message: `Add another one field to [${selectedFields.join(
|
|
66
69
|
","
|
|
67
70
|
)}] (default: true)?`,
|
|
68
71
|
default: true,
|
|
@@ -7,8 +7,8 @@ export default async (
|
|
|
7
7
|
config,
|
|
8
8
|
createFileContent,
|
|
9
9
|
PATH_TMPL
|
|
10
|
-
) => {
|
|
11
|
-
for (let entityData of entitiesList) {
|
|
10
|
+
) => {
|
|
11
|
+
for (let entityData of entitiesList) {
|
|
12
12
|
const TMPL_FILE_PATH = resolve(PATH_TMPL, TEMPLATES_DIR, `crud.ejs`);
|
|
13
13
|
const DEST_FILE_PATH = resolve(
|
|
14
14
|
module_layer_dir,
|
|
@@ -21,6 +21,7 @@ export default async (
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
if (entitiesList.length) {
|
|
24
|
+
//common validators
|
|
24
25
|
const TMPL_FILE_PATH_VALIDATORS = resolve(
|
|
25
26
|
PATH_TMPL,
|
|
26
27
|
TEMPLATES_DIR,
|
|
@@ -38,5 +39,23 @@ export default async (
|
|
|
38
39
|
...entitiesList[0],
|
|
39
40
|
}
|
|
40
41
|
);
|
|
42
|
+
//common service
|
|
43
|
+
const TMPL_FILE_PATH_COMMON_SERVICE = resolve(
|
|
44
|
+
PATH_TMPL,
|
|
45
|
+
TEMPLATES_DIR,
|
|
46
|
+
`service.ejs`
|
|
47
|
+
);
|
|
48
|
+
const DEST_FILE_PATH_COMMON_SERVICE = resolve(
|
|
49
|
+
module_layer_dir,
|
|
50
|
+
`ns${config.ModuleNameHumanReadable}Common.js`
|
|
51
|
+
);
|
|
52
|
+
await createFileContent(
|
|
53
|
+
TMPL_FILE_PATH_COMMON_SERVICE,
|
|
54
|
+
DEST_FILE_PATH_COMMON_SERVICE,
|
|
55
|
+
{
|
|
56
|
+
...config,
|
|
57
|
+
...entitiesList[0],
|
|
58
|
+
}
|
|
59
|
+
);
|
|
41
60
|
}
|
|
42
61
|
};
|
package/src/common.js
CHANGED
|
@@ -23,6 +23,27 @@ module.exports.firstLetterToUpper = function (string) {
|
|
|
23
23
|
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
+
/**
|
|
27
|
+
* transforms not-module-name -> ModuleName
|
|
28
|
+
* @param {string} moduleName
|
|
29
|
+
* @return {string}
|
|
30
|
+
*/
|
|
31
|
+
function moduleNameTransformer(moduleName) {
|
|
32
|
+
//not-module-name -> [not,module,name]
|
|
33
|
+
const ModuleNameParts = moduleName.split("-");
|
|
34
|
+
//[not,module,name] -> [module,name]
|
|
35
|
+
const moduleNameSelectedParts =
|
|
36
|
+
ModuleNameParts[0] === "not"
|
|
37
|
+
? ModuleNameParts.splice(1)
|
|
38
|
+
: ModuleNameParts;
|
|
39
|
+
//[module,name] -> ModuleName
|
|
40
|
+
return moduleNameSelectedParts
|
|
41
|
+
.map(module.exports.firstLetterToUpper)
|
|
42
|
+
.join("");
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
module.exports.moduleNameTransformer = moduleNameTransformer;
|
|
46
|
+
|
|
26
47
|
/**
|
|
27
48
|
* Validates if string is a ObjectId
|
|
28
49
|
* @param {string|import('mongoose').Schema.Types.ObjectId} id ObjectId string to validate
|
|
@@ -1,95 +1,94 @@
|
|
|
1
1
|
import { MODULE_NAME } from "../../const.js";
|
|
2
2
|
import Validators from "../common/validators.js";
|
|
3
|
-
import { Frame } from "not-bulma";
|
|
3
|
+
import { Frame, notCommon } from "not-bulma";
|
|
4
4
|
import CRUDActionList from "not-bulma/src/frame/crud/actions/list";
|
|
5
5
|
|
|
6
6
|
const { notCRUD } = Frame;
|
|
7
7
|
|
|
8
8
|
const MODEL_NAME = "<%- ModelName %>";
|
|
9
|
+
const modelName = notCommon.lowerFirstLetter(MODEL_NAME);
|
|
9
10
|
|
|
10
|
-
const LABELS = {
|
|
11
|
-
plural: `${MODULE_NAME}:${
|
|
12
|
-
single: `${MODULE_NAME}:${
|
|
13
|
-
};
|
|
11
|
+
const LABELS = {
|
|
12
|
+
plural: `${MODULE_NAME}:${modelName}_label_plural`,
|
|
13
|
+
single: `${MODULE_NAME}:${modelName}_label_single`,
|
|
14
|
+
};
|
|
14
15
|
|
|
15
|
-
Object.freeze(LABELS);
|
|
16
|
+
Object.freeze(LABELS);
|
|
16
17
|
|
|
17
|
-
class nc<%- ModelName %>Common extends notCRUD {
|
|
18
|
-
|
|
18
|
+
class nc<%- ModelName %>Common extends notCRUD {
|
|
19
|
+
static get MODULE_NAME(){
|
|
19
20
|
return MODULE_NAME;
|
|
20
|
-
|
|
21
|
+
}
|
|
21
22
|
|
|
22
|
-
|
|
23
|
+
static get MODEL_NAME(){
|
|
23
24
|
return MODEL_NAME;
|
|
24
|
-
|
|
25
|
+
}
|
|
25
26
|
|
|
26
|
-
|
|
27
|
+
static get LABELS(){
|
|
27
28
|
return LABELS;
|
|
28
|
-
|
|
29
|
+
}
|
|
29
30
|
|
|
30
|
-
|
|
31
|
+
constructor(app, params) {
|
|
31
32
|
super(app, `${MODULE_NAME}.${MODEL_NAME}`);
|
|
32
33
|
this.setModuleName(MODULE_NAME);
|
|
33
34
|
this.setModelName(MODEL_NAME);
|
|
34
35
|
this.setOptions("names", LABELS);
|
|
35
|
-
this.
|
|
36
|
+
this.setValidators(Validators);
|
|
36
37
|
this.setOptions("params", params);
|
|
37
38
|
this.setOptions("list", {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
interface: {
|
|
40
|
+
combined: true,
|
|
41
|
+
factory: this.make.<%- modelName %>,
|
|
41
42
|
},
|
|
42
43
|
endless: false,
|
|
43
44
|
preload: {},
|
|
44
45
|
sorter: {
|
|
45
|
-
|
|
46
|
+
id: -1,
|
|
46
47
|
},
|
|
47
48
|
showSearch: true,
|
|
48
49
|
idField: "_id",
|
|
49
50
|
fields: [
|
|
50
|
-
|
|
51
|
+
<% if (increment) { %>
|
|
51
52
|
{
|
|
52
|
-
|
|
53
|
+
path: ":<%- modelName %>ID",
|
|
53
54
|
title: "ID",
|
|
54
55
|
searchable: true,
|
|
55
56
|
sortable: true,
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
this.start();
|
|
76
|
-
return this;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
createDefault() {
|
|
80
|
-
let newRecord = this.getModel({
|
|
81
|
-
<% for (let fieldName of fields){ %><%- fieldName[0] %>: undefined,
|
|
82
|
-
<% } %>
|
|
83
|
-
});
|
|
84
|
-
return newRecord;
|
|
85
|
-
}
|
|
57
|
+
},
|
|
58
|
+
<% } %>
|
|
59
|
+
<% for (let fieldName of fields){ %>
|
|
60
|
+
{
|
|
61
|
+
path: ":<%- fieldName[0] %>",
|
|
62
|
+
title: `${MODULE_NAME}:<%- `${modelName}_field_${fieldName[0]}_label` %>`,
|
|
63
|
+
searchable: true,
|
|
64
|
+
sortable: true,
|
|
65
|
+
},
|
|
66
|
+
<% } %>
|
|
67
|
+
{
|
|
68
|
+
path: ":_id",
|
|
69
|
+
title: "Действия",
|
|
70
|
+
type: "button",
|
|
71
|
+
preprocessor: (value) => CRUDActionList.createActionsButtons(this, value),
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
});
|
|
86
75
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
76
|
+
this.start();
|
|
77
|
+
return this;
|
|
78
|
+
}
|
|
90
79
|
|
|
91
|
-
|
|
80
|
+
createDefault() {
|
|
81
|
+
let newRecord = this.getModel({
|
|
82
|
+
<% for (let fieldName of fields){ %><%- fieldName[0] %>: undefined,
|
|
83
|
+
<% } %>
|
|
84
|
+
});
|
|
85
|
+
return newRecord;
|
|
86
|
+
}
|
|
92
87
|
|
|
93
|
-
|
|
88
|
+
static getMenu(){
|
|
89
|
+
return notCRUD.getCommonMenu(nc<%- ModelName %>Common);
|
|
90
|
+
}
|
|
94
91
|
|
|
92
|
+
}
|
|
95
93
|
|
|
94
|
+
export default nc<%- ModelName %>Common;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import main from "../common/ws.client.main.js";
|
|
2
|
+
import ns<%- ModuleNameHumanReadable %>Common from "./ns<%- ModuleNameHumanReadable %>Common.js";
|
|
2
3
|
|
|
3
4
|
<% for (let {ModelName} of entities){ %>
|
|
4
5
|
import nc<%- {ModelName} %> from "./nc<%- {ModelName} %>.js";
|
|
@@ -10,7 +11,7 @@ const wsc = {
|
|
|
10
11
|
|
|
11
12
|
const uis = {};
|
|
12
13
|
|
|
13
|
-
const services = {};
|
|
14
|
+
const services = {ns<%- ModuleNameHumanReadable %>Common};
|
|
14
15
|
|
|
15
16
|
let manifest = {
|
|
16
17
|
router: {
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Builder } from "not-validation";
|
|
2
|
+
import Validator from "validator";
|
|
3
|
+
|
|
4
|
+
export default class ns<%- ModuleNameHumanReadable %>Common {
|
|
5
|
+
constructor(app) {
|
|
6
|
+
this.app = app;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
destroy() {
|
|
10
|
+
delete this.app;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
augmentValidators(validators) {
|
|
14
|
+
return Builder(validators, () => this.getValidatorEnv());
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
getValidatorEnv() {
|
|
18
|
+
return {
|
|
19
|
+
config: this.app.getConfigReaderForModule("<%- moduleName %>"),
|
|
20
|
+
validator: Validator,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
+
import ns<%- ModuleNameHumanReadable %>Common from "../common/ns<%- ModuleNameHumanReadable %>Common.js";
|
|
1
2
|
<% for (let {ModelName} of entities){ %>
|
|
2
3
|
import nc<%- ModelName %> from "./nc<%- ModelName %>.js";
|
|
3
4
|
<% } %>
|
|
4
5
|
|
|
5
6
|
const wsc = {};
|
|
6
7
|
const uis = {};
|
|
7
|
-
const services = {
|
|
8
|
+
const services = {
|
|
9
|
+
ns<%- ModuleNameHumanReadable %>Common
|
|
10
|
+
};
|
|
8
11
|
|
|
9
12
|
let manifest = {
|
|
10
13
|
router: {
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import UI<%- ComponentName %> from "./<%- componentName %>.svelte";
|
|
2
|
-
|
|
3
|
-
class not<%- ComponentName %> extends notBase{
|
|
4
|
-
|
|
5
|
-
static UIConstructor = UI<%- ComponentName %>;
|
|
6
|
-
|
|
7
|
-
constructor({
|
|
8
|
-
target = null,
|
|
9
|
-
name = "Default",
|
|
10
|
-
options = {},
|
|
11
|
-
working = {},
|
|
12
|
-
data = {},
|
|
13
|
-
}){
|
|
14
|
-
super({
|
|
15
|
-
working: {
|
|
16
|
-
name: `${name}<%- ComponentName %>`,
|
|
17
|
-
...working,
|
|
18
|
-
},
|
|
19
|
-
options,
|
|
20
|
-
data,
|
|
21
|
-
});
|
|
22
|
-
if (target) {
|
|
23
|
-
this.setOptions("target", target);
|
|
24
|
-
}
|
|
25
|
-
this.render();
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
render(){
|
|
29
|
-
this.remove();
|
|
30
|
-
if(this.UIConstructor){
|
|
31
|
-
this.ui = new this.UIConstructor({
|
|
32
|
-
target: this.getOptions('target'),
|
|
33
|
-
props:{
|
|
34
|
-
/* props */
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
update(){
|
|
41
|
-
if(this.ui){
|
|
42
|
-
this.ui.$set({ /* update props */ });
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
remove(){
|
|
47
|
-
if (this.ui) {
|
|
48
|
-
this.ui.$destroy();
|
|
49
|
-
this.ui = null;
|
|
50
|
-
}
|
|
51
|
-
return this;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export default not<%- ComponentName %>;
|
|
57
|
-
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
const INTERVAL = 360;
|
|
2
|
-
const INIT_UPDATE_DELAY = 5;
|
|
3
|
-
|
|
4
|
-
class ns<%- ServiceName %> {
|
|
5
|
-
#INTERVAL = INTERVAL;
|
|
6
|
-
#INIT_UPDATE_DELAY = INIT_UPDATE_DELAY;
|
|
7
|
-
|
|
8
|
-
constructor(app) {
|
|
9
|
-
this.app = app;
|
|
10
|
-
<% if(modelName){ %>
|
|
11
|
-
this.interface = this.app.getInterface("<%- modelName %>"");
|
|
12
|
-
if(this.interface){
|
|
13
|
-
this.init();
|
|
14
|
-
}else{
|
|
15
|
-
app.error('no network interface');
|
|
16
|
-
}
|
|
17
|
-
<% }else{ %>
|
|
18
|
-
this.init();
|
|
19
|
-
<% } %>
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
init() {
|
|
23
|
-
setTimeout(this.update.bind(this), this.#INIT_UPDATE_DELAY * 100);
|
|
24
|
-
this.int = setInterval(this.update.bind(this), this.#INTERVAL * 1000);
|
|
25
|
-
window.addEventListener('unload', () => {
|
|
26
|
-
clearInterval(this.int);
|
|
27
|
-
delete this.app;
|
|
28
|
-
<% if(modelName){ %>
|
|
29
|
-
delete this.interface;
|
|
30
|
-
<% } %>
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
update() {
|
|
35
|
-
//serve
|
|
36
|
-
}}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
export default ns<%- ServiceName %>;
|