@ronas-it/nx-generators 0.6.0 → 0.7.0
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/README.md +16 -0
- package/generators.json +5 -0
- package/package.json +4 -2
- package/src/generators/entity-api/files/api.ts.template +15 -0
- package/src/generators/entity-api/files/config.ts.template +4 -0
- package/src/generators/entity-api/files/index.ts.template +3 -0
- package/src/generators/entity-api/files/models/entity-request.ts.template +8 -0
- package/src/generators/entity-api/files/models/entity.ts.template +8 -0
- package/src/generators/entity-api/files/models/index.ts.template +3 -0
- package/src/generators/entity-api/files/models/pagination-request.ts.template +8 -0
- package/src/generators/entity-api/generator.d.ts +4 -0
- package/src/generators/entity-api/generator.js +93 -0
- package/src/generators/entity-api/generator.js.map +1 -0
- package/src/generators/entity-api/schema.d.ts +4 -0
- package/src/generators/entity-api/schema.json +18 -0
- package/src/generators/react-component/generator.js +15 -11
- package/src/generators/react-component/generator.js.map +1 -1
- package/src/shared/utils/cli-utils.d.ts +2 -1
- package/src/shared/utils/cli-utils.js +24 -4
- package/src/shared/utils/cli-utils.js.map +1 -1
- package/src/shared/utils/dynamic-import.d.ts +1 -0
- package/src/shared/utils/dynamic-import.js +5 -0
- package/src/shared/utils/dynamic-import.js.map +1 -0
- package/src/shared/utils/index.d.ts +1 -0
- package/src/shared/utils/index.js +1 -0
- package/src/shared/utils/index.js.map +1 -1
package/README.md
CHANGED
|
@@ -148,6 +148,22 @@ or
|
|
|
148
148
|
npx nx g react-component AppButton --subcomponent
|
|
149
149
|
```
|
|
150
150
|
|
|
151
|
+
### 7. `entity-api`
|
|
152
|
+
|
|
153
|
+
Creates an API with related entities in API library. It also updates redux store middlewares, reducers.
|
|
154
|
+
|
|
155
|
+
#### Options
|
|
156
|
+
|
|
157
|
+
1. `name` (optional) - name of the entity (e.g. User)
|
|
158
|
+
|
|
159
|
+
2. `baseEndpoint` (optional) - name of used endpoint in your API (e.g. /users)
|
|
160
|
+
|
|
161
|
+
#### Example
|
|
162
|
+
|
|
163
|
+
```sh
|
|
164
|
+
npx nx g entity-api --name=User --baseEndpoint=users
|
|
165
|
+
```
|
|
166
|
+
|
|
151
167
|
### Note
|
|
152
168
|
|
|
153
169
|
Each generator accepts the `--help` argument to see generator instructions.
|
package/generators.json
CHANGED
|
@@ -34,6 +34,11 @@
|
|
|
34
34
|
"factory": "./src/shared/generators/ui-kitten/generator",
|
|
35
35
|
"schema": "./src/shared/generators/ui-kitten/schema.json",
|
|
36
36
|
"description": "UI-Kitten generator for Expo projects"
|
|
37
|
+
},
|
|
38
|
+
"entity-api": {
|
|
39
|
+
"factory": "./src/generators/entity-api/generator",
|
|
40
|
+
"schema": "./src/generators/entity-api/schema.json",
|
|
41
|
+
"description": "entity-api generator"
|
|
37
42
|
}
|
|
38
43
|
}
|
|
39
44
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ronas-it/nx-generators",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "NX generators for Ronas IT projects",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Ronas IT",
|
|
@@ -24,9 +24,11 @@
|
|
|
24
24
|
"access": "public"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@nx/devkit": "19.3.0",
|
|
27
|
+
"@nx/devkit": "^19.3.0",
|
|
28
|
+
"@nx/expo": "^19.3.0",
|
|
28
29
|
"lodash": "^4.17.21",
|
|
29
30
|
"tslib": "^2.6.3",
|
|
31
|
+
"ts-morph": "^23.0.0",
|
|
30
32
|
"inquirer-autocomplete-standalone": "^0.8.1"
|
|
31
33
|
},
|
|
32
34
|
"type": "commonjs",
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createEntityApi } from '@ronas-it/rtkq-entity-api';
|
|
2
|
+
import { axiosBaseQuery, createAppApi } from '<%= apiClientDirectory %>';
|
|
3
|
+
import { <%= entityName %> } from '../<%= entityFileName %>';
|
|
4
|
+
import { <%= apiName %>ApiConfig } from './config';
|
|
5
|
+
import { <%= entityName %>EntityRequest, <%= entityName %>PaginationRequest } from './models';
|
|
6
|
+
|
|
7
|
+
export const <%= apiName %>Api = createEntityApi({
|
|
8
|
+
entityName: <%= apiName %>ApiConfig.entityName,
|
|
9
|
+
baseApiCreator: createAppApi,
|
|
10
|
+
baseQuery: axiosBaseQuery,
|
|
11
|
+
baseEndpoint: <%= apiName %>ApiConfig.baseEndpoint,
|
|
12
|
+
entityConstructor: <%= entityName %>,
|
|
13
|
+
entityGetRequestConstructor: <%= entityName %>EntityRequest,
|
|
14
|
+
entitySearchRequestConstructor: <%= entityName %>PaginationRequest
|
|
15
|
+
});
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.entityApiGenerator = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const devkit_1 = require("@nx/devkit");
|
|
6
|
+
const ts_morph_1 = require("ts-morph");
|
|
7
|
+
const path = require("path");
|
|
8
|
+
const lodash_1 = require("lodash");
|
|
9
|
+
const utils_1 = require("../../shared/utils");
|
|
10
|
+
function entityApiGenerator(tree, options) {
|
|
11
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
12
|
+
const { default: autocomplete } = yield (0, utils_1.dynamicImport)('inquirer-autocomplete-standalone');
|
|
13
|
+
const nxLibsPaths = (0, utils_1.getNxLibsPaths)([utils_1.LibraryType.DATA_ACCESS]);
|
|
14
|
+
const apiLibsPaths = (0, utils_1.searchNxLibsPaths)(nxLibsPaths, 'data-access/api/');
|
|
15
|
+
const apiClientLibsPaths = (0, utils_1.searchNxLibsPaths)(nxLibsPaths, 'data-access/api-client/');
|
|
16
|
+
if (!apiClientLibsPaths.length) {
|
|
17
|
+
throw new Error('Could not find API Client path.');
|
|
18
|
+
}
|
|
19
|
+
if (!apiLibsPaths.length) {
|
|
20
|
+
throw new Error('Could not find API path.');
|
|
21
|
+
}
|
|
22
|
+
if (apiClientLibsPaths.length > 1) {
|
|
23
|
+
apiClientLibsPaths[0] = yield autocomplete({
|
|
24
|
+
message: 'Select the api client library path:',
|
|
25
|
+
suggestOnly: true,
|
|
26
|
+
source: () => tslib_1.__awaiter(this, void 0, void 0, function* () { return apiClientLibsPaths.map((path) => ({ value: path })); })
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
if (apiLibsPaths.length > 1) {
|
|
30
|
+
apiLibsPaths[0] = yield autocomplete({
|
|
31
|
+
message: 'Select the api library path:',
|
|
32
|
+
suggestOnly: true,
|
|
33
|
+
source: () => tslib_1.__awaiter(this, void 0, void 0, function* () { return apiLibsPaths.map((path) => ({ value: path })); })
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
const apiDirectory = (0, utils_1.searchAliasPath)(apiLibsPaths[0]);
|
|
37
|
+
const apiClientDirectory = (0, utils_1.searchAliasPath)(apiClientLibsPaths[0]);
|
|
38
|
+
const libPath = apiLibsPaths[0];
|
|
39
|
+
const libRootPath = `${libPath}/lib`;
|
|
40
|
+
options.name = options.name || (yield (0, utils_1.askQuestion)('Enter the name of the entity (e.g: User): '));
|
|
41
|
+
const apiName = (0, lodash_1.kebabCase)(options.name);
|
|
42
|
+
options.baseEndpoint = options.baseEndpoint || (yield (0, utils_1.askQuestion)('Enter the base endpoint (e.g: /users): ', `/${apiName}`));
|
|
43
|
+
const apiPath = `${libRootPath}/${apiName}`;
|
|
44
|
+
const entityName = (0, lodash_1.startCase)((0, lodash_1.camelCase)(apiName)).replace(/\s+/g, '');
|
|
45
|
+
(0, devkit_1.generateFiles)(tree, path.join(__dirname, `files`), apiPath, Object.assign(Object.assign({}, options), { apiName: (0, lodash_1.camelCase)(options.name), entityName, entityFileName: apiName, apiClientDirectory, baseEndpoint: options.baseEndpoint.startsWith('/') ? options.baseEndpoint : `/${options.baseEndpoint}` }));
|
|
46
|
+
tree.rename(`${apiPath}/models/entity.ts`, `${apiPath}/models/${apiName}.ts`);
|
|
47
|
+
const appendFileContent = (path, endContent) => {
|
|
48
|
+
const content = tree.read(path, 'utf-8');
|
|
49
|
+
const contentUpdate = content + endContent;
|
|
50
|
+
tree.write(path, contentUpdate);
|
|
51
|
+
};
|
|
52
|
+
appendFileContent(`${libRootPath}/index.ts`, `export * from './${apiName}';\n`);
|
|
53
|
+
const storeLibsPaths = (0, utils_1.searchNxLibsPaths)(nxLibsPaths, 'data-access/store/');
|
|
54
|
+
if (!storeLibsPaths.length) {
|
|
55
|
+
yield (0, devkit_1.formatFiles)(tree);
|
|
56
|
+
throw new Error('Could not find redux store path.');
|
|
57
|
+
}
|
|
58
|
+
if (storeLibsPaths.length > 1) {
|
|
59
|
+
storeLibsPaths[0] = yield autocomplete({
|
|
60
|
+
message: 'Select the store library path:',
|
|
61
|
+
suggestOnly: true,
|
|
62
|
+
source: () => tslib_1.__awaiter(this, void 0, void 0, function* () { return storeLibsPaths.map((path) => ({ value: path })); })
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
// Update redux store
|
|
66
|
+
const apiNameDeclaration = (0, lodash_1.camelCase)(options.name + 'Api');
|
|
67
|
+
const project = new ts_morph_1.Project({
|
|
68
|
+
manipulationSettings: {
|
|
69
|
+
indentationText: ts_morph_1.IndentationText.TwoSpaces,
|
|
70
|
+
quoteKind: ts_morph_1.QuoteKind.Single
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
const store = project.addSourceFileAtPath(`${storeLibsPaths[0]}/store.ts`);
|
|
74
|
+
// TODO: create declaration if not exists
|
|
75
|
+
const apiImportsDeclaration = store.getImportDeclarationOrThrow((node) => node.getModuleSpecifierValue() === apiDirectory);
|
|
76
|
+
apiImportsDeclaration.addNamedImport(apiNameDeclaration);
|
|
77
|
+
const rootReducer = store.getVariableDeclarationOrThrow('rootReducer');
|
|
78
|
+
rootReducer.getInitializerIfKindOrThrow(ts_morph_1.SyntaxKind.ObjectLiteralExpression)
|
|
79
|
+
.addProperty({
|
|
80
|
+
name: `[${apiNameDeclaration}.reducerPath]`,
|
|
81
|
+
initializer: `${apiNameDeclaration}.reducer`,
|
|
82
|
+
kind: ts_morph_1.StructureKind.PropertyAssignment
|
|
83
|
+
});
|
|
84
|
+
const middlewares = store.getVariableDeclarationOrThrow('middlewares');
|
|
85
|
+
middlewares.getInitializerIfKindOrThrow(ts_morph_1.SyntaxKind.ArrayLiteralExpression)
|
|
86
|
+
.addElement(`${apiNameDeclaration}.middleware`);
|
|
87
|
+
project.saveSync();
|
|
88
|
+
yield (0, devkit_1.formatFiles)(tree);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
exports.entityApiGenerator = entityApiGenerator;
|
|
92
|
+
exports.default = entityApiGenerator;
|
|
93
|
+
//# sourceMappingURL=generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../plugin/src/generators/entity-api/generator.ts"],"names":[],"mappings":";;;;AAAA,uCAA8D;AAC9D,uCAA0F;AAC1F,6BAA6B;AAC7B,mCAAyD;AAEzD,8CAAiI;AAEjI,SAAsB,kBAAkB,CACtC,IAAU,EACV,OAAiC;;QAEjC,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,GAAG,MAAM,IAAA,qBAAa,EAAoD,kCAAkC,CAAC,CAAC;QAC7I,MAAM,WAAW,GAAG,IAAA,sBAAc,EAAC,CAAC,mBAAW,CAAC,WAAW,CAAC,CAAC,CAAC;QAC9D,MAAM,YAAY,GAAG,IAAA,yBAAiB,EAAC,WAAW,EAAE,kBAAkB,CAAC,CAAC;QACxE,MAAM,kBAAkB,GAAG,IAAA,yBAAiB,EAAC,WAAW,EAAE,yBAAyB,CAAC,CAAC;QAErF,IAAI,CAAC,kBAAkB,CAAC,MAAM,EAAE,CAAC;YAC/B,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;QACrD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uBAAuB,CAAC;aACxE,WAAW,CAAC;YACX,IAAI,EAAE,IAAI,kBAAkB,eAAe;YAC3C,WAAW,EAAE,GAAG,kBAAkB,UAAU;YAC5C,IAAI,EAAE,wBAAa,CAAC,kBAAkB;SACvC,CAAC,CAAC;QAEL,MAAM,WAAW,GAAG,KAAK,CAAC,6BAA6B,CAAC,aAAa,CAAC,CAAC;QAEvE,WAAW,CAAC,2BAA2B,CAAC,qBAAU,CAAC,sBAAsB,CAAC;aACvE,UAAU,CAAC,GAAG,kBAAkB,aAAa,CAAC,CAAC;QAElD,OAAO,CAAC,QAAQ,EAAE,CAAC;QAEnB,MAAM,IAAA,oBAAW,EAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;CAAA;AAnHD,gDAmHC;AAED,kBAAe,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"$id": "EntityAPI",
|
|
4
|
+
"title": "",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"properties": {
|
|
7
|
+
"name": {
|
|
8
|
+
"type": "string",
|
|
9
|
+
"description": "Name of the entity",
|
|
10
|
+
"default": "",
|
|
11
|
+
"$default": {
|
|
12
|
+
"$source": "argv",
|
|
13
|
+
"index": 0
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"required": []
|
|
18
|
+
}
|
|
@@ -7,10 +7,9 @@ const path = require("path");
|
|
|
7
7
|
const lodash_1 = require("lodash");
|
|
8
8
|
const utils_1 = require("../../shared/utils");
|
|
9
9
|
const fs_1 = require("fs");
|
|
10
|
-
const dynamicImport = new Function('specifier', 'return import(specifier)');
|
|
11
10
|
function reactComponentGenerator(tree, options) {
|
|
12
11
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
13
|
-
const { default: autocomplete } = yield dynamicImport('inquirer-autocomplete-standalone');
|
|
12
|
+
const { default: autocomplete } = yield (0, utils_1.dynamicImport)('inquirer-autocomplete-standalone');
|
|
14
13
|
const nxLibsPaths = (0, utils_1.getNxLibsPaths)([utils_1.LibraryType.FEATURES, utils_1.LibraryType.UI]);
|
|
15
14
|
const libPath = yield autocomplete({
|
|
16
15
|
message: 'Enter the library path:',
|
|
@@ -22,26 +21,31 @@ function reactComponentGenerator(tree, options) {
|
|
|
22
21
|
options.name = options.name || (yield (0, utils_1.askQuestion)('Enter the name of the component (e.g: AppButton): '));
|
|
23
22
|
options.subcomponent = options.subcomponent || (yield (0, utils_1.askQuestion)('Generate component inside components folder? (y/n): ')) === 'y';
|
|
24
23
|
const libRootPath = `${libPath}/lib`;
|
|
24
|
+
const componentsPath = `${libRootPath}/components`;
|
|
25
25
|
const componentPath = options.subcomponent
|
|
26
26
|
? `${libRootPath}/components/${(0, lodash_1.kebabCase)(options.name)}`
|
|
27
27
|
: libRootPath;
|
|
28
|
-
const
|
|
28
|
+
const shouldUpdateSrcIndex = !(0, fs_1.existsSync)(libRootPath);
|
|
29
|
+
const shouldUpdateLibIndex = !(0, fs_1.existsSync)(componentsPath) && options.subcomponent;
|
|
29
30
|
(0, devkit_1.generateFiles)(tree, path.join(__dirname, `files`), componentPath, Object.assign(Object.assign({}, options), { formatName: utils_1.formatName }));
|
|
31
|
+
const appendFileContent = (path, endContent) => {
|
|
32
|
+
const content = tree.read(path, 'utf-8');
|
|
33
|
+
const contentUpdate = content + endContent;
|
|
34
|
+
tree.write(path, contentUpdate);
|
|
35
|
+
};
|
|
30
36
|
const updateIndexes = () => {
|
|
31
37
|
const componentsIndexFilePath = `${libRootPath}/components/index.ts`;
|
|
32
|
-
if (
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
38
|
+
if (shouldUpdateSrcIndex) {
|
|
39
|
+
appendFileContent(`${libPath}/index.ts`, `export * from './lib';\n`);
|
|
40
|
+
}
|
|
41
|
+
if (shouldUpdateLibIndex) {
|
|
42
|
+
appendFileContent(`${libRootPath}/index.ts`, `export * from './components';\n`);
|
|
37
43
|
}
|
|
38
44
|
if (!(0, fs_1.existsSync)(componentsIndexFilePath)) {
|
|
39
45
|
tree.write(componentsIndexFilePath, `export * from './${(0, lodash_1.kebabCase)(options.name)}';\n`);
|
|
40
46
|
}
|
|
41
47
|
else {
|
|
42
|
-
|
|
43
|
-
const contentUpdate = componentsIndexFileContent + `export * from './${(0, lodash_1.kebabCase)(options.name)}';\n`;
|
|
44
|
-
tree.write(componentsIndexFilePath, contentUpdate);
|
|
48
|
+
appendFileContent(componentsIndexFilePath, `export * from './${(0, lodash_1.kebabCase)(options.name)}';\n`);
|
|
45
49
|
}
|
|
46
50
|
};
|
|
47
51
|
if (options.subcomponent) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../plugin/src/generators/react-component/generator.ts"],"names":[],"mappings":";;;;AAAA,uCAA8D;AAC9D,6BAA6B;AAC7B,mCAAmC;AAEnC,
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../plugin/src/generators/react-component/generator.ts"],"names":[],"mappings":";;;;AAAA,uCAA8D;AAC9D,6BAA6B;AAC7B,mCAAmC;AAEnC,8CAA4H;AAC5H,2BAAgC;AAEhC,SAAsB,uBAAuB,CAC3C,IAAU,EACV,OAAsC;;QAEtC,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,GAAG,MAAM,IAAA,qBAAa,EAAoD,kCAAkC,CAAC,CAAC;QAE7I,MAAM,WAAW,GAAG,IAAA,sBAAc,EAAC,CAAC,mBAAW,CAAC,QAAQ,EAAE,mBAAW,CAAC,EAAE,CAAC,CAAC,CAAC;QAE3E,MAAM,OAAO,GAAG,MAAM,YAAY,CAAC;YACjC,OAAO,EAAE,yBAAyB;YAClC,MAAM,EAAE,CAAO,KAAK,EAAE,EAAE;gBACtB,MAAM,mBAAmB,GAAG,IAAA,yBAAiB,EAAC,WAAW,EAAE,KAAK,CAAC,CAAA;gBAEjE,OAAO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,GAAS,EAAE;YAC/B,MAAM,uBAAuB,GAAG,GAAG,WAAW,sBAAsB,CAAC;YAErE,IAAI,oBAAoB,EAAE,CAAC;gBACzB,iBAAiB,CAAC,GAAG,OAAO,WAAW,EAAE,0BAA0B,CAAC,CAAC;YACvE,CAAC;YAED,IAAI,oBAAoB,EAAE,CAAC;gBACzB,iBAAiB,CAAC,GAAG,WAAW,WAAW,EAAE,iCAAiC,CAAC,CAAC;YAClF,CAAC;YAED,IAAI,CAAC,IAAA,eAAU,EAAC,uBAAuB,CAAC,EAAE,CAAC;gBACzC,IAAI,CAAC,KAAK,CAAC,uBAAuB,EAAE,oBAAoB,IAAA,kBAAS,EAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACzF,CAAC;iBAAM,CAAC;gBACN,iBAAiB,CAAC,uBAAuB,EAAE,oBAAoB,IAAA,kBAAS,EAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YAChG,CAAC;QACH,CAAC,CAAA;QAED,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;YACzB,aAAa,EAAE,CAAC;QAClB,CAAC;QAED,MAAM,IAAA,oBAAW,EAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;CAAA;AA5DD,0DA4DC;AAED,kBAAe,uBAAuB,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const askQuestion: (question: string) => Promise<string>;
|
|
1
|
+
export declare const askQuestion: (question: string, defaultAnswer?: string) => Promise<string>;
|
|
2
2
|
export declare enum LibraryType {
|
|
3
3
|
UI = "ui",
|
|
4
4
|
DATA_ACCESS = "data-access",
|
|
@@ -7,3 +7,4 @@ export declare enum LibraryType {
|
|
|
7
7
|
}
|
|
8
8
|
export declare const getNxLibsPaths: (types: Array<LibraryType>) => any[];
|
|
9
9
|
export declare const searchNxLibsPaths: (paths: Array<string>, input: string) => string[];
|
|
10
|
+
export declare const searchAliasPath: (input: string) => string;
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.searchNxLibsPaths = exports.getNxLibsPaths = exports.LibraryType = exports.askQuestion = void 0;
|
|
3
|
+
exports.searchAliasPath = exports.searchNxLibsPaths = exports.getNxLibsPaths = exports.LibraryType = exports.askQuestion = void 0;
|
|
4
4
|
const readline = require("readline");
|
|
5
5
|
const fs = require("fs");
|
|
6
|
-
const askQuestion = (question) => {
|
|
6
|
+
const askQuestion = (question, defaultAnswer) => {
|
|
7
7
|
const rl = readline.createInterface({
|
|
8
8
|
input: process.stdin,
|
|
9
9
|
output: process.stdout,
|
|
10
10
|
});
|
|
11
|
+
if (defaultAnswer) {
|
|
12
|
+
rl.write(defaultAnswer);
|
|
13
|
+
// Move cursor to end of the line
|
|
14
|
+
setTimeout(() => rl.write(null, { ctrl: true, name: 'e' }));
|
|
15
|
+
}
|
|
11
16
|
return new Promise((resolve) => rl.question(question, (answer) => {
|
|
12
17
|
rl.close();
|
|
13
18
|
resolve(answer);
|
|
@@ -21,9 +26,18 @@ var LibraryType;
|
|
|
21
26
|
LibraryType["FEATURES"] = "features";
|
|
22
27
|
LibraryType["UTILS"] = "utils";
|
|
23
28
|
})(LibraryType || (exports.LibraryType = LibraryType = {}));
|
|
29
|
+
const parseLibsPaths = () => {
|
|
30
|
+
let tsconfig;
|
|
31
|
+
if (fs.existsSync('tsconfig.base.json')) {
|
|
32
|
+
tsconfig = JSON.parse(fs.readFileSync('tsconfig.base.json', 'utf8'));
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
tsconfig = JSON.parse(fs.readFileSync('tsconfig.json', 'utf8'));
|
|
36
|
+
}
|
|
37
|
+
return tsconfig.compilerOptions.paths;
|
|
38
|
+
};
|
|
24
39
|
const getNxLibsPaths = (types) => {
|
|
25
|
-
const
|
|
26
|
-
const libs = tsconfig.compilerOptions.paths;
|
|
40
|
+
const libs = parseLibsPaths();
|
|
27
41
|
return Object.values(libs)
|
|
28
42
|
.map((value) => value[0].replace('/index.ts', ''))
|
|
29
43
|
.filter((value) => types.some((type) => value.includes(type)));
|
|
@@ -33,4 +47,10 @@ const searchNxLibsPaths = (paths, input) => {
|
|
|
33
47
|
return paths.filter((path) => path.includes(input));
|
|
34
48
|
};
|
|
35
49
|
exports.searchNxLibsPaths = searchNxLibsPaths;
|
|
50
|
+
const searchAliasPath = (input) => {
|
|
51
|
+
const libs = parseLibsPaths();
|
|
52
|
+
const path = Object.keys(libs).find((key) => libs[key][0].includes(input));
|
|
53
|
+
return path;
|
|
54
|
+
};
|
|
55
|
+
exports.searchAliasPath = searchAliasPath;
|
|
36
56
|
//# sourceMappingURL=cli-utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli-utils.js","sourceRoot":"","sources":["../../../../../plugin/src/shared/utils/cli-utils.ts"],"names":[],"mappings":";;;AAAA,qCAAqC;AACrC,yBAAyB;AAElB,MAAM,WAAW,GAAG,CAAC,QAAgB,EAAmB,EAAE;
|
|
1
|
+
{"version":3,"file":"cli-utils.js","sourceRoot":"","sources":["../../../../../plugin/src/shared/utils/cli-utils.ts"],"names":[],"mappings":";;;AAAA,qCAAqC;AACrC,yBAAyB;AAElB,MAAM,WAAW,GAAG,CAAC,QAAgB,EAAE,aAAsB,EAAmB,EAAE;IACvF,MAAM,EAAE,GAAG,QAAQ,CAAC,eAAe,CAAC;QAClC,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,MAAM,EAAE,OAAO,CAAC,MAAM;KACvB,CAAC,CAAC;IAEH,IAAI,aAAa,EAAE,CAAC;QAClB,EAAE,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;QACxB,iCAAiC;QACjC,UAAU,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC;IAC9D,CAAC;IAED,OAAO,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,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACnE,CAAC,CAAA;AANY,QAAA,cAAc,kBAM1B;AAEM,MAAM,iBAAiB,GAAG,CAAC,KAAoB,EAAE,KAAa,EAAE,EAAE;IACvE,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;AACtD,CAAC,CAAA;AAFY,QAAA,iBAAiB,qBAE7B;AAEM,MAAM,eAAe,GAAG,CAAC,KAAa,EAAE,EAAE;IAC/C,MAAM,IAAI,GAAG,cAAc,EAAE,CAAC;IAC9B,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;IAE3E,OAAO,IAAI,CAAC;AACd,CAAC,CAAA;AALY,QAAA,eAAe,mBAK3B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const dynamicImport: <T = never>(specifier: string) => Promise<T>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dynamic-import.js","sourceRoot":"","sources":["../../../../../plugin/src/shared/utils/dynamic-import.ts"],"names":[],"mappings":";;;AAAa,QAAA,aAAa,GAAG,IAAI,QAAQ,CACvC,WAAW,EACX,0BAA0B,CACqB,CAAC"}
|
|
@@ -3,4 +3,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
tslib_1.__exportStar(require("./format-utils"), exports);
|
|
5
5
|
tslib_1.__exportStar(require("./cli-utils"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./dynamic-import"), exports);
|
|
6
7
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../plugin/src/shared/utils/index.ts"],"names":[],"mappings":";;;AAAA,yDAA+B;AAC/B,sDAA4B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../plugin/src/shared/utils/index.ts"],"names":[],"mappings":";;;AAAA,yDAA+B;AAC/B,sDAA4B;AAC5B,2DAAiC"}
|