@nlabs/lex 1.32.0 → 1.37.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/.postcssrc.js +1 -1
- package/dist/LexConfig.js +22 -43
- package/dist/commands/build.js +24 -42
- package/dist/commands/bulid.test.js +1 -1
- package/dist/commands/clean.js +18 -21
- package/dist/commands/compile.js +53 -57
- package/dist/commands/config.js +17 -23
- package/dist/commands/copy.js +21 -26
- package/dist/commands/create.js +44 -49
- package/dist/commands/dev.js +21 -39
- package/dist/commands/index.js +9 -13
- package/dist/commands/init.js +21 -26
- package/dist/commands/link.js +13 -16
- package/dist/commands/lint.js +17 -23
- package/dist/commands/migrate.js +18 -23
- package/dist/commands/publish.js +23 -45
- package/dist/commands/test.js +17 -21
- package/dist/commands/update.js +15 -21
- package/dist/commands/upgrade.js +17 -22
- package/dist/commands/versions.js +17 -21
- package/dist/create/changelog.js +18 -23
- package/dist/lex.js +1 -0
- package/dist/resolver.js +35 -22
- package/dist/utils/app.js +243 -0
- package/dist/utils/file.js +53 -0
- package/dist/utils/log.js +54 -0
- package/dist/utils/reactShim.js +31 -0
- package/jest.config.js +2 -3
- package/jest.config.lex.js +44 -10
- package/jest.setup.js +3 -1
- package/package.json +41 -40
- package/tsconfig.template.json +1 -1
- package/webpack.config.js +29 -10
- package/dist/utils.js +0 -312
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nlabs/lex",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.37.0",
|
|
4
4
|
"description": "Lex",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bin": {
|
|
@@ -26,14 +26,14 @@
|
|
|
26
26
|
"url": "https://github.com/nitrogenlabs/lex/issues"
|
|
27
27
|
},
|
|
28
28
|
"engines": {
|
|
29
|
-
"node": ">=
|
|
29
|
+
"node": ">=16"
|
|
30
30
|
},
|
|
31
31
|
"browserslist": [
|
|
32
32
|
"last 5 version",
|
|
33
33
|
"ie 11"
|
|
34
34
|
],
|
|
35
35
|
"scripts": {
|
|
36
|
-
"build": "NODE_ENV=production && rm -rf dist && esbuild src/**/**.ts* src/**.ts* --platform=node --outdir=./dist --target=
|
|
36
|
+
"build": "NODE_ENV=production && rm -rf dist && esbuild src/**/**.ts* src/**.ts* --platform=node --outdir=./dist --sourcemap=inline --target=node16 --format=cjs",
|
|
37
37
|
"clean": "rm -rf dist node_modules package-lock.json *.log coverage",
|
|
38
38
|
"compile": "tsc -p tsconfig.build.json",
|
|
39
39
|
"env": "LEX_CONFIG='{\"useTypescript\":true}'",
|
|
@@ -45,77 +45,78 @@
|
|
|
45
45
|
"watch": "NODE_ENV=development rm -rf dist && yarn compile -w"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@hot-loader/react-dom": "17.0.2",
|
|
49
48
|
"@luckycatfactory/esbuild-graphql-loader": "^3.7.0",
|
|
49
|
+
"@nlabs/esbuild-jest": "^1.37.0",
|
|
50
50
|
"@nlabs/gothamjs": "^0.8.2",
|
|
51
51
|
"@nlabs/webpack-plugin-static-site": "^0.1.1",
|
|
52
52
|
"acorn": "^8.7.0",
|
|
53
53
|
"acorn-dynamic-import": "^4.0.0",
|
|
54
54
|
"assert": "^2.0.0",
|
|
55
55
|
"boxen": "5.1.2",
|
|
56
|
-
"caniuse-lite": "1.0.
|
|
56
|
+
"caniuse-lite": "1.0.30001363",
|
|
57
57
|
"chalk": "^4.1.2",
|
|
58
58
|
"commander": "^8.2.0",
|
|
59
59
|
"compare-versions": "^4.1.3",
|
|
60
60
|
"compression-webpack-plugin": "^9.2.0",
|
|
61
61
|
"config-webpack-plugin": "^1.1.0",
|
|
62
62
|
"copy-webpack-plugin": "^10.2.4",
|
|
63
|
-
"core-js": "^3.21.
|
|
63
|
+
"core-js": "^3.21.1",
|
|
64
64
|
"crypto-browserify": "^3.12.0",
|
|
65
|
-
"css-loader": "^6.
|
|
66
|
-
"cssnano": "^5.
|
|
65
|
+
"css-loader": "^6.7.1",
|
|
66
|
+
"cssnano": "^5.1.5",
|
|
67
67
|
"dotenv-webpack": "^7.1.0",
|
|
68
68
|
"download-npm-package": "^3.1.12",
|
|
69
|
-
"esbuild": "^0.14.
|
|
70
|
-
"esbuild-jest": "^0.5.0",
|
|
69
|
+
"esbuild": "^0.14.48",
|
|
71
70
|
"esbuild-loader": "^2.18.0",
|
|
72
|
-
"execa": "5",
|
|
73
|
-
"exports-loader": "^
|
|
71
|
+
"execa": "5.1.1",
|
|
72
|
+
"exports-loader": "^4.0.0",
|
|
74
73
|
"favicons-webpack-plugin": "^5.0.2",
|
|
75
74
|
"file-loader": "^6.2.0",
|
|
76
75
|
"find-file-up": "^2.0.1",
|
|
77
|
-
"fs-extra": "^10.0.
|
|
78
|
-
"glob": "^
|
|
76
|
+
"fs-extra": "^10.0.1",
|
|
77
|
+
"glob": "^8.0.3",
|
|
79
78
|
"graphql": "^16.3.0",
|
|
80
79
|
"graphql-tag": "^2.12.6",
|
|
81
80
|
"html-loader": "^3.1.0",
|
|
82
81
|
"html-webpack-plugin": "^5.5.0",
|
|
83
82
|
"https-browserify": "^1.0.0",
|
|
84
|
-
"imports-loader": "^
|
|
85
|
-
"jest": "^
|
|
86
|
-
"jest-
|
|
83
|
+
"imports-loader": "^4.0.0",
|
|
84
|
+
"jest": "^28.1.2",
|
|
85
|
+
"jest-circus": "^28.1.2",
|
|
86
|
+
"jest-cli": "^28.1.2",
|
|
87
|
+
"jest-environment-jsdom": "^28.1.2",
|
|
87
88
|
"jest-transform-graphql": "^2.1.0",
|
|
88
89
|
"json-d-ts": "^1.0.1",
|
|
89
90
|
"latest-version": "5.1.0",
|
|
90
91
|
"lodash": "^4.17.21",
|
|
91
|
-
"luxon": "^2.3.
|
|
92
|
+
"luxon": "^2.3.1",
|
|
92
93
|
"net": "^1.0.2",
|
|
93
|
-
"npm-check-updates": "^
|
|
94
|
+
"npm-check-updates": "^15.2.1",
|
|
94
95
|
"ora": "5.4.1",
|
|
95
96
|
"os-browserify": "^0.3.0",
|
|
96
97
|
"path-browserify": "^1.0.1",
|
|
97
98
|
"postcss-browser-reporter": "^0.6.0",
|
|
98
|
-
"postcss-cli": "^
|
|
99
|
-
"postcss-custom-properties": "^12.1.
|
|
99
|
+
"postcss-cli": "^10.0.0",
|
|
100
|
+
"postcss-custom-properties": "^12.1.5",
|
|
100
101
|
"postcss-flexbugs-fixes": "^5.0.2",
|
|
101
102
|
"postcss-for": "^2.1.1",
|
|
102
103
|
"postcss-hash": "^3.0.0",
|
|
103
|
-
"postcss-import": "14.0
|
|
104
|
-
"postcss-loader": "^
|
|
105
|
-
"postcss-nesting": "^10.1.
|
|
104
|
+
"postcss-import": "14.1.0",
|
|
105
|
+
"postcss-loader": "^7.0.0",
|
|
106
|
+
"postcss-nesting": "^10.1.3",
|
|
106
107
|
"postcss-percentage": "^0.0.0",
|
|
107
|
-
"postcss-preset-env": "^7.3
|
|
108
|
+
"postcss-preset-env": "^7.4.3",
|
|
108
109
|
"postcss-simple-vars": "^6.0.3",
|
|
109
|
-
"postcss-svgo": "5.0
|
|
110
|
+
"postcss-svgo": "5.1.0",
|
|
110
111
|
"postcss-url": "10.1.3",
|
|
111
112
|
"process": "^0.11.10",
|
|
112
|
-
"react": "^
|
|
113
|
-
"react-dom": "^
|
|
113
|
+
"react": "^18.0.0",
|
|
114
|
+
"react-dom": "^18.0.0",
|
|
114
115
|
"regenerator-runtime": "^0.13.9",
|
|
115
116
|
"resolve": "^1.22.0",
|
|
116
117
|
"rimraf": "^3.0.2",
|
|
117
118
|
"semver": "^7.3.5",
|
|
118
|
-
"source-map-loader": "^
|
|
119
|
+
"source-map-loader": "^4.0.0",
|
|
119
120
|
"source-map-support": "^0.5.21",
|
|
120
121
|
"speed-measure-webpack-plugin": "^1.5.0",
|
|
121
122
|
"static-site-generator-webpack-plugin": "^3.4.2",
|
|
@@ -125,10 +126,10 @@
|
|
|
125
126
|
"svg-spritemap-webpack-plugin": "^4.4.0",
|
|
126
127
|
"svgo": "2.8.0",
|
|
127
128
|
"tls": "^0.0.1",
|
|
128
|
-
"typescript": "^4.
|
|
129
|
+
"typescript": "^4.6.3",
|
|
129
130
|
"url-loader": "^4.1.1",
|
|
130
131
|
"util": "^0.12.4",
|
|
131
|
-
"webpack": "5.
|
|
132
|
+
"webpack": "5.73.0",
|
|
132
133
|
"webpack-bundle-analyzer": "^4.5.0",
|
|
133
134
|
"webpack-cli": "^4.9.2",
|
|
134
135
|
"webpack-merge": "^5.8.0",
|
|
@@ -136,16 +137,16 @@
|
|
|
136
137
|
"webpack-plugin-serve": "^1.6.0"
|
|
137
138
|
},
|
|
138
139
|
"devDependencies": {
|
|
139
|
-
"@nlabs/execa-mock": "^1.
|
|
140
|
-
"@types/jest": "^
|
|
141
|
-
"@types/luxon": "^2.
|
|
142
|
-
"@types/node": "^
|
|
140
|
+
"@nlabs/execa-mock": "^1.37.0",
|
|
141
|
+
"@types/jest": "^28.1.4",
|
|
142
|
+
"@types/luxon": "^2.3.1",
|
|
143
|
+
"@types/node": "^18.0.3",
|
|
143
144
|
"@types/ora": "^3.2.0",
|
|
144
|
-
"@types/react": "^
|
|
145
|
+
"@types/react": "^18.0.15",
|
|
145
146
|
"@types/webpack": "^5.28.0",
|
|
146
|
-
"eslint": "^8.
|
|
147
|
-
"eslint-config-styleguidejs": "^
|
|
148
|
-
"lerna": "^
|
|
147
|
+
"eslint": "^8.12.0",
|
|
148
|
+
"eslint-config-styleguidejs": "^3.0.0",
|
|
149
|
+
"lerna": "^5.1.8"
|
|
149
150
|
},
|
|
150
|
-
"gitHead": "
|
|
151
|
+
"gitHead": "2357f4ef91e9e856726d8e4210684193005e50c5"
|
|
151
152
|
}
|
package/tsconfig.template.json
CHANGED
package/webpack.config.js
CHANGED
|
@@ -19,7 +19,7 @@ const {BundleAnalyzerPlugin} = require('webpack-bundle-analyzer');
|
|
|
19
19
|
const {merge} = require('webpack-merge');
|
|
20
20
|
const {WebpackPluginServe} = require('webpack-plugin-serve');
|
|
21
21
|
|
|
22
|
-
const {getNodePath, relativeFilePath} = require('./dist/utils');
|
|
22
|
+
const {getNodePath, relativeFilePath} = require('./dist/utils/file');
|
|
23
23
|
|
|
24
24
|
const {ProgressPlugin, ProvidePlugin} = webpack;
|
|
25
25
|
const isProduction = process.env.NODE_ENV === 'production';
|
|
@@ -55,7 +55,10 @@ const isWeb = (preset || targetEnvironment) === 'web';
|
|
|
55
55
|
if(isWeb) {
|
|
56
56
|
plugins.push(
|
|
57
57
|
new CompressionWebpackPlugin({algorithm: 'gzip'}),
|
|
58
|
-
new ProvidePlugin({
|
|
58
|
+
new ProvidePlugin({
|
|
59
|
+
process: 'process/browser',
|
|
60
|
+
React: path.resolve(__dirname, './node_modules/react')
|
|
61
|
+
})
|
|
59
62
|
);
|
|
60
63
|
}
|
|
61
64
|
|
|
@@ -71,6 +74,9 @@ const svgPaths = `${sourceFullPath}/icons/**/**.svg`;
|
|
|
71
74
|
|
|
72
75
|
if(glob.sync(svgPaths, globOptions).length) {
|
|
73
76
|
plugins.push(new SVGSpritemapPlugin(svgPaths, {
|
|
77
|
+
input: {
|
|
78
|
+
allowDuplicates: false
|
|
79
|
+
},
|
|
74
80
|
output: {
|
|
75
81
|
chunk: {keep: true},
|
|
76
82
|
filename: './icons/icons.svg'
|
|
@@ -194,7 +200,10 @@ module.exports = (webpackEnv, webpackOptions) => {
|
|
|
194
200
|
loader: esbuildLoaderPath,
|
|
195
201
|
options: {
|
|
196
202
|
loader: 'tsx',
|
|
197
|
-
target: targetEnvironment
|
|
203
|
+
target: targetEnvironment === 'node' ? 'node16' : 'es2016'
|
|
204
|
+
},
|
|
205
|
+
resolve: {
|
|
206
|
+
symlinks: true
|
|
198
207
|
},
|
|
199
208
|
test: /\.(ts|tsx|js)$/
|
|
200
209
|
},
|
|
@@ -328,9 +337,6 @@ module.exports = (webpackEnv, webpackOptions) => {
|
|
|
328
337
|
node_modules: true
|
|
329
338
|
}
|
|
330
339
|
},
|
|
331
|
-
// stats: {
|
|
332
|
-
// warningsFilter: [/Failed to parse source map/]
|
|
333
|
-
// },
|
|
334
340
|
target: isWeb ? 'web' : 'node'
|
|
335
341
|
};
|
|
336
342
|
|
|
@@ -338,7 +344,6 @@ module.exports = (webpackEnv, webpackOptions) => {
|
|
|
338
344
|
if(!isProduction) {
|
|
339
345
|
webpackConfig.resolve.alias = {
|
|
340
346
|
...webpackConfig.resolve.alias,
|
|
341
|
-
'react-dom': relativeFilePath('node_modules/@hot-loader/react-dom', __dirname),
|
|
342
347
|
webpack: webpackPath
|
|
343
348
|
};
|
|
344
349
|
webpackConfig.optimization = {minimize: false};
|
|
@@ -353,7 +358,14 @@ module.exports = (webpackEnv, webpackOptions) => {
|
|
|
353
358
|
disableDotRule: true,
|
|
354
359
|
htmlAcceptHeaders: ['text/html','*/*'],
|
|
355
360
|
index: '/index.html',
|
|
361
|
+
logger: console.log.bind(console),
|
|
356
362
|
rewrites: [
|
|
363
|
+
// wps
|
|
364
|
+
{
|
|
365
|
+
from: '/wps',
|
|
366
|
+
to: ({parsedUrl: {pathname}}) => pathname
|
|
367
|
+
},
|
|
368
|
+
|
|
357
369
|
// Javascript files
|
|
358
370
|
{
|
|
359
371
|
from: /\.js/,
|
|
@@ -364,7 +376,7 @@ module.exports = (webpackEnv, webpackOptions) => {
|
|
|
364
376
|
}
|
|
365
377
|
},
|
|
366
378
|
|
|
367
|
-
//
|
|
379
|
+
// Static files
|
|
368
380
|
{
|
|
369
381
|
from: /\.[css,gif,ico,jpg,json,png,svg]/,
|
|
370
382
|
to: ({parsedUrl: {pathname}}) => pathname
|
|
@@ -374,8 +386,15 @@ module.exports = (webpackEnv, webpackOptions) => {
|
|
|
374
386
|
},
|
|
375
387
|
hmr: false,
|
|
376
388
|
log: {level: 'trace'},
|
|
389
|
+
middleware: (app) => app.use(async (ctx, next) => {
|
|
390
|
+
if(ctx.path.match(/^\/wps/)) {
|
|
391
|
+
const {accept, Accept, ...remainingHeaders} = ctx.request.header;
|
|
392
|
+
ctx.request.header = remainingHeaders;
|
|
393
|
+
}
|
|
394
|
+
await next();
|
|
395
|
+
}),
|
|
377
396
|
open: process.env.WEBPACK_DEV_OPEN === 'true',
|
|
378
|
-
port:
|
|
397
|
+
port: 7001,
|
|
379
398
|
progress: 'minimal',
|
|
380
399
|
static: [outputFullPath],
|
|
381
400
|
status: true
|
|
@@ -388,7 +407,7 @@ module.exports = (webpackEnv, webpackOptions) => {
|
|
|
388
407
|
|
|
389
408
|
if(watch) {
|
|
390
409
|
webpackConfig.bail = false;
|
|
391
|
-
webpackConfig.watch = true;
|
|
410
|
+
// webpackConfig.watch = true;
|
|
392
411
|
webpackConfig.watchOptions = {
|
|
393
412
|
aggregateTimeout: 500,
|
|
394
413
|
ignored: ['node_modules/**', ...watchIgnorePaths]
|
package/dist/utils.js
DELETED
|
@@ -1,312 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
9
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
-
var __spreadValues = (a, b) => {
|
|
11
|
-
for (var prop in b || (b = {}))
|
|
12
|
-
if (__hasOwnProp.call(b, prop))
|
|
13
|
-
__defNormalProp(a, prop, b[prop]);
|
|
14
|
-
if (__getOwnPropSymbols)
|
|
15
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
16
|
-
if (__propIsEnum.call(b, prop))
|
|
17
|
-
__defNormalProp(a, prop, b[prop]);
|
|
18
|
-
}
|
|
19
|
-
return a;
|
|
20
|
-
};
|
|
21
|
-
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
22
|
-
var __export = (target, all) => {
|
|
23
|
-
for (var name in all)
|
|
24
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
25
|
-
};
|
|
26
|
-
var __reExport = (target, module2, copyDefault, desc) => {
|
|
27
|
-
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
28
|
-
for (let key of __getOwnPropNames(module2))
|
|
29
|
-
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
|
|
30
|
-
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
31
|
-
}
|
|
32
|
-
return target;
|
|
33
|
-
};
|
|
34
|
-
var __toESM = (module2, isNodeMode) => {
|
|
35
|
-
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
36
|
-
};
|
|
37
|
-
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
38
|
-
return (module2, temp) => {
|
|
39
|
-
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
40
|
-
};
|
|
41
|
-
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
42
|
-
var utils_exports = {};
|
|
43
|
-
__export(utils_exports, {
|
|
44
|
-
checkLinkedModules: () => checkLinkedModules,
|
|
45
|
-
copyFileSync: () => copyFileSync,
|
|
46
|
-
copyFiles: () => copyFiles,
|
|
47
|
-
copyFolderRecursiveSync: () => copyFolderRecursiveSync,
|
|
48
|
-
createSpinner: () => createSpinner,
|
|
49
|
-
cwd: () => cwd,
|
|
50
|
-
getFilenames: () => getFilenames,
|
|
51
|
-
getFilesByExt: () => getFilesByExt,
|
|
52
|
-
getNodePath: () => getNodePath,
|
|
53
|
-
getPackageJson: () => getPackageJson,
|
|
54
|
-
linkedModules: () => linkedModules,
|
|
55
|
-
log: () => log,
|
|
56
|
-
relativeFilePath: () => relativeFilePath,
|
|
57
|
-
removeConflictModules: () => removeConflictModules,
|
|
58
|
-
removeFiles: () => removeFiles,
|
|
59
|
-
removeModules: () => removeModules,
|
|
60
|
-
setPackageJson: () => setPackageJson,
|
|
61
|
-
updateTemplateName: () => updateTemplateName
|
|
62
|
-
});
|
|
63
|
-
var import_boxen = __toESM(require("boxen"));
|
|
64
|
-
var import_chalk = __toESM(require("chalk"));
|
|
65
|
-
var import_find_file_up = __toESM(require("find-file-up"));
|
|
66
|
-
var import_fs_extra = __toESM(require("fs-extra"));
|
|
67
|
-
var import_glob = __toESM(require("glob"));
|
|
68
|
-
var import_isEmpty = __toESM(require("lodash/isEmpty"));
|
|
69
|
-
var import_ora = __toESM(require("ora"));
|
|
70
|
-
var import_path = __toESM(require("path"));
|
|
71
|
-
var import_rimraf = __toESM(require("rimraf"));
|
|
72
|
-
var import_LexConfig = require("./LexConfig");
|
|
73
|
-
const cwd = process.cwd();
|
|
74
|
-
const log = (message, type = "info", quiet = false) => {
|
|
75
|
-
if (!quiet) {
|
|
76
|
-
let color;
|
|
77
|
-
switch (type) {
|
|
78
|
-
case "error":
|
|
79
|
-
color = import_chalk.default.red;
|
|
80
|
-
break;
|
|
81
|
-
case "note":
|
|
82
|
-
color = import_chalk.default.grey;
|
|
83
|
-
break;
|
|
84
|
-
case "success":
|
|
85
|
-
color = import_chalk.default.greenBright;
|
|
86
|
-
break;
|
|
87
|
-
case "warn":
|
|
88
|
-
color = import_chalk.default.yellow;
|
|
89
|
-
break;
|
|
90
|
-
default:
|
|
91
|
-
color = import_chalk.default.cyan;
|
|
92
|
-
break;
|
|
93
|
-
}
|
|
94
|
-
console.log(color(message));
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
const getFilenames = (props) => {
|
|
98
|
-
const { callback, cliName, name, quiet, type, useTypescript } = props;
|
|
99
|
-
let nameCaps;
|
|
100
|
-
const itemTypes = ["stores", "views"];
|
|
101
|
-
if (!name) {
|
|
102
|
-
if (itemTypes.includes(type)) {
|
|
103
|
-
log(`
|
|
104
|
-
${cliName} Error: ${type} name is required. Please use 'lex -h' for options.`, "error", quiet);
|
|
105
|
-
return callback(1);
|
|
106
|
-
}
|
|
107
|
-
} else {
|
|
108
|
-
nameCaps = `${name.charAt(0).toUpperCase()}${name.substr(1)}`;
|
|
109
|
-
}
|
|
110
|
-
log(`${cliName} adding ${name} ${type}...`, "info", quiet);
|
|
111
|
-
let templatePath;
|
|
112
|
-
let templateExt;
|
|
113
|
-
let templateReact;
|
|
114
|
-
if (useTypescript) {
|
|
115
|
-
templatePath = "../../templates/typescript";
|
|
116
|
-
templateExt = ".ts";
|
|
117
|
-
templateReact = ".tsx";
|
|
118
|
-
} else {
|
|
119
|
-
templatePath = "../../templates/flow";
|
|
120
|
-
templateExt = ".js";
|
|
121
|
-
templateReact = ".js";
|
|
122
|
-
}
|
|
123
|
-
return {
|
|
124
|
-
nameCaps,
|
|
125
|
-
templateExt,
|
|
126
|
-
templatePath,
|
|
127
|
-
templateReact
|
|
128
|
-
};
|
|
129
|
-
};
|
|
130
|
-
const createSpinner = (quiet = false) => {
|
|
131
|
-
if (quiet) {
|
|
132
|
-
return {
|
|
133
|
-
fail: () => {
|
|
134
|
-
},
|
|
135
|
-
start: () => {
|
|
136
|
-
},
|
|
137
|
-
succeed: () => {
|
|
138
|
-
}
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
return (0, import_ora.default)({ color: "yellow" });
|
|
142
|
-
};
|
|
143
|
-
const copyFiles = async (files, typeName, spinner) => {
|
|
144
|
-
const { outputFullPath, sourceFullPath } = import_LexConfig.LexConfig.config;
|
|
145
|
-
const items = files.map((fileName) => ({
|
|
146
|
-
from: fileName,
|
|
147
|
-
to: import_path.default.resolve(outputFullPath, import_path.default.relative(sourceFullPath, fileName))
|
|
148
|
-
}));
|
|
149
|
-
try {
|
|
150
|
-
spinner.start(`Copying ${typeName} files...`);
|
|
151
|
-
await Promise.all(items.map(({ from, to }) => import_fs_extra.default.copy(from, to)));
|
|
152
|
-
spinner.succeed(`Successfully copied ${files.length} ${typeName} files!`);
|
|
153
|
-
} catch (error) {
|
|
154
|
-
spinner.fail(`Copying of ${typeName} files failed.`);
|
|
155
|
-
log(`Error: ${error.message}`, "error");
|
|
156
|
-
console.log(error);
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
const copyFileSync = (source, target) => {
|
|
160
|
-
let targetFile = target;
|
|
161
|
-
if (import_fs_extra.default.existsSync(target)) {
|
|
162
|
-
if (import_fs_extra.default.lstatSync(target).isDirectory()) {
|
|
163
|
-
targetFile = import_path.default.join(target, import_path.default.basename(source));
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
import_fs_extra.default.writeFileSync(targetFile, import_fs_extra.default.readFileSync(source));
|
|
167
|
-
};
|
|
168
|
-
const copyFolderRecursiveSync = (source, target) => {
|
|
169
|
-
let files = [];
|
|
170
|
-
const targetFolder = import_path.default.join(target, import_path.default.basename(source));
|
|
171
|
-
if (!import_fs_extra.default.existsSync(targetFolder)) {
|
|
172
|
-
import_fs_extra.default.mkdirSync(targetFolder);
|
|
173
|
-
}
|
|
174
|
-
if (import_fs_extra.default.lstatSync(source).isDirectory()) {
|
|
175
|
-
files = import_fs_extra.default.readdirSync(source);
|
|
176
|
-
files.forEach((file) => {
|
|
177
|
-
const curSource = import_path.default.join(source, file);
|
|
178
|
-
if (import_fs_extra.default.lstatSync(curSource).isDirectory()) {
|
|
179
|
-
copyFolderRecursiveSync(curSource, targetFolder);
|
|
180
|
-
} else {
|
|
181
|
-
copyFileSync(curSource, targetFolder);
|
|
182
|
-
}
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
};
|
|
186
|
-
const getPackageJson = (packagePath) => {
|
|
187
|
-
const formatPath = packagePath || `${process.cwd()}/package.json`;
|
|
188
|
-
const packageData = import_fs_extra.default.readFileSync(formatPath).toString();
|
|
189
|
-
return JSON.parse(packageData);
|
|
190
|
-
};
|
|
191
|
-
const getFilesByExt = (ext) => {
|
|
192
|
-
const { sourceFullPath } = import_LexConfig.LexConfig.config;
|
|
193
|
-
return import_glob.default.sync(`${sourceFullPath}/**/**${ext}`);
|
|
194
|
-
};
|
|
195
|
-
const removeConflictModules = (moduleList) => {
|
|
196
|
-
const updatedList = __spreadValues({}, moduleList);
|
|
197
|
-
Object.keys(updatedList).forEach((moduleName) => {
|
|
198
|
-
const regex = new RegExp("^(?!@types/).*(jest|webpack).*$", "gi");
|
|
199
|
-
if (regex.test(moduleName)) {
|
|
200
|
-
delete updatedList[moduleName];
|
|
201
|
-
}
|
|
202
|
-
});
|
|
203
|
-
return updatedList;
|
|
204
|
-
};
|
|
205
|
-
const removeFiles = (fileName, isRelative = false) => new Promise((resolve, reject) => {
|
|
206
|
-
const filePath = isRelative ? import_path.default.resolve(cwd, fileName) : fileName;
|
|
207
|
-
(0, import_rimraf.default)(filePath, (error) => {
|
|
208
|
-
if (error) {
|
|
209
|
-
return reject(error);
|
|
210
|
-
}
|
|
211
|
-
return resolve(null);
|
|
212
|
-
});
|
|
213
|
-
});
|
|
214
|
-
const removeModules = () => new Promise(async (resolve, reject) => {
|
|
215
|
-
try {
|
|
216
|
-
await removeFiles("./node_modules", true);
|
|
217
|
-
await removeFiles("./yarn.lock", true);
|
|
218
|
-
await removeFiles("./package-lock.json", true);
|
|
219
|
-
resolve(null);
|
|
220
|
-
} catch (error) {
|
|
221
|
-
reject(error);
|
|
222
|
-
}
|
|
223
|
-
});
|
|
224
|
-
const setPackageJson = (json, packagePath) => {
|
|
225
|
-
if (!json) {
|
|
226
|
-
return;
|
|
227
|
-
}
|
|
228
|
-
const formatPath = packagePath || `${process.cwd()}/package.json`;
|
|
229
|
-
import_fs_extra.default.writeFileSync(formatPath, JSON.stringify(json, null, 2));
|
|
230
|
-
};
|
|
231
|
-
const linkedModules = (startPath) => {
|
|
232
|
-
const workingPath = startPath || process.cwd();
|
|
233
|
-
let modulePath;
|
|
234
|
-
let prefix;
|
|
235
|
-
if (workingPath.includes("@")) {
|
|
236
|
-
prefix = `@${workingPath.split("@").pop()}`;
|
|
237
|
-
modulePath = workingPath;
|
|
238
|
-
} else {
|
|
239
|
-
modulePath = import_path.default.join(workingPath, "node_modules");
|
|
240
|
-
}
|
|
241
|
-
const foundPaths = import_glob.default.sync(`${modulePath}/*`);
|
|
242
|
-
return foundPaths.reduce((list, foundPath) => {
|
|
243
|
-
try {
|
|
244
|
-
const stats = import_fs_extra.default.lstatSync(foundPath);
|
|
245
|
-
if (stats.isDirectory()) {
|
|
246
|
-
const deepList = linkedModules(foundPath);
|
|
247
|
-
list.push(...deepList);
|
|
248
|
-
} else if (stats.isSymbolicLink()) {
|
|
249
|
-
const moduleNames = [prefix, import_path.default.basename(foundPath)].filter((item) => !(0, import_isEmpty.default)(item));
|
|
250
|
-
list.push({ name: `${moduleNames.join("/")}`, path: foundPath });
|
|
251
|
-
}
|
|
252
|
-
return list;
|
|
253
|
-
} catch (fsError) {
|
|
254
|
-
throw fsError;
|
|
255
|
-
}
|
|
256
|
-
}, []);
|
|
257
|
-
};
|
|
258
|
-
const checkLinkedModules = () => {
|
|
259
|
-
const linked = linkedModules();
|
|
260
|
-
if (linked.length) {
|
|
261
|
-
const msgModule = linked.length > 1 ? "Modules" : "Module";
|
|
262
|
-
const linkedMsg = linked.reduce((msg, linkedModule) => `${msg}
|
|
263
|
-
* ${linkedModule.name}`, `Linked ${msgModule}:`);
|
|
264
|
-
log((0, import_boxen.default)(linkedMsg, { dimBorder: true, padding: 1 }), "warn");
|
|
265
|
-
}
|
|
266
|
-
};
|
|
267
|
-
const relativeFilePath = (filename, nodePath = "./", backUp = 0) => {
|
|
268
|
-
const nestDepth = 10;
|
|
269
|
-
if (backUp) {
|
|
270
|
-
const filePath = import_find_file_up.default.sync(filename, nodePath, nestDepth);
|
|
271
|
-
const previousPath = Array(backUp).fill(null).map(() => "../").join("");
|
|
272
|
-
return import_path.default.resolve(filePath, previousPath);
|
|
273
|
-
}
|
|
274
|
-
return import_find_file_up.default.sync(filename, nodePath, nestDepth);
|
|
275
|
-
};
|
|
276
|
-
const getNodePath = (moduleName) => {
|
|
277
|
-
const modulePath = `node_modules/${moduleName}`;
|
|
278
|
-
const repoPath = import_find_file_up.default.sync(modulePath, __dirname);
|
|
279
|
-
if (repoPath && import_fs_extra.default.existsSync(repoPath)) {
|
|
280
|
-
return repoPath;
|
|
281
|
-
}
|
|
282
|
-
const localPath = import_find_file_up.default.sync(modulePath, "./", 10) || `./${modulePath}`;
|
|
283
|
-
return localPath;
|
|
284
|
-
};
|
|
285
|
-
const updateTemplateName = (filePath, replace, replaceCaps) => {
|
|
286
|
-
let data = import_fs_extra.default.readFileSync(filePath, "utf8");
|
|
287
|
-
data = data.replace(/sample/g, replace);
|
|
288
|
-
data = data.replace(/Sample/g, replaceCaps);
|
|
289
|
-
import_fs_extra.default.writeFileSync(filePath, data, "utf8");
|
|
290
|
-
};
|
|
291
|
-
module.exports = __toCommonJS(utils_exports);
|
|
292
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
293
|
-
0 && (module.exports = {
|
|
294
|
-
checkLinkedModules,
|
|
295
|
-
copyFileSync,
|
|
296
|
-
copyFiles,
|
|
297
|
-
copyFolderRecursiveSync,
|
|
298
|
-
createSpinner,
|
|
299
|
-
cwd,
|
|
300
|
-
getFilenames,
|
|
301
|
-
getFilesByExt,
|
|
302
|
-
getNodePath,
|
|
303
|
-
getPackageJson,
|
|
304
|
-
linkedModules,
|
|
305
|
-
log,
|
|
306
|
-
relativeFilePath,
|
|
307
|
-
removeConflictModules,
|
|
308
|
-
removeFiles,
|
|
309
|
-
removeModules,
|
|
310
|
-
setPackageJson,
|
|
311
|
-
updateTemplateName
|
|
312
|
-
});
|