lcd-router-webpack-plugin 1.0.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/.lecprc.ts +5 -0
- package/LICENSE +674 -0
- package/lib/Generator.d.ts +16 -0
- package/lib/Generator.d.ts.map +1 -0
- package/lib/Generator.js +35 -0
- package/lib/Generator.js.map +1 -0
- package/lib/ReducersGenerator.d.ts +15 -0
- package/lib/ReducersGenerator.d.ts.map +1 -0
- package/lib/ReducersGenerator.js +62 -0
- package/lib/ReducersGenerator.js.map +1 -0
- package/lib/RoutersGenerator.d.ts +24 -0
- package/lib/RoutersGenerator.d.ts.map +1 -0
- package/lib/RoutersGenerator.js +115 -0
- package/lib/RoutersGenerator.js.map +1 -0
- package/lib/SagasGenerator.d.ts +16 -0
- package/lib/SagasGenerator.d.ts.map +1 -0
- package/lib/SagasGenerator.js +56 -0
- package/lib/SagasGenerator.js.map +1 -0
- package/lib/index.d.ts +9 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +181 -0
- package/lib/index.js.map +1 -0
- package/lib/utils/files.d.ts +23 -0
- package/lib/utils/files.d.ts.map +1 -0
- package/lib/utils/files.js +65 -0
- package/lib/utils/files.js.map +1 -0
- package/lib/utils/index.d.ts +5 -0
- package/lib/utils/index.d.ts.map +1 -0
- package/lib/utils/index.js +50 -0
- package/lib/utils/index.js.map +1 -0
- package/lib/utils/paths.d.ts +38 -0
- package/lib/utils/paths.d.ts.map +1 -0
- package/lib/utils/paths.js +81 -0
- package/lib/utils/paths.js.map +1 -0
- package/lib/utils/resolver.d.ts +25 -0
- package/lib/utils/resolver.d.ts.map +1 -0
- package/lib/utils/resolver.js +41 -0
- package/lib/utils/resolver.js.map +1 -0
- package/lib/utils/types.d.ts +75 -0
- package/lib/utils/types.d.ts.map +1 -0
- package/lib/utils/types.js +6 -0
- package/lib/utils/types.js.map +1 -0
- package/package.json +29 -0
- package/src/Generator.ts +46 -0
- package/src/ReducersGenerator.ts +90 -0
- package/src/RoutersGenerator.ts +295 -0
- package/src/SagasGenerator.ts +101 -0
- package/src/index.ts +204 -0
- package/src/utils/files.ts +54 -0
- package/src/utils/index.ts +4 -0
- package/src/utils/paths.ts +77 -0
- package/src/utils/resolver.ts +37 -0
- package/src/utils/types.ts +76 -0
- package/tsconfig.json +14 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare class Generator<T> {
|
|
2
|
+
protected cache: Map<string, T>;
|
|
3
|
+
constructor();
|
|
4
|
+
set(name: string, value: T): void;
|
|
5
|
+
protected identifierString(arg: string): string;
|
|
6
|
+
protected importDefaultDeclaration(name: string, source: string): any;
|
|
7
|
+
/**
|
|
8
|
+
* 创建一条 import 语句, 例如:
|
|
9
|
+
* importNamedDeclaration(['a', 'b'], 'xxx/c') 会生成 import {a, b} from 'xxx/c'
|
|
10
|
+
*
|
|
11
|
+
* 也支持 alias, 例如:
|
|
12
|
+
* importNamedDeclaration([['a', 'aliasName'], 'b'], 'xxx/c') 会生成 import {a as aliasName, b} from 'xxx/c'
|
|
13
|
+
*/
|
|
14
|
+
protected importNamedDeclaration(names: Array<string | [name: string, alias: string]>, source: string): any;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=Generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Generator.d.ts","sourceRoot":"","sources":["../src/Generator.ts"],"names":[],"mappings":"AACA,qBAAa,SAAS,CAAC,CAAC;IACtB,SAAS,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;;IAKhC,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;IAI1B,SAAS,CAAC,gBAAgB,CAAC,GAAG,EAAE,MAAM;IAItC,SAAS,CAAC,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAO/D;;;;;;OAMG;IACH,SAAS,CAAC,sBAAsB,CAC9B,KAAK,EAAE,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,EACpD,MAAM,EAAE,MAAM;CAcjB"}
|
package/lib/Generator.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Generator = void 0;
|
|
7
|
+
var _core = require("@babel/core");
|
|
8
|
+
class Generator {
|
|
9
|
+
cache;
|
|
10
|
+
constructor() {
|
|
11
|
+
this.cache = new Map();
|
|
12
|
+
}
|
|
13
|
+
set(name, value) {
|
|
14
|
+
this.cache.set(name, value);
|
|
15
|
+
}
|
|
16
|
+
identifierString(arg) {
|
|
17
|
+
return arg.replace(/(\/|-)/g, '_');
|
|
18
|
+
}
|
|
19
|
+
importDefaultDeclaration(name, source) {
|
|
20
|
+
return _core.types.importDeclaration([_core.types.importDefaultSpecifier(_core.types.identifier(this.identifierString(name)))], _core.types.stringLiteral(source));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 创建一条 import 语句, 例如:
|
|
25
|
+
* importNamedDeclaration(['a', 'b'], 'xxx/c') 会生成 import {a, b} from 'xxx/c'
|
|
26
|
+
*
|
|
27
|
+
* 也支持 alias, 例如:
|
|
28
|
+
* importNamedDeclaration([['a', 'aliasName'], 'b'], 'xxx/c') 会生成 import {a as aliasName, b} from 'xxx/c'
|
|
29
|
+
*/
|
|
30
|
+
importNamedDeclaration(names, source) {
|
|
31
|
+
return _core.types.importDeclaration(names.map(x => typeof x === 'string' ? _core.types.importSpecifier(_core.types.identifier(x), _core.types.identifier(x)) : _core.types.importSpecifier(_core.types.identifier(this.identifierString(x[1])), _core.types.identifier(x[0]))), _core.types.stringLiteral(source));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.Generator = Generator;
|
|
35
|
+
//# sourceMappingURL=Generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Generator.js","names":["_core","require","Generator","cache","constructor","Map","set","name","value","identifierString","arg","replace","importDefaultDeclaration","source","types","importDeclaration","importDefaultSpecifier","identifier","stringLiteral","importNamedDeclaration","names","map","x","importSpecifier","exports"],"sources":["../Generator.ts"],"sourcesContent":["import { types } from '@babel/core';\nexport class Generator<T> {\n protected cache: Map<string, T>;\n constructor() {\n this.cache = new Map<string, T>();\n }\n\n set(name: string, value: T) {\n this.cache.set(name, value);\n }\n\n protected identifierString(arg: string) {\n return arg.replace(/(\\/|-)/g, '_');\n }\n\n protected importDefaultDeclaration(name: string, source: string) {\n return types.importDeclaration(\n [types.importDefaultSpecifier(types.identifier(this.identifierString(name)))],\n types.stringLiteral(source),\n );\n }\n\n /**\n * 创建一条 import 语句, 例如:\n * importNamedDeclaration(['a', 'b'], 'xxx/c') 会生成 import {a, b} from 'xxx/c'\n *\n * 也支持 alias, 例如:\n * importNamedDeclaration([['a', 'aliasName'], 'b'], 'xxx/c') 会生成 import {a as aliasName, b} from 'xxx/c'\n */\n protected importNamedDeclaration(\n names: Array<string | [name: string, alias: string]>,\n source: string,\n ) {\n return types.importDeclaration(\n names.map((x) =>\n typeof x === 'string'\n ? types.importSpecifier(types.identifier(x), types.identifier(x))\n : types.importSpecifier(\n types.identifier(this.identifierString(x[1])),\n types.identifier(x[0]),\n ),\n ),\n types.stringLiteral(source),\n );\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AACO,MAAMC,SAAS,CAAI;EACdC,KAAK;EACfC,WAAWA,CAAA,EAAG;IACZ,IAAI,CAACD,KAAK,GAAG,IAAIE,GAAG,EAAa;EACnC;EAEAC,GAAGA,CAACC,IAAY,EAAEC,KAAQ,EAAE;IAC1B,IAAI,CAACL,KAAK,CAACG,GAAG,CAACC,IAAI,EAAEC,KAAK,CAAC;EAC7B;EAEUC,gBAAgBA,CAACC,GAAW,EAAE;IACtC,OAAOA,GAAG,CAACC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC;EACpC;EAEUC,wBAAwBA,CAACL,IAAY,EAAEM,MAAc,EAAE;IAC/D,OAAOC,WAAK,CAACC,iBAAiB,CAC5B,CAACD,WAAK,CAACE,sBAAsB,CAACF,WAAK,CAACG,UAAU,CAAC,IAAI,CAACR,gBAAgB,CAACF,IAAI,CAAC,CAAC,CAAC,CAAC,EAC7EO,WAAK,CAACI,aAAa,CAACL,MAAM,CAAC,CAC5B;EACH;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;EACYM,sBAAsBA,CAC9BC,KAAoD,EACpDP,MAAc,EACd;IACA,OAAOC,WAAK,CAACC,iBAAiB,CAC5BK,KAAK,CAACC,GAAG,CAAEC,CAAC,IACV,OAAOA,CAAC,KAAK,QAAQ,GACjBR,WAAK,CAACS,eAAe,CAACT,WAAK,CAACG,UAAU,CAACK,CAAC,CAAC,EAAER,WAAK,CAACG,UAAU,CAACK,CAAC,CAAC,CAAC,GAC/DR,WAAK,CAACS,eAAe,CACnBT,WAAK,CAACG,UAAU,CAAC,IAAI,CAACR,gBAAgB,CAACa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAC7CR,WAAK,CAACG,UAAU,CAACK,CAAC,CAAC,CAAC,CAAC,CAAC,CACvB,CACN,EACDR,WAAK,CAACI,aAAa,CAACL,MAAM,CAAC,CAC5B;EACH;AACF;AAACW,OAAA,CAAAtB,SAAA,GAAAA,SAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { MeJSON } from './utils';
|
|
2
|
+
import { Generator } from './Generator';
|
|
3
|
+
interface GetReducersBabelPluginItem {
|
|
4
|
+
meJSON: MeJSON;
|
|
5
|
+
namespace: string;
|
|
6
|
+
isExternal: boolean;
|
|
7
|
+
meJSONPath: string;
|
|
8
|
+
}
|
|
9
|
+
export declare class ReducersGenerator extends Generator<GetReducersBabelPluginItem> {
|
|
10
|
+
constructor();
|
|
11
|
+
objectPropertyValue(type: 'call' | 'string' | 'identifier', value: string): any;
|
|
12
|
+
writeCodeToFile(absPath: string): void;
|
|
13
|
+
}
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=ReducersGenerator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReducersGenerator.d.ts","sourceRoot":"","sources":["../src/ReducersGenerator.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,UAAU,0BAA0B;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,OAAO,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;CACpB;AACD,qBAAa,iBAAkB,SAAQ,SAAS,CAAC,0BAA0B,CAAC;;IAM1E,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,YAAY,EAAE,KAAK,EAAE,MAAM,GAAG,GAAG;IAe/E,eAAe,CAAC,OAAO,EAAE,MAAM;CAyDhC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ReducersGenerator = void 0;
|
|
7
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
8
|
+
var _core = require("@babel/core");
|
|
9
|
+
var _Generator = require("./Generator");
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
class ReducersGenerator extends _Generator.Generator {
|
|
12
|
+
constructor() {
|
|
13
|
+
super();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// TODO: 这里类型 加了个 any, 不太希望写else, 所以导致的问题,ts类型推导似乎不合理
|
|
17
|
+
objectPropertyValue(type, value) {
|
|
18
|
+
if (type === 'call') {
|
|
19
|
+
return _core.types.callExpression(_core.types.identifier('decorate'), [_core.types.identifier(this.identifierString(value)), _core.types.stringLiteral(value)]);
|
|
20
|
+
}
|
|
21
|
+
if (type === 'string') {
|
|
22
|
+
return _core.types.stringLiteral('');
|
|
23
|
+
}
|
|
24
|
+
if (type === 'identifier') {
|
|
25
|
+
return _core.types.identifier(this.identifierString(value));
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
writeCodeToFile(absPath) {
|
|
29
|
+
const items = Array.from(this.cache.values());
|
|
30
|
+
const code = (0, _core.transformSync)('', {
|
|
31
|
+
plugins: [() => {
|
|
32
|
+
return {
|
|
33
|
+
name: 'babel-plugin-replace-react-redux',
|
|
34
|
+
visitor: {
|
|
35
|
+
Program: {
|
|
36
|
+
enter: path => {
|
|
37
|
+
const codes = [this.importDefaultDeclaration('decorate', 'rrc-loader-helper/lib/reducer-decorate')];
|
|
38
|
+
items.filter(x => x.meJSON.sync || x.isExternal).map(x => this.importNamedDeclaration([['reducer', x.namespace]], x.meJSONPath)).forEach(x => codes.push(x));
|
|
39
|
+
const properties = items.map(x => {
|
|
40
|
+
if (x.isExternal || x.meJSON.sync) {
|
|
41
|
+
if (x.meJSON.mobx) {
|
|
42
|
+
return _core.types.objectProperty(_core.types.stringLiteral(x.namespace), this.objectPropertyValue('call', x.namespace));
|
|
43
|
+
}
|
|
44
|
+
return _core.types.objectProperty(_core.types.stringLiteral(x.namespace), this.objectPropertyValue('identifier', x.namespace));
|
|
45
|
+
}
|
|
46
|
+
return _core.types.objectProperty(_core.types.stringLiteral(x.namespace), this.objectPropertyValue('string', x.namespace));
|
|
47
|
+
});
|
|
48
|
+
codes.push(_core.types.exportDefaultDeclaration(_core.types.objectExpression(properties)));
|
|
49
|
+
path.pushContainer('body', codes);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
}]
|
|
55
|
+
});
|
|
56
|
+
_fs.default.writeFileSync(absPath, code?.code, {
|
|
57
|
+
encoding: 'utf8'
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.ReducersGenerator = ReducersGenerator;
|
|
62
|
+
//# sourceMappingURL=ReducersGenerator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReducersGenerator.js","names":["_fs","_interopRequireDefault","require","_core","_Generator","obj","__esModule","default","ReducersGenerator","Generator","constructor","objectPropertyValue","type","value","types","callExpression","identifier","identifierString","stringLiteral","writeCodeToFile","absPath","items","Array","from","cache","values","code","transformSync","plugins","name","visitor","Program","enter","path","codes","importDefaultDeclaration","filter","x","meJSON","sync","isExternal","map","importNamedDeclaration","namespace","meJSONPath","forEach","push","properties","mobx","objectProperty","exportDefaultDeclaration","objectExpression","pushContainer","fs","writeFileSync","encoding","exports"],"sources":["../ReducersGenerator.ts"],"sourcesContent":["import fs from 'fs';\nimport babelCore, { transformSync, types } from '@babel/core';\nimport type { MeJSON } from './utils';\nimport { Generator } from './Generator';\n\ninterface GetReducersBabelPluginItem {\n meJSON: MeJSON;\n namespace: string;\n isExternal: boolean;\n meJSONPath: string;\n}\nexport class ReducersGenerator extends Generator<GetReducersBabelPluginItem> {\n constructor() {\n super();\n }\n\n // TODO: 这里类型 加了个 any, 不太希望写else, 所以导致的问题,ts类型推导似乎不合理\n objectPropertyValue(type: 'call' | 'string' | 'identifier', value: string): any {\n if (type === 'call') {\n return types.callExpression(types.identifier('decorate'), [\n types.identifier(this.identifierString(value)),\n types.stringLiteral(value),\n ]);\n }\n if (type === 'string') {\n return types.stringLiteral('');\n }\n if (type === 'identifier') {\n return types.identifier(this.identifierString(value));\n }\n }\n\n writeCodeToFile(absPath: string) {\n const items = Array.from(this.cache.values());\n const code = transformSync('', {\n plugins: [\n () => {\n return {\n name: 'babel-plugin-replace-react-redux',\n visitor: {\n Program: {\n enter: (path) => {\n const codes: (\n | babelCore.types.ImportDeclaration\n | babelCore.types.ExportDefaultDeclaration\n )[] = [\n this.importDefaultDeclaration(\n 'decorate',\n 'rrc-loader-helper/lib/reducer-decorate',\n ),\n ];\n items\n .filter((x) => x.meJSON.sync || x.isExternal)\n .map((x) =>\n this.importNamedDeclaration([['reducer', x.namespace]], x.meJSONPath),\n )\n .forEach((x) => codes.push(x));\n\n const properties = items.map((x) => {\n if (x.isExternal || x.meJSON.sync) {\n if (x.meJSON.mobx) {\n return types.objectProperty(\n types.stringLiteral(x.namespace),\n this.objectPropertyValue('call', x.namespace),\n );\n }\n return types.objectProperty(\n types.stringLiteral(x.namespace),\n this.objectPropertyValue('identifier', x.namespace),\n );\n }\n return types.objectProperty(\n types.stringLiteral(x.namespace),\n this.objectPropertyValue('string', x.namespace),\n );\n });\n\n codes.push(types.exportDefaultDeclaration(types.objectExpression(properties)));\n\n path.pushContainer('body', codes);\n },\n },\n },\n };\n },\n ],\n });\n fs.writeFileSync(absPath, code?.code!, { encoding: 'utf8' });\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,GAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAEA,IAAAE,UAAA,GAAAF,OAAA;AAAwC,SAAAD,uBAAAI,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAQjC,MAAMG,iBAAiB,SAASC,oBAAS,CAA6B;EAC3EC,WAAWA,CAAA,EAAG;IACZ,KAAK,EAAE;EACT;;EAEA;EACAC,mBAAmBA,CAACC,IAAsC,EAAEC,KAAa,EAAO;IAC9E,IAAID,IAAI,KAAK,MAAM,EAAE;MACnB,OAAOE,WAAK,CAACC,cAAc,CAACD,WAAK,CAACE,UAAU,CAAC,UAAU,CAAC,EAAE,CACxDF,WAAK,CAACE,UAAU,CAAC,IAAI,CAACC,gBAAgB,CAACJ,KAAK,CAAC,CAAC,EAC9CC,WAAK,CAACI,aAAa,CAACL,KAAK,C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AAK,CAACI,aAAa,CAACmB,CAAC,CAACM,SAAS,CAAC,EAChC,IAAI,CAAChC,mBAAmB,CAAC,MAAM,EAAE0B,CAAC,CAACM,SAAS,CAAC,CAC9C;oBACH;oBACA,OAAO7B,WAAK,CAACmC,cAAc,CACzBnC,WAAK,CAACI,aAAa,CAACmB,CAAC,CAACM,SAAS,CAAC,EAChC,IAAI,CAAChC,mBAAmB,CAAC,YAAY,EAAE0B,CAAC,CAACM,SAAS,CAAC,CACpD;kBACH;kBACA,OAAO7B,WAAK,CAACmC,cAAc,CACzBnC,WAAK,CAACI,aAAa,CAACmB,CAAC,CAACM,SAAS,CAAC,EAChC,IAAI,CAAChC,mBAAmB,CAAC,QAAQ,EAAE0B,CAAC,CAACM,SAAS,CAAC,CAChD;gBACH,CAAC,CAAC;gBAEFT,KAAK,CAACY,IAAI,CAAChC,WAAK,CAACoC,wBAAwB,CAACpC,WAAK,CAACqC,gBAAgB,CAACJ,UAAU,CAAC,CAAC,CAAC;gBAE9Ed,IAAI,CAACmB,aAAa,CAAC,MAAM,EAAElB,KAAK,CAAC;cACnC;YACF;UACF;QACF,CAAC;MACH,CAAC;IAEL,CAAC,CAAC;IACFmB,WAAE,CAACC,aAAa,CAAClC,OAAO,EAAEM,IAAI,EAAEA,IAAI,EAAG;MAAE6B,QAAQ,EAAE;IAAO,CAAC,CAAC;EAC9D;AACF;AAACC,OAAA,CAAAhD,iBAAA,GAAAA,iBAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Options, MeJSON, PathService } from './utils';
|
|
2
|
+
import { Generator } from './Generator';
|
|
3
|
+
interface Item {
|
|
4
|
+
meJSONPath: string;
|
|
5
|
+
meJSON: MeJSON;
|
|
6
|
+
isExternal: boolean;
|
|
7
|
+
path: string;
|
|
8
|
+
page: string;
|
|
9
|
+
exact: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare class RoutersGenerator extends Generator<Item> {
|
|
12
|
+
config: Options;
|
|
13
|
+
pathService: PathService;
|
|
14
|
+
constructor(config: Options, pathService: PathService);
|
|
15
|
+
private errorComponentVariableDeclaration;
|
|
16
|
+
private loadingVariableDeclaration;
|
|
17
|
+
private createDowngradeValue;
|
|
18
|
+
private transform;
|
|
19
|
+
private pageImportExpression;
|
|
20
|
+
private loadableCallExpression;
|
|
21
|
+
writeCodeToFile(absPath: string): void;
|
|
22
|
+
}
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=RoutersGenerator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RoutersGenerator.d.ts","sourceRoot":"","sources":["../src/RoutersGenerator.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,UAAU,IAAI;IACZ,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,OAAO,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,OAAO,CAAC;CAChB;AAID,qBAAa,gBAAiB,SAAQ,SAAS,CAAC,IAAI,CAAC;IACnD,MAAM,EAAE,OAAO,CAAC;IAChB,WAAW,EAAE,WAAW,CAAC;gBAEb,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,WAAW;IAMrD,OAAO,CAAC,iCAAiC;IA4CzC,OAAO,CAAC,0BAA0B;IAgBlC,OAAO,CAAC,oBAAoB;IAO5B,OAAO,CAAC,SAAS;IAuBjB,OAAO,CAAC,oBAAoB;IAqC5B,OAAO,CAAC,sBAAsB;IAqC9B,eAAe,CAAC,OAAO,EAAE,MAAM;CAwGhC"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.RoutersGenerator = void 0;
|
|
7
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
8
|
+
var _core = require("@babel/core");
|
|
9
|
+
var _Generator = require("./Generator");
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
class RoutersGenerator extends _Generator.Generator {
|
|
12
|
+
config;
|
|
13
|
+
pathService;
|
|
14
|
+
constructor(config, pathService) {
|
|
15
|
+
super();
|
|
16
|
+
this.config = config;
|
|
17
|
+
this.pathService = pathService;
|
|
18
|
+
}
|
|
19
|
+
errorComponentVariableDeclaration() {
|
|
20
|
+
return _core.types.variableDeclaration('const', [_core.types.variableDeclarator(_core.types.identifier('ErrorComponent'), _core.types.arrowFunctionExpression([_core.types.identifier('props')], _core.types.blockStatement([_core.types.returnStatement(_core.types.jsxElement(_core.types.jsxOpeningElement(_core.types.jsxIdentifier('div'), [], false), _core.types.jsxClosingElement(_core.types.jsxIdentifier('div')), [_core.types.jsxElement(_core.types.jsxOpeningElement(_core.types.jsxIdentifier('h1'), [], false), _core.types.jsxClosingElement(_core.types.jsxIdentifier('h1')), [_core.types.jsxText('页面渲染发生异常')]), _core.types.jsxElement(_core.types.jsxOpeningElement(_core.types.jsxIdentifier('span'), [], false), _core.types.jsxClosingElement(_core.types.jsxIdentifier('span')), [_core.types.jsxExpressionContainer(_core.types.optionalMemberExpression(_core.types.memberExpression(_core.types.identifier('props'), _core.types.identifier('errorStack')), _core.types.identifier('message'), false, true))])], false))])))]);
|
|
21
|
+
}
|
|
22
|
+
loadingVariableDeclaration() {
|
|
23
|
+
return _core.types.variableDeclaration('const', [_core.types.variableDeclarator(_core.types.identifier('Loading'), _core.types.arrowFunctionExpression([], _core.types.blockStatement([_core.types.returnStatement(_core.types.jsxFragment(_core.types.jsxOpeningFragment(), _core.types.jsxClosingFragment(), []))])))]);
|
|
24
|
+
}
|
|
25
|
+
createDowngradeValue(meJSON) {
|
|
26
|
+
return (name, defaultValue) => {
|
|
27
|
+
/** @ts-ignore */
|
|
28
|
+
return meJSON[name] ?? this.config[name] ?? defaultValue;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
transform(item) {
|
|
32
|
+
const downgradeValue = this.createDowngradeValue(item.meJSON);
|
|
33
|
+
// 路由参数
|
|
34
|
+
let route = item.meJSON.route ?? '';
|
|
35
|
+
const keepAlive = downgradeValue('keepAlive', false);
|
|
36
|
+
const retain = downgradeValue('retain', false);
|
|
37
|
+
const title = downgradeValue('title', undefined);
|
|
38
|
+
// FUCK keep-alive 特性的坑, 为了兼容同一个页面多次打开 动态拓展 redux 的reducer 节点
|
|
39
|
+
const linkExtendable = downgradeValue('linkExtendable', false);
|
|
40
|
+
route = linkExtendable ? `${route}/:id?` : route;
|
|
41
|
+
let injectStore = downgradeValue('injectStore', false);
|
|
42
|
+
if (injectStore === true) injectStore = 'store';
|
|
43
|
+
return {
|
|
44
|
+
...item,
|
|
45
|
+
route,
|
|
46
|
+
keepAlive,
|
|
47
|
+
retain,
|
|
48
|
+
title,
|
|
49
|
+
linkExtendable,
|
|
50
|
+
injectStore
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
pageImportExpression(item) {
|
|
54
|
+
const returnObjectProperties = [_core.types.objectProperty(_core.types.identifier('module'), _core.types.identifier('module'))];
|
|
55
|
+
if (item.meJSON.sync) {
|
|
56
|
+
returnObjectProperties.push(_core.types.objectProperty(_core.types.identifier('sync'), _core.types.booleanLiteral(true)));
|
|
57
|
+
} else {
|
|
58
|
+
returnObjectProperties.push(_core.types.objectProperty(_core.types.identifier('sync'), _core.types.booleanLiteral(false)), _core.types.objectProperty(_core.types.identifier('reducers'), _core.types.identifier('reducers')));
|
|
59
|
+
}
|
|
60
|
+
const sourceAst = _core.types.stringLiteral(item.meJSONPath);
|
|
61
|
+
if (this.config.enablePreFetch) {
|
|
62
|
+
_core.types.addComment(sourceAst, 'leading', 'webpackPrefetch: true');
|
|
63
|
+
}
|
|
64
|
+
return _core.types.callExpression(_core.types.memberExpression(_core.types.callExpression(_core.types.import(), [sourceAst]), _core.types.identifier('then')), [_core.types.arrowFunctionExpression([_core.types.identifier('module')], _core.types.blockStatement([
|
|
65
|
+
// TODO
|
|
66
|
+
_core.types.returnStatement(_core.types.objectExpression(returnObjectProperties))]))]);
|
|
67
|
+
}
|
|
68
|
+
loadableCallExpression(item) {
|
|
69
|
+
return _core.types.callExpression(_core.types.identifier('Loadable'), [_core.types.objectExpression([_core.types.objectProperty(_core.types.identifier('title'), item.title ? _core.types.stringLiteral(item.title) : _core.types.nullLiteral()), _core.types.objectProperty(_core.types.identifier('keepAlive'), _core.types.booleanLiteral(item.keepAlive)), _core.types.objectProperty(_core.types.identifier('route'), _core.types.stringLiteral(item.route)), _core.types.objectProperty(_core.types.identifier('retain'), _core.types.booleanLiteral(item.retain)), _core.types.objectProperty(_core.types.identifier('injectStore'), typeof item.injectStore === 'boolean' ? _core.types.booleanLiteral(item.injectStore) : _core.types.stringLiteral(item.injectStore)), _core.types.objectProperty(_core.types.identifier('page'), _core.types.stringLiteral(item.page)), _core.types.objectProperty(_core.types.identifier('loading'), _core.types.identifier('Loading')), _core.types.objectProperty(_core.types.identifier('errorComponent'), _core.types.identifier('ErrorComponent')), _core.types.objectProperty(_core.types.identifier('metaInfo'), _core.types.callExpression(_core.types.memberExpression(_core.types.identifier('JSON'), _core.types.identifier('parse')), [_core.types.stringLiteral(JSON.stringify(item.meJSON))])), _core.types.objectProperty(_core.types.identifier('loader'), _core.types.arrowFunctionExpression([], this.pageImportExpression(item)))])]);
|
|
70
|
+
}
|
|
71
|
+
writeCodeToFile(absPath) {
|
|
72
|
+
const items = Array.from(this.cache.values());
|
|
73
|
+
const code = (0, _core.transformSync)('', {
|
|
74
|
+
plugins: [() => {
|
|
75
|
+
return {
|
|
76
|
+
name: 'babel-plugin-replace-react-redux',
|
|
77
|
+
visitor: {
|
|
78
|
+
Program: {
|
|
79
|
+
enter: path => {
|
|
80
|
+
const ast = [this.importNamedDeclaration([], 'rrc-loader-helper/lib/fake-react'), this.importDefaultDeclaration('Loadable', 'rrc-loader-helper/lib/loadable'), this.importDefaultDeclaration('React', 'react')];
|
|
81
|
+
|
|
82
|
+
/** 如果用户没有指定loading组件,那么自动生成一个空 loading */
|
|
83
|
+
if (this.config.loading) {
|
|
84
|
+
ast.push(this.importDefaultDeclaration('Loading', this.config.loading));
|
|
85
|
+
} else {
|
|
86
|
+
ast.push(this.loadingVariableDeclaration());
|
|
87
|
+
}
|
|
88
|
+
if (this.config.errorComponent) {
|
|
89
|
+
ast.push(this.importDefaultDeclaration('ErrorComponent', this.config.errorComponent));
|
|
90
|
+
} else {
|
|
91
|
+
ast.push(this.errorComponentVariableDeclaration());
|
|
92
|
+
}
|
|
93
|
+
if (this.config.theme?.hash) {
|
|
94
|
+
ast.push(this.importNamedDeclaration(['toGlobalTheme'], this.pathService.getThemeJSCacheFileAbs(this.config.theme?.hash)));
|
|
95
|
+
ast.push(_core.types.expressionStatement(_core.types.optionalCallExpression(_core.types.identifier('toGlobalTheme'), [], true)));
|
|
96
|
+
}
|
|
97
|
+
const _ = items.filter(x => !x.isExternal).map(x => this.transform(x)).map(x => {
|
|
98
|
+
const path = this.config.dangerousRoute || !x.exact ? `/${x.path}${x.route}` : `/${x.path}`;
|
|
99
|
+
return _core.types.objectExpression([_core.types.objectProperty(_core.types.identifier('exact'), _core.types.booleanLiteral(x.exact)), _core.types.objectProperty(_core.types.identifier('keepAlive'), _core.types.booleanLiteral(x.keepAlive)), _core.types.objectProperty(_core.types.identifier('key'), _core.types.stringLiteral(path)), _core.types.objectProperty(_core.types.identifier('path'), _core.types.stringLiteral(path)), _core.types.objectProperty(_core.types.identifier('component'), this.loadableCallExpression(x))]);
|
|
100
|
+
});
|
|
101
|
+
ast.push(_core.types.exportDefaultDeclaration(_core.types.arrowFunctionExpression([_core.types.identifier('reducers')], _core.types.blockStatement([_core.types.returnStatement(_core.types.arrayExpression(_))]))));
|
|
102
|
+
path.pushContainer('body', ast);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
}]
|
|
108
|
+
});
|
|
109
|
+
_fs.default.writeFileSync(absPath, [JSON.stringify(`👹 pages total count is ${Array.from(this.cache.keys()).length}`), code?.code].join(';\r\n'), {
|
|
110
|
+
encoding: 'utf8'
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
exports.RoutersGenerator = RoutersGenerator;
|
|
115
|
+
//# sourceMappingURL=RoutersGenerator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RoutersGenerator.js","names":["_fs","_interopRequireDefault","require","_core","_Generator","obj","__esModule","default","RoutersGenerator","Generator","config","pathService","constructor","errorComponentVariableDeclaration","types","variableDeclaration","variableDeclarator","identifier","arrowFunctionExpression","blockStatement","returnStatement","jsxElement","jsxOpeningElement","jsxIdentifier","jsxClosingElement","jsxText","jsxExpressionContainer","optionalMemberExpression","memberExpression","loadingVariableDeclaration","jsxFragment","jsxOpeningFragment","jsxClosingFragment","createDowngradeValue","meJSON","name","defaultValue","transform","item","downgradeValue","route","keepAlive","retain","title","undefined","linkExtendable","injectStore","pageImportExpression","returnObjectProperties","objectProperty","sync","push","booleanLiteral","sourceAst","stringLiteral","meJSONPath","enablePreFetch","addComment","callExpression","import","objectExpression","loadableCallExpression","nullLiteral","page","JSON","stringify","writeCodeToFile","absPath","items","Array","from","cache","values","code","transformSync","plugins","visitor","Program","enter","path","ast","importNamedDeclaration","importDefaultDeclaration","loading","errorComponent","theme","hash","getThemeJSCacheFileAbs","expressionStatement","optionalCallExpression","_","filter","x","isExternal","map","dangerousRoute","exact","exportDefaultDeclaration","arrayExpression","pushContainer","fs","writeFileSync","keys","length","join","encoding","exports"],"sources":["../RoutersGenerator.ts"],"sourcesContent":["import fs from 'fs';\nimport { transformSync, types } from '@babel/core';\nimport type { Options, MeJSON, PathService } from './utils';\nimport { Generator } from './Generator';\n\ninterface Item {\n meJSONPath: string;\n meJSON: MeJSON;\n isExternal: boolean;\n path: string;\n page: string;\n exact: boolean;\n}\n\ninterface TransformItem extends Item, MeJSON {}\n\nexport class RoutersGenerator extends Generator<Item> {\n config: Options;\n pathService: PathService;\n\n constructor(config: Options, pathService: PathService) {\n super();\n this.config = config;\n this.pathService = pathService;\n }\n\n private errorComponentVariableDeclaration() {\n return types.variableDeclaration('const', [\n types.variableDeclarator(\n types.identifier('ErrorComponent'),\n types.arrowFunctionExpression(\n [types.identifier('props')],\n types.blockStatement([\n types.returnStatement(\n types.jsxElement(\n types.jsxOpeningElement(types.jsxIdentifier('div'), [], false),\n types.jsxClosingElement(types.jsxIdentifier('div')),\n [\n types.jsxElement(\n types.jsxOpeningElement(types.jsxIdentifier('h1'), [], false),\n types.jsxClosingElement(types.jsxIdentifier('h1')),\n [types.jsxText('页面渲染发生异常')],\n ),\n types.jsxElement(\n types.jsxOpeningElement(types.jsxIdentifier('span'), [], false),\n types.jsxClosingElement(types.jsxIdentifier('span')),\n [\n types.jsxExpressionContainer(\n types.optionalMemberExpression(\n types.memberExpression(\n types.identifier('props'),\n types.identifier('errorStack'),\n ),\n types.identifier('message'),\n false,\n true,\n ),\n ),\n ],\n ),\n ],\n false,\n ),\n ),\n ]),\n ),\n ),\n ]);\n }\n\n private loadingVariableDeclaration() {\n return types.variableDeclaration('const', [\n types.variableDeclarator(\n types.identifier('Loading'),\n types.arrowFunctionExpression(\n [],\n types.blockStatement([\n types.returnStatement(\n types.jsxFragment(types.jsxOpeningFragment(), types.jsxClosingFragment(), []),\n ),\n ]),\n ),\n ),\n ]);\n }\n\n private createDowngradeValue(meJSON: MeJSON) {\n return <T extends keyof MeJSON>(name: T, defaultValue: MeJSON[T]) => {\n /** @ts-ignore */\n return meJSON[name] ?? this.config[name] ?? defaultValue;\n };\n }\n\n private transform(item: Item): TransformItem {\n const downgradeValue = this.createDowngradeValue(item.meJSON);\n // 路由参数\n let route = item.meJSON.route ?? '';\n const keepAlive = downgradeValue('keepAlive', false);\n const retain = downgradeValue('retain', false);\n const title = downgradeValue('title', undefined);\n // FUCK keep-alive 特性的坑, 为了兼容同一个页面多次打开 动态拓展 redux 的reducer 节点\n const linkExtendable = downgradeValue('linkExtendable', false);\n route = linkExtendable ? `${route}/:id?` : route;\n let injectStore = downgradeValue('injectStore', false);\n if (injectStore === true) injectStore = 'store';\n return {\n ...item,\n route,\n keepAlive,\n retain,\n title,\n linkExtendable,\n injectStore,\n };\n }\n\n private pageImportExpression(item: TransformItem) {\n const returnObjectProperties = [\n types.objectProperty(types.identifier('module'), types.identifier('module')),\n ];\n if (item.meJSON.sync) {\n returnObjectProperties.push(\n types.objectProperty(types.identifier('sync'), types.booleanLiteral(true)),\n );\n } else {\n returnObjectProperties.push(\n types.objectProperty(types.identifier('sync'), types.booleanLiteral(false)),\n types.objectProperty(types.identifier('reducers'), types.identifier('reducers')),\n );\n }\n const sourceAst = types.stringLiteral(item.meJSONPath);\n\n if (this.config.enablePreFetch) {\n types.addComment(sourceAst, 'leading', 'webpackPrefetch: true');\n }\n\n return types.callExpression(\n types.memberExpression(\n types.callExpression(types.import(), [sourceAst]),\n types.identifier('then'),\n ),\n [\n types.arrowFunctionExpression(\n [types.identifier('module')],\n types.blockStatement([\n // TODO\n types.returnStatement(types.objectExpression(returnObjectProperties)),\n ]),\n ),\n ],\n );\n }\n\n private loadableCallExpression(item: TransformItem) {\n return types.callExpression(types.identifier('Loadable'), [\n types.objectExpression([\n types.objectProperty(\n types.identifier('title'),\n item.title ? types.stringLiteral(item.title) : types.nullLiteral(),\n ),\n types.objectProperty(types.identifier('keepAlive'), types.booleanLiteral(item.keepAlive!)),\n types.objectProperty(types.identifier('route'), types.stringLiteral(item.route!)),\n types.objectProperty(types.identifier('retain'), types.booleanLiteral(item.retain!)),\n types.objectProperty(\n types.identifier('injectStore'),\n typeof item.injectStore === 'boolean'\n ? types.booleanLiteral(item.injectStore)\n : types.stringLiteral(item.injectStore!),\n ),\n types.objectProperty(types.identifier('page'), types.stringLiteral(item.page)),\n types.objectProperty(types.identifier('loading'), types.identifier('Loading')),\n types.objectProperty(\n types.identifier('errorComponent'),\n types.identifier('ErrorComponent'),\n ),\n types.objectProperty(\n types.identifier('metaInfo'),\n types.callExpression(\n types.memberExpression(types.identifier('JSON'), types.identifier('parse')),\n [types.stringLiteral(JSON.stringify(item.meJSON))],\n ),\n ),\n types.objectProperty(\n types.identifier('loader'),\n types.arrowFunctionExpression([], this.pageImportExpression(item)),\n ),\n ]),\n ]);\n }\n\n writeCodeToFile(absPath: string) {\n const items = Array.from(this.cache.values());\n const code = transformSync('', {\n plugins: [\n () => {\n return {\n name: 'babel-plugin-replace-react-redux',\n visitor: {\n Program: {\n enter: (path) => {\n const ast: (\n | types.ImportDeclaration\n | types.VariableDeclaration\n | types.ExportDefaultDeclaration\n | types.ExpressionStatement\n )[] = [\n this.importNamedDeclaration([], 'rrc-loader-helper/lib/fake-react'),\n this.importDefaultDeclaration('Loadable', 'rrc-loader-helper/lib/loadable'),\n this.importDefaultDeclaration('React', 'react'),\n ];\n\n /** 如果用户没有指定loading组件,那么自动生成一个空 loading */\n if (this.config.loading) {\n ast.push(this.importDefaultDeclaration('Loading', this.config.loading));\n } else {\n ast.push(this.loadingVariableDeclaration());\n }\n\n if (this.config.errorComponent) {\n ast.push(\n this.importDefaultDeclaration('ErrorComponent', this.config.errorComponent),\n );\n } else {\n ast.push(this.errorComponentVariableDeclaration());\n }\n\n if (this.config.theme?.hash) {\n ast.push(\n this.importNamedDeclaration(\n ['toGlobalTheme'],\n this.pathService.getThemeJSCacheFileAbs(this.config.theme?.hash),\n ),\n );\n ast.push(\n types.expressionStatement(\n types.optionalCallExpression(types.identifier('toGlobalTheme'), [], true),\n ),\n );\n }\n\n const _ = items\n .filter((x) => !x.isExternal)\n .map((x) => this.transform(x))\n .map((x) => {\n const path =\n this.config.dangerousRoute || !x.exact\n ? `/${x.path}${x.route}`\n : `/${x.path}`;\n return types.objectExpression([\n types.objectProperty(\n types.identifier('exact'),\n types.booleanLiteral(x.exact),\n ),\n types.objectProperty(\n types.identifier('keepAlive'),\n types.booleanLiteral(x.keepAlive!),\n ),\n types.objectProperty(types.identifier('key'), types.stringLiteral(path)),\n types.objectProperty(types.identifier('path'), types.stringLiteral(path)),\n types.objectProperty(\n types.identifier('component'),\n this.loadableCallExpression(x),\n ),\n ]);\n });\n ast.push(\n types.exportDefaultDeclaration(\n types.arrowFunctionExpression(\n [types.identifier('reducers')],\n types.blockStatement([types.returnStatement(types.arrayExpression(_))]),\n ),\n ),\n );\n\n path.pushContainer('body', ast);\n },\n },\n },\n };\n },\n ],\n });\n\n fs.writeFileSync(\n absPath,\n [\n JSON.stringify(`👹 pages total count is ${Array.from(this.cache.keys()).length}`),\n code?.code!,\n ].join(';\\r\\n'),\n {\n encoding: 'utf8',\n },\n );\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,GAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAEA,IAAAE,UAAA,GAAAF,OAAA;AAAwC,SAAAD,uBAAAI,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAajC,MAAMG,gBAAgB,SAASC,oBAAS,CAAO;EACpDC,MAAM;EACNC,WAAW;EAEXC,WAAWA,CAACF,MAAe,EAAEC,WAAwB,EAAE;IACrD,KAAK,EAAE;IACP,IAAI,CAACD,MAAM,GAAGA,MAAM;IACpB,IAAI,CAACC,WAAW,GAAGA,WAAW;EAChC;EAEQE,iCAAiCA,CAAA,EAAG;IAC1C,OAAOC,WAAK,CAACC,mBAAmB,CAAC,OAAO,EAAE,CACxCD,WAAK,CAACE,kBAAkB,CACtBF,WAAK,CAACG,UAAU,CAAC,gBAAgB,CAAC,EAClCH,WAAK,CAACI,uBAAuB,CAC3B,CAACJ,WAAK,CAACG,UAAU,CAAC,OAAO,CAAC,C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CACF;gBAEDX,IAAI,CAACoB,aAAa,CAAC,MAAM,EAAEnB,GAAG,CAAC;cACjC;YACF;UACF;QACF,CAAC;MACH,CAAC;IAEL,CAAC,CAAC;IAEFoB,WAAE,CAACC,aAAa,CACdlC,OAAO,EACP,CACEH,IAAI,CAACC,SAAS,CAAE,2BAA0BI,KAAK,CAACC,IAAI,CAAC,IAAI,CAACC,KAAK,CAAC+B,IAAI,EAAE,CAAC,CAACC,MAAO,EAAC,CAAC,EACjF9B,IAAI,EAAEA,IAAI,CACX,CAAC+B,IAAI,CAAC,OAAO,CAAC,EACf;MACEC,QAAQ,EAAE;IACZ,CAAC,CACF;EACH;AACF;AAACC,OAAA,CAAAlG,gBAAA,GAAAA,gBAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Generator } from './Generator';
|
|
2
|
+
import type { MeJSON } from './utils';
|
|
3
|
+
interface Item {
|
|
4
|
+
namespace: string;
|
|
5
|
+
meJSONPath: string;
|
|
6
|
+
isExternal: boolean;
|
|
7
|
+
meJSON: MeJSON;
|
|
8
|
+
}
|
|
9
|
+
export declare class SagasGenerator extends Generator<Item> {
|
|
10
|
+
constructor();
|
|
11
|
+
private setCtxExpressionStatement;
|
|
12
|
+
private callExpressionStatement;
|
|
13
|
+
writeCodeToFile(absPath: string): void;
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=SagasGenerator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SagasGenerator.d.ts","sourceRoot":"","sources":["../src/SagasGenerator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAGtC,UAAU,IAAI;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,OAAO,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;CAChB;AACD,qBAAa,cAAe,SAAQ,SAAS,CAAC,IAAI,CAAC;;IAKjD,OAAO,CAAC,yBAAyB;IAcjC,OAAO,CAAC,uBAAuB;IAa/B,eAAe,CAAC,OAAO,EAAE,MAAM;CA0DhC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.SagasGenerator = void 0;
|
|
7
|
+
var _Generator = require("./Generator");
|
|
8
|
+
var _core = require("@babel/core");
|
|
9
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
class SagasGenerator extends _Generator.Generator {
|
|
12
|
+
constructor() {
|
|
13
|
+
super();
|
|
14
|
+
}
|
|
15
|
+
setCtxExpressionStatement(namespace) {
|
|
16
|
+
return _core.types.expressionStatement(_core.types.yieldExpression(_core.types.callExpression(_core.types.identifier('setCtx'), [_core.types.objectExpression([_core.types.objectProperty(_core.types.identifier('mobxStyle'), _core.types.booleanLiteral(true)), _core.types.objectProperty(_core.types.identifier('page'), _core.types.stringLiteral(namespace)), _core.types.objectProperty(_core.types.identifier('url'), _core.types.stringLiteral(''))])])));
|
|
17
|
+
}
|
|
18
|
+
callExpressionStatement(namespace) {
|
|
19
|
+
return _core.types.expressionStatement(_core.types.yieldExpression(_core.types.callExpression(_core.types.identifier('call'), [_core.types.memberExpression(_core.types.identifier(this.identifierString(namespace)), _core.types.identifier('saga'))])));
|
|
20
|
+
}
|
|
21
|
+
writeCodeToFile(absPath) {
|
|
22
|
+
const items = Array.from(this.cache.values());
|
|
23
|
+
const code = (0, _core.transformSync)('', {
|
|
24
|
+
plugins: [() => {
|
|
25
|
+
return {
|
|
26
|
+
visitor: {
|
|
27
|
+
Program: {
|
|
28
|
+
enter: path => {
|
|
29
|
+
const ast = [this.importNamedDeclaration(['setCtx'], 'rrc-loader-helper/lib/retain'), this.importNamedDeclaration(['call'], 'rrc-loader-helper/lib/sagas/redux-saga/effects')];
|
|
30
|
+
items.filter(x => x.meJSON.sync || x.isExternal).forEach(x =>
|
|
31
|
+
// 如果是mobx, 取 reducer, 否则取 saga
|
|
32
|
+
ast.push(this.importNamedDeclaration([[x.meJSON.mobx ? 'reducer' : 'saga', x.namespace]], x.meJSONPath)));
|
|
33
|
+
const arrayItem = items.map(x => {
|
|
34
|
+
if (!x.isExternal && !x.meJSON.sync) {
|
|
35
|
+
return _core.types.stringLiteral('');
|
|
36
|
+
}
|
|
37
|
+
if (x.meJSON.mobx) {
|
|
38
|
+
return _core.types.functionExpression(null, [], _core.types.blockStatement([this.setCtxExpressionStatement(x.namespace), this.callExpressionStatement(x.namespace)]), true, false);
|
|
39
|
+
}
|
|
40
|
+
return _core.types.identifier(this.identifierString(x.namespace));
|
|
41
|
+
});
|
|
42
|
+
ast.push(_core.types.exportDefaultDeclaration(_core.types.arrayExpression(arrayItem)));
|
|
43
|
+
path.pushContainer('body', ast);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}]
|
|
49
|
+
});
|
|
50
|
+
_fs.default.writeFileSync(absPath, code?.code, {
|
|
51
|
+
encoding: 'utf8'
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.SagasGenerator = SagasGenerator;
|
|
56
|
+
//# sourceMappingURL=SagasGenerator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SagasGenerator.js","names":["_Generator","require","_core","_fs","_interopRequireDefault","obj","__esModule","default","SagasGenerator","Generator","constructor","setCtxExpressionStatement","namespace","types","expressionStatement","yieldExpression","callExpression","identifier","objectExpression","objectProperty","booleanLiteral","stringLiteral","callExpressionStatement","memberExpression","identifierString","writeCodeToFile","absPath","items","Array","from","cache","values","code","transformSync","plugins","visitor","Program","enter","path","ast","importNamedDeclaration","filter","x","meJSON","sync","isExternal","forEach","push","mobx","meJSONPath","arrayItem","map","functionExpression","blockStatement","exportDefaultDeclaration","arrayExpression","pushContainer","fs","writeFileSync","encoding","exports"],"sources":["../SagasGenerator.ts"],"sourcesContent":["import { Generator } from './Generator';\nimport type { MeJSON } from './utils';\nimport { transformSync, types } from '@babel/core';\nimport fs from 'fs';\ninterface Item {\n namespace: string;\n meJSONPath: string;\n isExternal: boolean;\n meJSON: MeJSON;\n}\nexport class SagasGenerator extends Generator<Item> {\n constructor() {\n super();\n }\n\n private setCtxExpressionStatement(namespace: string) {\n return types.expressionStatement(\n types.yieldExpression(\n types.callExpression(types.identifier('setCtx'), [\n types.objectExpression([\n types.objectProperty(types.identifier('mobxStyle'), types.booleanLiteral(true)),\n types.objectProperty(types.identifier('page'), types.stringLiteral(namespace)),\n types.objectProperty(types.identifier('url'), types.stringLiteral('')),\n ]),\n ]),\n ),\n );\n }\n\n private callExpressionStatement(namespace: string) {\n return types.expressionStatement(\n types.yieldExpression(\n types.callExpression(types.identifier('call'), [\n types.memberExpression(\n types.identifier(this.identifierString(namespace)),\n types.identifier('saga'),\n ),\n ]),\n ),\n );\n }\n\n writeCodeToFile(absPath: string) {\n const items = Array.from(this.cache.values());\n const code = transformSync('', {\n plugins: [\n () => {\n return {\n visitor: {\n Program: {\n enter: (path) => {\n const ast: (types.ImportDeclaration | types.ExportDefaultDeclaration)[] = [\n this.importNamedDeclaration(['setCtx'], 'rrc-loader-helper/lib/retain'),\n this.importNamedDeclaration(\n ['call'],\n 'rrc-loader-helper/lib/sagas/redux-saga/effects',\n ),\n ];\n\n items\n .filter((x) => x.meJSON.sync || x.isExternal)\n .forEach((x) =>\n // 如果是mobx, 取 reducer, 否则取 saga\n ast.push(\n this.importNamedDeclaration(\n [[x.meJSON.mobx ? 'reducer' : 'saga', x.namespace]],\n x.meJSONPath,\n ),\n ),\n );\n\n const arrayItem = items.map((x) => {\n if (!x.isExternal && !x.meJSON.sync) {\n return types.stringLiteral('');\n }\n if (x.meJSON.mobx) {\n return types.functionExpression(\n null,\n [],\n types.blockStatement([\n this.setCtxExpressionStatement(x.namespace),\n this.callExpressionStatement(x.namespace),\n ]),\n true,\n false,\n );\n }\n return types.identifier(this.identifierString(x.namespace));\n });\n ast.push(types.exportDefaultDeclaration(types.arrayExpression(arrayItem)));\n path.pushContainer('body', ast);\n },\n },\n },\n };\n },\n ],\n });\n fs.writeFileSync(absPath, code?.code!, { encoding: 'utf8' });\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,UAAA,GAAAC,OAAA;AAEA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,GAAA,GAAAC,sBAAA,CAAAH,OAAA;AAAoB,SAAAG,uBAAAC,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAOb,MAAMG,cAAc,SAASC,oBAAS,CAAO;EAClDC,WAAWA,CAAA,EAAG;IACZ,KAAK,EAAE;EACT;EAEQC,yBAAyBA,CAACC,SAAiB,EAAE;IACnD,OAAOC,WAAK,CAACC,mBAAmB,CAC9BD,WAAK,CAACE,eAAe,CACnBF,WAAK,CAACG,cAAc,CAACH,WAAK,CAACI,UAAU,CAAC,QAAQ,CAAC,EAAE,CAC/CJ,WAAK,CAACK,gBAAgB,CAAC,CACrBL,WAAK,CAACM,cAAc,CAACN,WAAK,CAACI,UAAU,CAAC,WAAW,CAAC,EAAEJ,WAAK,CAACO,cAAc,CAAC,IAAI,CAAC,CAAC,EAC/EP,WAAK,CAACM,cAAc,CAACN,WAAK,CAACI,UAAU,CAAC,MAAM,CAAC,EAAEJ,WAAK,CAACQ,aAAa,CAACT,SAAS,CAAC,CAAC,EAC9EC,WAAK,CAACM,cAAc,CAACN,WAAK,CAACI,UAAU,CAAC,KAAK,CAAC,EAAEJ,WAAK,CAACQ,aAAa,CAAC,EAAE,CAAC,CAAC,CACvE,CAAC,CACH,CA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AG,CAAET,CAAC,IAAK;kBACjC,IAAI,CAACA,CAAC,CAACG,UAAU,IAAI,CAACH,CAAC,CAACC,MAAM,CAACC,IAAI,EAAE;oBACnC,OAAO/B,WAAK,CAACQ,aAAa,CAAC,EAAE,CAAC;kBAChC;kBACA,IAAIqB,CAAC,CAACC,MAAM,CAACK,IAAI,EAAE;oBACjB,OAAOnC,WAAK,CAACuC,kBAAkB,CAC7B,IAAI,EACJ,EAAE,EACFvC,WAAK,CAACwC,cAAc,CAAC,CACnB,IAAI,CAAC1C,yBAAyB,CAAC+B,CAAC,CAAC9B,SAAS,CAAC,EAC3C,IAAI,CAACU,uBAAuB,CAACoB,CAAC,CAAC9B,SAAS,CAAC,CAC1C,CAAC,EACF,IAAI,EACJ,KAAK,CACN;kBACH;kBACA,OAAOC,WAAK,CAACI,UAAU,CAAC,IAAI,CAACO,gBAAgB,CAACkB,CAAC,CAAC9B,SAAS,CAAC,CAAC;gBAC7D,CAAC,CAAC;gBACF2B,GAAG,CAACQ,IAAI,CAAClC,WAAK,CAACyC,wBAAwB,CAACzC,WAAK,CAAC0C,eAAe,CAACL,SAAS,CAAC,CAAC,CAAC;gBAC1EZ,IAAI,CAACkB,aAAa,CAAC,MAAM,EAAEjB,GAAG,CAAC;cACjC;YACF;UACF;QACF,CAAC;MACH,CAAC;IAEL,CAAC,CAAC;IACFkB,WAAE,CAACC,aAAa,CAAChC,OAAO,EAAEM,IAAI,EAAEA,IAAI,EAAG;MAAE2B,QAAQ,EAAE;IAAO,CAAC,CAAC;EAC9D;AACF;AAACC,OAAA,CAAApD,cAAA,GAAAA,cAAA"}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Compiler, WebpackPluginInstance } from 'webpack';
|
|
2
|
+
import { Options } from './utils';
|
|
3
|
+
export default class LcdRouterWebpackPlugin implements WebpackPluginInstance {
|
|
4
|
+
options: Options;
|
|
5
|
+
constructor(options: Options);
|
|
6
|
+
apply(compiler: Compiler): void;
|
|
7
|
+
mergeOptions(compiler: Compiler): void;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAI/D,OAAO,EAAyB,OAAO,EAAe,MAAM,SAAS,CAAC;AAOtE,MAAM,CAAC,OAAO,OAAO,sBAAuB,YAAW,qBAAqB;IAC1E,OAAO,EAAE,OAAO,CAAC;gBACL,OAAO,EAAE,OAAO;IAI5B,KAAK,CAAC,QAAQ,EAAE,QAAQ;IA8KxB,YAAY,CAAC,QAAQ,EAAE,QAAQ;CAYhC"}
|