lcd-router-webpack-plugin 9.2.1-alpha.1 → 9.2.1-alpha.3

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.
@@ -2,6 +2,7 @@ export declare class Generator<T> {
2
2
  protected cache: Map<string, T>;
3
3
  constructor();
4
4
  set(name: string, value: T): void;
5
+ clear(): void;
5
6
  protected identifierString(arg: string): string;
6
7
  protected importDefaultDeclaration(name: string, source: string): any;
7
8
  /**
@@ -1 +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;IAI/D;;;;;;OAMG;IACH,SAAS,CAAC,sBAAsB,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM;CAUtG"}
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,KAAK;IAIL,SAAS,CAAC,gBAAgB,CAAC,GAAG,EAAE,MAAM;IAItC,SAAS,CAAC,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAI/D;;;;;;OAMG;IACH,SAAS,CAAC,sBAAsB,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM;CAUtG"}
package/lib/Generator.js CHANGED
@@ -13,6 +13,9 @@ class Generator {
13
13
  set(name, value) {
14
14
  this.cache.set(name, value);
15
15
  }
16
+ clear() {
17
+ this.cache.clear();
18
+ }
16
19
  identifierString(arg) {
17
20
  return arg.replace(/(\/|-)/g, '_');
18
21
  }
@@ -1 +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([types.importDefaultSpecifier(types.identifier(this.identifierString(name)))], types.stringLiteral(source));\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(names: Array<string | [name: string, alias: string]>, source: string) {\n return types.importDeclaration(\n names.map((x) =>\n typeof x === 'string'\n ? types.importSpecifier(types.identifier(x), types.identifier(x))\n : types.importSpecifier(types.identifier(this.identifierString(x[1])), types.identifier(x[0])),\n ),\n types.stringLiteral(source),\n );\n }\n}\n"],"mappings":";;;;;;A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 {"version":3,"file":"Generator.js","names":["_core","require","Generator","cache","constructor","Map","set","name","value","clear","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 clear() {\n this.cache.clear();\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([types.importDefaultSpecifier(types.identifier(this.identifierString(name)))], types.stringLiteral(source));\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(names: Array<string | [name: string, alias: string]>, source: string) {\n return types.importDeclaration(\n names.map((x) =>\n typeof x === 'string'\n ? types.importSpecifier(types.identifier(x), types.identifier(x))\n : types.importSpecifier(types.identifier(this.identifierString(x[1])), types.identifier(x[0])),\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;EAEAC,KAAKA,CAAA,EAAG;IACN,IAAI,CAACN,KAAK,CAACM,KAAK,EAAE;EACpB;EAEUC,gBAAgBA,CAACC,GAAW,EAAE;IACtC,OAAOA,GAAG,CAACC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC;EACpC;EAEUC,wBAAwBA,CAACN,IAAY,EAAEO,MAAc,EAAE;IAC/D,OAAOC,WAAK,CAACC,iBAAiB,CAAC,CAACD,WAAK,CAACE,sBAAsB,CAACF,WAAK,CAACG,UAAU,CAAC,IAAI,CAACR,gBAAgB,CAACH,IAAI,CAAC,CAAC,CAAC,CAAC,EAAEQ,WAAK,CAACI,aAAa,CAACL,MAAM,CAAC,CAAC;EAC5I;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;EACYM,sBAAsBA,CAACC,KAAoD,EAAEP,MAAc,EAAE;IACrG,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,CAACT,WAAK,CAACG,UAAU,CAAC,IAAI,CAACR,gBAAgB,CAACa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAER,WAAK,CAACG,UAAU,CAACK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CACjG,EACDR,WAAK,CAACI,aAAa,CAACL,MAAM,CAAC,CAC5B;EACH;AACF;AAACW,OAAA,CAAAvB,SAAA,GAAAA,SAAA"}
@@ -1,7 +1,7 @@
1
1
  import type { Options, MeJSON, PathService } from './utils';
2
2
  import { Generator } from './Generator';
3
3
  interface Item {
4
- meJSONPath: string;
4
+ meJSONRelativePath: string;
5
5
  meJSON: MeJSON;
6
6
  isExternal: boolean;
7
7
  path: string;
@@ -1 +1 @@
1
- {"version":3,"file":"RoutersGenerator.d.ts","sourceRoot":"","sources":["../src/RoutersGenerator.ts"],"names":[],"mappings":"AAEA,OAA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AM,EAAE,OAAO,EAAE,WAAW,EAAE,WAAW;IAMrD,OAAO,CAAC,iCAAiC;IAyCzC,OAAO,CAAC,0BAA0B;IAYlC,OAAO,CAAC,oBAAoB;IAO5B,OAAO,CAAC,SAAS;IAuBjB,OAAO,CAAC,oBAAoB;IA2B5B,OAAO,CAAC,sBAAsB;IAyB9B,eAAe,CAAC,OAAO,EAAE,MAAM;CAmFhC"}
@@ -57,7 +57,7 @@ class RoutersGenerator extends _Generator.Generator {
57
57
  } else {
58
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
59
  }
60
- const sourceAst = _core.types.stringLiteral(item.meJSONPath);
60
+ const sourceAst = _core.types.stringLiteral(item.meJSONRelativePath);
61
61
  if (this.config.enablePreFetch) {
62
62
  _core.types.addComment(sourceAst, 'leading', 'webpackPrefetch: true');
63
63
  }
@@ -91,7 +91,7 @@ class RoutersGenerator extends _Generator.Generator {
91
91
  ast.push(this.errorComponentVariableDeclaration());
92
92
  }
93
93
  if (this.config.theme?.hash) {
94
- ast.push(this.importNamedDeclaration(['toGlobalTheme'], this.pathService.getThemeJSCacheFileAbs(this.config.theme?.hash)));
94
+ ast.push(this.importNamedDeclaration(['toGlobalTheme'], this.pathService.getThemePath(this.config.theme.hash)));
95
95
  ast.push(_core.types.expressionStatement(_core.types.optionalCallExpression(_core.types.identifier('toGlobalTheme'), [], true)));
96
96
  }
97
97
  const _ = items.filter(x => !x.isExternal).map(x => this.transform(x)).map(x => {
@@ -1 +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","routeList","exportNamedDeclaration","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(types.identifier('props'), types.identifier('errorStack')),\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([types.returnStatement(types.jsxFragment(types.jsxOpeningFragment(), types.jsxClosingFragment(), []))]),\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 = [types.objectProperty(types.identifier('module'), types.identifier('module'))];\n if (item.meJSON.sync) {\n returnObjectProperties.push(types.objectProperty(types.identifier('sync'), types.booleanLiteral(true)));\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(types.memberExpression(types.callExpression(types.import(), [sourceAst]), types.identifier('then')), [\n types.arrowFunctionExpression(\n [types.identifier('module')],\n types.blockStatement([\n // TODO\n types.returnStatement(types.objectExpression(returnObjectProperties)),\n ]),\n ),\n ]);\n }\n\n private loadableCallExpression(item: TransformItem) {\n return types.callExpression(types.identifier('Loadable'), [\n types.objectExpression([\n types.objectProperty(types.identifier('title'), item.title ? types.stringLiteral(item.title) : types.nullLiteral()),\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' ? types.booleanLiteral(item.injectStore) : 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(types.identifier('errorComponent'), types.identifier('ErrorComponent')),\n types.objectProperty(\n types.identifier('metaInfo'),\n types.callExpression(types.memberExpression(types.identifier('JSON'), types.identifier('parse')), [\n types.stringLiteral(JSON.stringify(item.meJSON)),\n ]),\n ),\n types.objectProperty(types.identifier('loader'), types.arrowFunctionExpression([], this.pageImportExpression(item))),\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: (types.ImportDeclaration | types.VariableDeclaration | types.ExportDefaultDeclaration | types.ExpressionStatement)[] = [\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(this.importDefaultDeclaration('ErrorComponent', this.config.errorComponent));\n } else {\n ast.push(this.errorComponentVariableDeclaration());\n }\n\n if (this.config.theme?.hash) {\n ast.push(this.importNamedDeclaration(['toGlobalTheme'], this.pathService.getThemeJSCacheFileAbs(this.config.theme?.hash)));\n ast.push(types.expressionStatement(types.optionalCallExpression(types.identifier('toGlobalTheme'), [], true)));\n }\n\n const _ = items\n .filter((x) => !x.isExternal)\n .map((x) => this.transform(x))\n .map((x) => {\n const path = this.config.dangerousRoute || !x.exact ? `/${x.path}${x.route}` : `/${x.path}`;\n return types.objectExpression([\n types.objectProperty(types.identifier('exact'), types.booleanLiteral(x.exact)),\n types.objectProperty(types.identifier('keepAlive'), types.booleanLiteral(x.keepAlive!)),\n types.objectProperty(types.identifier('key'), types.stringLiteral(path)),\n types.objectProperty(types.identifier('path'), types.stringLiteral(path)),\n types.objectProperty(types.identifier('component'), this.loadableCallExpression(x)),\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 const routeList = items\n .map((x) => this.transform(x))\n .map((x) => {\n const path = this.config.dangerousRoute || !x.exact ? `/${x.path}${x.route}` : `/${x.path}`;\n return types.objectExpression([types.objectProperty(types.identifier('path'), types.stringLiteral(path))]);\n });\n\n ast.push(\n types.exportNamedDeclaration(\n types.variableDeclaration('const', [types.variableDeclarator(types.identifier('routeList'), types.arrayExpression(routeList))]),\n [],\n ),\n );\n\n path.pushContainer('body', ast);\n },\n },\n },\n };\n },\n ],\n });\n\n fs.writeFileSync(absPath, [JSON.stringify(`👹 pages total count is ${Array.from(this.cache.keys()).length}`), code?.code!].join(';\\r\\n'), {\n encoding: 'utf8',\n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AAC,CAAC;gBAEJC,GAAG,CAAC7B,IAAI,CACNrC,WAAK,CAACsF,sBAAsB,CAC1BtF,WAAK,CAACC,mBAAmB,CAAC,OAAO,EAAE,CAACD,WAAK,CAACE,kBAAkB,CAACF,WAAK,CAACG,UAAU,CAAC,WAAW,CAAC,EAAEH,WAAK,CAACoF,eAAe,CAACC,SAAS,CAAC,CAAC,CAAC,CAAC,EAC/H,EAAE,CACH,CACF;gBAEDpB,IAAI,CAACsB,aAAa,CAAC,MAAM,EAAErB,GAAG,CAAC;cACjC;YACF;UACF;QACF,CAAC;MACH,CAAC;IAEL,CAAC,CAAC;IAEFsB,WAAE,CAACC,aAAa,CAACpC,OAAO,EAAE,CAACH,IAAI,CAACC,SAAS,CAAE,2BAA0BI,KAAK,CAACC,IAAI,CAAC,IAAI,CAACC,KAAK,CAACiC,IAAI,EAAE,CAAC,CAACC,MAAO,EAAC,CAAC,EAAEhC,IAAI,EAAEA,IAAI,CAAE,CAACiC,IAAI,CAAC,OAAO,CAAC,EAAE;MACxIC,QAAQ,EAAE;IACZ,CAAC,CAAC;EACJ;AACF;AAACC,OAAA,CAAApG,gBAAA,GAAAA,gBAAA"}
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","meJSONRelativePath","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","getThemePath","expressionStatement","optionalCallExpression","_","filter","x","isExternal","map","dangerousRoute","exact","exportDefaultDeclaration","arrayExpression","routeList","exportNamedDeclaration","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 meJSONRelativePath: 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(types.identifier('props'), types.identifier('errorStack')),\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([types.returnStatement(types.jsxFragment(types.jsxOpeningFragment(), types.jsxClosingFragment(), []))]),\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 = [types.objectProperty(types.identifier('module'), types.identifier('module'))];\n if (item.meJSON.sync) {\n returnObjectProperties.push(types.objectProperty(types.identifier('sync'), types.booleanLiteral(true)));\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.meJSONRelativePath);\n\n if (this.config.enablePreFetch) {\n types.addComment(sourceAst, 'leading', 'webpackPrefetch: true');\n }\n\n return types.callExpression(types.memberExpression(types.callExpression(types.import(), [sourceAst]), types.identifier('then')), [\n types.arrowFunctionExpression(\n [types.identifier('module')],\n types.blockStatement([\n // TODO\n types.returnStatement(types.objectExpression(returnObjectProperties)),\n ]),\n ),\n ]);\n }\n\n private loadableCallExpression(item: TransformItem) {\n return types.callExpression(types.identifier('Loadable'), [\n types.objectExpression([\n types.objectProperty(types.identifier('title'), item.title ? types.stringLiteral(item.title) : types.nullLiteral()),\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' ? types.booleanLiteral(item.injectStore) : 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(types.identifier('errorComponent'), types.identifier('ErrorComponent')),\n types.objectProperty(\n types.identifier('metaInfo'),\n types.callExpression(types.memberExpression(types.identifier('JSON'), types.identifier('parse')), [\n types.stringLiteral(JSON.stringify(item.meJSON)),\n ]),\n ),\n types.objectProperty(types.identifier('loader'), types.arrowFunctionExpression([], this.pageImportExpression(item))),\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: (types.ImportDeclaration | types.VariableDeclaration | types.ExportDefaultDeclaration | types.ExpressionStatement)[] = [\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(this.importDefaultDeclaration('ErrorComponent', this.config.errorComponent));\n } else {\n ast.push(this.errorComponentVariableDeclaration());\n }\n\n if (this.config.theme?.hash) {\n ast.push(this.importNamedDeclaration(['toGlobalTheme'], this.pathService.getThemePath(this.config.theme.hash)));\n ast.push(types.expressionStatement(types.optionalCallExpression(types.identifier('toGlobalTheme'), [], true)));\n }\n\n const _ = items\n .filter((x) => !x.isExternal)\n .map((x) => this.transform(x))\n .map((x) => {\n const path = this.config.dangerousRoute || !x.exact ? `/${x.path}${x.route}` : `/${x.path}`;\n return types.objectExpression([\n types.objectProperty(types.identifier('exact'), types.booleanLiteral(x.exact)),\n types.objectProperty(types.identifier('keepAlive'), types.booleanLiteral(x.keepAlive!)),\n types.objectProperty(types.identifier('key'), types.stringLiteral(path)),\n types.objectProperty(types.identifier('path'), types.stringLiteral(path)),\n types.objectProperty(types.identifier('component'), this.loadableCallExpression(x)),\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 const routeList = items\n .map((x) => this.transform(x))\n .map((x) => {\n const path = this.config.dangerousRoute || !x.exact ? `/${x.path}${x.route}` : `/${x.path}`;\n return types.objectExpression([types.objectProperty(types.identifier('path'), types.stringLiteral(path))]);\n });\n\n ast.push(\n types.exportNamedDeclaration(\n types.variableDeclaration('const', [types.variableDeclarator(types.identifier('routeList'), types.arrayExpression(routeList))]),\n [],\n ),\n );\n\n path.pushContainer('body', ast);\n },\n },\n },\n };\n },\n ],\n });\n\n fs.writeFileSync(absPath, [JSON.stringify(`👹 pages total count is ${Array.from(this.cache.keys()).length}`), code?.code!].join(';\\r\\n'), {\n encoding: 'utf8',\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,CAA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,CAACsB,aAAa,CAAC,MAAM,EAAErB,GAAG,CAAC;cACjC;YACF;UACF;QACF,CAAC;MACH,CAAC;IAEL,CAAC,CAAC;IAEFsB,WAAE,CAACC,aAAa,CAACpC,OAAO,EAAE,CAACH,IAAI,CAACC,SAAS,CAAE,2BAA0BI,KAAK,CAACC,IAAI,CAAC,IAAI,CAACC,KAAK,CAACiC,IAAI,EAAE,CAAC,CAACC,MAAO,EAAC,CAAC,EAAEhC,IAAI,EAAEA,IAAI,CAAE,CAACiC,IAAI,CAAC,OAAO,CAAC,EAAE;MACxIC,QAAQ,EAAE;IACZ,CAAC,CAAC;EACJ;AACF;AAACC,OAAA,CAAApG,gBAAA,GAAAA,gBAAA"}
@@ -1 +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;IAElB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,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;IAU/B,eAAe,CAAC,OAAO,EAAE,MAAM;IAsD/B,OAAO,CAAC,qBAAqB;CAY9B"}
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,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,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;IAU/B,eAAe,CAAC,OAAO,EAAE,MAAM;IAsD/B,OAAO,CAAC,qBAAqB;CAY9B"}
@@ -1 +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","mobx","sagaPath","console","log","push","generateDefaultSagaFn","importDefaultDeclaration","reducerPath","arrayItem","map","functionExpression","blockStatement","exportDefaultDeclaration","arrayExpression","pushContainer","fs","writeFileSync","encoding","functionName","functionBody","returnStatement","functionDeclaration","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 sagaPath: string;\n reducerPath: 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(types.identifier(this.identifierString(namespace)), types.identifier('saga')),\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(['call'], 'rrc-loader-helper/lib/sagas/redux-saga/effects'),\n ];\n\n items\n .filter((x) => x.meJSON.sync || x.isExternal)\n .forEach((x) => {\n // 如果不是 mobx,并且 saga 文件不存在,手动补一个 saga 函数\n if (!x.meJSON.mobx && !x.sagaPath) {\n console.log('x.namespace', x.namespace);\n ast.push(this.generateDefaultSagaFn(x.namespace));\n } else {\n // 如果是mobx, 取 reducer, 否则取 saga\n ast.push(this.importDefaultDeclaration(x.namespace, x.meJSON.mobx ? x.reducerPath : x.sagaPath));\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([this.setCtxExpressionStatement(x.namespace), this.callExpressionStatement(x.namespace)]),\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 private generateDefaultSagaFn(functionName: string) {\n const functionBody = types.blockStatement([\n types.returnStatement(types.objectExpression([])), // 返回一个空对象\n ]);\n return types.functionDeclaration(\n types.identifier(this.identifierString(functionName)), // 函数名\n [], // 参数列表\n functionBody, // 函数体\n true, // generator 标志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yC,YAAY,CAAC,CAAC;IAAE;IACvD,EAAE;IAAE;IACJC,YAAY;IAAE;IACd,IAAI;IAAE;IACN,KAAK,CAAE;IAAA,CACR;EACH;AACF;AAACG,OAAA,CAAA7D,cAAA,GAAAA,cAAA"}
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","mobx","sagaPath","console","log","push","generateDefaultSagaFn","importDefaultDeclaration","reducerPath","arrayItem","map","functionExpression","blockStatement","exportDefaultDeclaration","arrayExpression","pushContainer","fs","writeFileSync","encoding","functionName","functionBody","returnStatement","functionDeclaration","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 sagaPath: string;\n reducerPath: 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(types.identifier(this.identifierString(namespace)), types.identifier('saga')),\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(['call'], 'rrc-loader-helper/lib/sagas/redux-saga/effects'),\n ];\n\n items\n .filter((x) => x.meJSON.sync || x.isExternal)\n .forEach((x) => {\n // 如果不是 mobx,并且 saga 文件不存在,手动补一个 saga 函数\n if (!x.meJSON.mobx && !x.sagaPath) {\n console.log('x.namespace', x.namespace);\n ast.push(this.generateDefaultSagaFn(x.namespace));\n } else {\n // 如果是mobx, 取 reducer, 否则取 saga\n ast.push(this.importDefaultDeclaration(x.namespace, x.meJSON.mobx ? x.reducerPath : x.sagaPath));\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([this.setCtxExpressionStatement(x.namespace), this.callExpressionStatement(x.namespace)]),\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 private generateDefaultSagaFn(functionName: string) {\n const functionBody = types.blockStatement([\n types.returnStatement(types.objectExpression([])), // 返回一个空对象\n ]);\n return types.functionDeclaration(\n types.identifier(this.identifierString(functionName)), // 函数名\n [], // 参数列表\n functionBody, // 函数体\n true, // generator 标志\n false, // async 标志\n );\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,UAAA,GAAAC,OAAA;AAEA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,GAAA,GAAAC,sBAAA,CAAAH,OAAA;AAAoB,SAAAG,uBAAA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 @@
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,KAAK,OAAO,EAAe,MAAM,SAAS,CAAC;AAO3E,OAAO,EAAE,OAAO,EAAE,CAAC;AAEnB,MAAM,CAAC,OAAO,OAAO,sBAAuB,YAAW,qBAAqB;IAC1E,OAAO,EAAE,OAAO,CAAC;gBACL,OAAO,EAAE,OAAO;IAI5B,KAAK,CAAC,QAAQ,EAAE,QAAQ;IAyOxB,YAAY,CAAC,QAAQ,EAAE,QAAQ;CAYhC"}
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,KAAK,OAAO,EAAe,MAAM,SAAS,CAAC;AAO3E,OAAO,EAAE,OAAO,EAAE,CAAC;AAEnB,MAAM,CAAC,OAAO,OAAO,sBAAuB,YAAW,qBAAqB;IAC1E,OAAO,EAAE,OAAO,CAAC;gBACL,OAAO,EAAE,OAAO;IAI5B,KAAK,CAAC,QAAQ,EAAE,QAAQ;IA2OxB,YAAY,CAAC,QAAQ,EAAE,QAAQ;CAYhC"}
package/lib/index.js CHANGED
@@ -48,7 +48,8 @@ class LcdRouterWebpackPlugin {
48
48
  const meJSON = fileService.readJSONSync(absFilePath);
49
49
  let reducerPath = '';
50
50
  try {
51
- reducerPath = resolver.getReducerFile(absCurrentDir);
51
+ resolver.getReducerFile(absCurrentDir);
52
+ reducerPath = pathService.getReducerPath(filepath);
52
53
  chunkCode.push(`export { default as reducer } from '${reducerPath}';`);
53
54
  } catch (e) {
54
55
  // feat: reducers 可以不存在, 方便结合reactive 和 ak,默认创建一个reducers
@@ -70,7 +71,7 @@ class LcdRouterWebpackPlugin {
70
71
  chunkCode.push(`export function reducer(){ return {} }`);
71
72
  }
72
73
  if (!isExternal) {
73
- const viewPath = resolver.getViewFile(absCurrentDir);
74
+ const viewPath = pathService.getViewPath(filepath);
74
75
  chunkCode.push(`export { default as view } from '${viewPath}';`);
75
76
  }
76
77
  if (meJSON.theme && !options.theme?.hash) {
@@ -79,7 +80,8 @@ class LcdRouterWebpackPlugin {
79
80
  let sagaPath = '';
80
81
  if (!meJSON.mobx) {
81
82
  try {
82
- sagaPath = resolver.getSagaFile(absCurrentDir);
83
+ resolver.getSagaFile(absCurrentDir);
84
+ sagaPath = pathService.getSagaPath(filepath);
83
85
  chunkCode.push(`export { default as saga } from '${sagaPath}';`);
84
86
  } catch (e) {
85
87
  // feat: saga 也可以不存在, 方便结合reactive 和 ak,默认创建一个reducers
@@ -87,19 +89,20 @@ class LcdRouterWebpackPlugin {
87
89
  }
88
90
  }
89
91
  if (meJSON.errorComponent) {
90
- const errorCompPath = resolver.getErrorComFile(absCurrentDir, meJSON.errorComponent);
91
- chunkCode.push(`export { default as ErrorComponent } from '${errorCompPath}';`);
92
+ resolver.getErrorComFile(absCurrentDir, meJSON.errorComponent);
93
+ chunkCode.push(`export { default as ErrorComponent } from '${meJSON.errorComponent}';`);
92
94
  }
93
95
  if (options.theme?.hash) {
94
- const themePath = pathService.getThemeJSCacheFileAbs(options.theme?.hash);
96
+ const themePath = pathService.getThemePath(options.theme.hash);
95
97
  chunkCode.push(`export * from '${themePath}';`);
96
98
  }
97
99
  if (meJSON.theme) {
98
100
  fileService.writeThemeFile(meJSON.theme, 'toGlobalTheme');
99
- const themePath = pathService.getThemeJSCacheFileAbs(meJSON.theme);
101
+ const themePath = pathService.getThemePath(meJSON.theme);
100
102
  chunkCode.push(`export * from '${themePath}';`);
101
103
  }
102
104
  const meJSONPath = pathService.getMeJSONCacheFileAbs(filepath);
105
+ const meJSONRelativePath = pathService.getMeJSONRelativePath(filepath);
103
106
  fileService.writeMeJSONFile(meJSONPath, chunkCode);
104
107
 
105
108
  // 处理是否存在多store的场景
@@ -123,7 +126,6 @@ class LcdRouterWebpackPlugin {
123
126
  meJSON,
124
127
  isExternal,
125
128
  namespace: currentDir,
126
- // meJSONPath: meJSONPath,
127
129
  reducerPath,
128
130
  sagaPath
129
131
  });
@@ -135,7 +137,7 @@ class LcdRouterWebpackPlugin {
135
137
  page: currentDir,
136
138
  path: currentDir,
137
139
  exact: false,
138
- meJSONPath: meJSONPath
140
+ meJSONRelativePath
139
141
  });
140
142
 
141
143
  /** 处理 /list 的路由 */
@@ -147,7 +149,7 @@ class LcdRouterWebpackPlugin {
147
149
  page: currentDir,
148
150
  path: _key,
149
151
  exact: true,
150
- meJSONPath: meJSONPath
152
+ meJSONRelativePath
151
153
  });
152
154
  }
153
155
  }
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["_globby","_interopRequireDefault","require","_chokidar","_deepmerge","_utils","_ReducersGenerator","_SagasGenerator","_RoutersGenerator","_nodePath","obj","__esModule","default","LcdRouterWebpackPlugin","options","constructor","apply","compiler","mergeOptions","hooks","afterPlugins","tap","pathService","PathService","resolver","Resolver","fileService","FileService","reducersGenerator","ReducersGenerator","sagasGenerator","SagasGenerator","routersGenerator","RoutersGenerator","isDev","mode","process","env","NODE_ENV","writeCode","writeCodeToFile","getReducersCacheFileAbs","getSagasCacheFileAbs","getRoutersCacheFileAbs","resolveFile","filepath","absFilePath","getCurrentFileAbs","currentDir","path","dirname","absCurrentDir","isExternal","externals","some","x","chunkCode","meJSON","readJSONSync","reducerPath","getReducerFile","push","e","mobx","Error","viewPath","getViewFile","theme","hash","sagaPath","getSagaFile","errorComponent","errorCompPath","getErrorComFile","themePath","getThemeJSCacheFileAbs","writeThemeFile","meJSONPath","getMeJSONCacheFileAbs","writeMeJSONFile","hasChildStore","globby","sync","reducerName","cwd","length","set","namespace","page","exact","RegExp","index","test","_key","replace","list","getPageRootAbs","console","warn","sortedList","map","sort","a","b","startsWith","localeCompare","dir","forEach","watcher","chokidar","watch","ignoreInitial","fn","on","environment","disableBabelLoaderRule","module","rules","exclude","use","loader","resolve","presets","babelrc","parserOpts","plugins","defaultOptions","context","enablePreFetch","pageDir","disableBuiltInRoute","deepmerge","exports"],"sources":["../index.ts"],"sourcesContent":["import type { Compiler, WebpackPluginInstance } from 'webpack';\nimport globby from 'globby';\nimport chokidar from 'chokidar';\nimport deepmerge from 'deepmerge';\nimport { PathService, Resolver, type Options, FileService } from './utils';\nimport { ReducersGenerator } from './ReducersGenerator';\nimport { SagasGenerator } from './SagasGenerator';\nimport { RoutersGenerator } from './RoutersGenerator';\n\nimport path from 'node:path';\n\nexport { Options };\n\nexport default class LcdRouterWebpackPlugin implements WebpackPluginInstance {\n options: Options;\n constructor(options: Options) {\n this.options = options;\n }\n\n apply(compiler: Compiler) {\n this.mergeOptions(compiler);\n\n // 处理 lcd 中的路由体系\n compiler.hooks.afterPlugins.tap('LcdRouterWebpackPlugin', (compiler) => {\n const options = this.options;\n\n const pathService = new PathService(options);\n const resolver = new Resolver(compiler, options);\n const fileService = new FileService(pathService);\n\n const reducersGenerator = new ReducersGenerator();\n const sagasGenerator = new SagasGenerator();\n const routersGenerator = new RoutersGenerator(options, pathService);\n\n function isDev(compiler) {\n if (compiler.options.mode === 'production' || process.env.NODE_ENV === 'production') return false;\n return true;\n }\n\n function writeCode() {\n reducersGenerator.writeCodeToFile(pathService.getReducersCacheFileAbs());\n sagasGenerator.writeCodeToFile(pathService.getSagasCacheFileAbs());\n routersGenerator.writeCodeToFile(pathService.getRoutersCacheFileAbs());\n }\n\n function resolveFile(filepath: string) {\n const absFilePath = pathService.getCurrentFileAbs(filepath);\n const currentDir = path.dirname(filepath);\n const absCurrentDir = path.dirname(absFilePath);\n const isExternal = options.externals?.some?.((x) => x === path.dirname(filepath)) ?? false;\n const chunkCode = [] as string[];\n const meJSON = fileService.readJSONSync(absFilePath);\n let reducerPath = '';\n try {\n reducerPath = resolver.getReducerFile(absCurrentDir);\n chunkCode.push(`export { default as reducer } from '${reducerPath}';`);\n } catch (e) {\n // feat: reducers 可以不存在, 方便结合reactive 和 ak,默认创建一个reducers\n if (meJSON.mobx) {\n /**\n * mobx 模式下, 需要垫一个被 mobx-adapter 包裹的 reducer 函数\n * 如果存在reducer文件,是默认会被 babel-plugin-enhance-reducer 处理的\n *\n * import storeHoc from 'rrc-loader-helper/lib/mobx-adapter';\n * export const reducer = storeHoc({\n * state: {},\n * }, 'report/other-table')\n *\n * 不太方便去垫一个 reducer 函数,reducer 的路径计算比较复杂, 所以直接报错\n * 同时,从逻辑上讲,如果开启了 mobx,那么必须要有 reducer 文件\n */\n throw Error(`开启 mobx 后,reducer 文件必须存在 ${absFilePath}`);\n }\n chunkCode.push(`export function reducer(){ return {} }`);\n }\n\n if (!isExternal) {\n const viewPath = resolver.getViewFile(absCurrentDir);\n chunkCode.push(`export { default as view } from '${viewPath}';`);\n }\n\n if (meJSON.theme && !options.theme?.hash) {\n throw Error(`开启页面级主题之前,请优先开启全局主题 ${absFilePath}`);\n }\n\n let sagaPath = '';\n if (!meJSON.mobx) {\n try {\n sagaPath = resolver.getSagaFile(absCurrentDir);\n chunkCode.push(`export { default as saga } from '${sagaPath}';`);\n } catch (e) {\n // feat: saga 也可以不存在, 方便结合reactive 和 ak,默认创建一个reducers\n chunkCode.push(`export function* saga(){ return {} }`);\n }\n }\n\n if (meJSON.errorComponent) {\n const errorCompPath = resolver.getErrorComFile(absCurrentDir, meJSON.errorComponent);\n chunkCode.push(`export { default as ErrorComponent } from '${errorCompPath}';`);\n }\n\n if (options.theme?.hash) {\n const themePath = pathService.getThemeJSCacheFileAbs(options.theme?.hash);\n chunkCode.push(`export * from '${themePath}';`);\n }\n\n if (meJSON.theme) {\n fileService.writeThemeFile(meJSON.theme, 'toGlobalTheme');\n const themePath = pathService.getThemeJSCacheFileAbs(meJSON.theme);\n chunkCode.push(`export * from '${themePath}';`);\n }\n\n const meJSONPath = pathService.getMeJSONCacheFileAbs(filepath);\n\n fileService.writeMeJSONFile(meJSONPath, chunkCode);\n\n // 处理是否存在多store的场景\n const hasChildStore = globby.sync(`**/*.${options.reducerName}.{t,j}s`, { cwd: absCurrentDir }).length > 0;\n if (hasChildStore && (meJSON.sync || isExternal)) {\n throw Error(`如果开启了Sync模式或当前页面存在于LCD的external中,那么则不支持多Store功能,${absCurrentDir}`);\n }\n\n /** reducers.js */\n reducersGenerator.set(filepath, {\n meJSON,\n isExternal,\n namespace: currentDir,\n reducerPath,\n });\n\n /** saga.js */\n sagasGenerator.set(currentDir, {\n meJSON,\n isExternal,\n namespace: currentDir,\n // meJSONPath: meJSONPath,\n reducerPath,\n sagaPath,\n });\n\n /** router */\n routersGenerator.set(currentDir, {\n meJSON,\n isExternal,\n page: currentDir,\n path: currentDir,\n exact: false,\n meJSONPath: meJSONPath,\n });\n\n /** 处理 /list 的路由 */\n if (new RegExp(`\\/${options.index}$`).test(currentDir)) {\n const _key = currentDir.replace(new RegExp(`\\/${options.index}$`), '');\n routersGenerator.set(_key, {\n meJSON,\n isExternal,\n page: currentDir,\n path: _key,\n exact: true,\n meJSONPath: meJSONPath,\n });\n }\n }\n\n if (options.theme?.hash) {\n fileService.writeThemeFile(options.theme.hash, 'toGlobalTheme');\n }\n\n const list = globby.sync('**/me.json', {\n cwd: pathService.getPageRootAbs(),\n });\n\n if (list.length === 0) {\n console.warn('没有找到me.json文件');\n }\n\n /**\n * glob 的排序 是包含文件名 me.json 的完整路径,存在问题\n * 比如 会将 /xx/ss/me.json 排到 /xx/ss/zz/me.json 前面\n * glob 的 noSort option 会将 文件夹排到前面, 因此需要手动排序, 并且统一成 globby, 速度更快\n */\n const sortedList = list\n .map((filepath) => filepath?.replace(/me.json$/, ''))\n .sort((a, b) => {\n if (a?.startsWith(b)) return -1;\n return a.localeCompare(b, 'en');\n })\n .map((dir) => `${dir}me.json`);\n\n sortedList.forEach((filepath) => {\n resolveFile(filepath);\n });\n\n writeCode();\n\n if (isDev(compiler)) {\n const watcher = chokidar.watch('**/me.json', {\n cwd: pathService.getPageRootAbs(),\n ignoreInitial: true,\n });\n const fn = async (filepath) => {\n await resolveFile(filepath);\n writeCode();\n };\n watcher.on('add', fn);\n watcher.on('addDir', fn);\n watcher.on('change', fn);\n watcher.on('unlink', fn);\n watcher.on('unlinkDir', fn);\n watcher.on('error', fn);\n }\n });\n\n // lcd 中包含一些语法转换处理\n compiler.hooks.environment.tap('lcd-preset', () => {\n if (this.options.disableBabelLoaderRule) return;\n compiler.options.module.rules.push({\n test: /\\.(js|ts)x?$/,\n exclude: /node_modules/,\n use: [\n {\n loader: require.resolve('babel-loader'),\n options: {\n presets: [[require.resolve('./babel/index'), this.options]],\n babelrc: false,\n // 需要支持语法解析, 但不需要做转换\n parserOpts: {\n plugins: [\n 'jsx',\n 'typescript',\n 'asyncDoExpressions',\n 'decimal',\n 'decorators-legacy',\n 'decoratorAutoAccessors',\n 'destructuringPrivate',\n 'doExpressions',\n 'exportDefaultFrom',\n 'functionBind',\n 'functionSent',\n 'importAssertions',\n 'moduleBlocks',\n 'partialApplication',\n 'throwExpressions',\n ],\n },\n },\n },\n ],\n });\n });\n }\n\n mergeOptions(compiler: Compiler) {\n const defaultOptions = {\n context: compiler.context,\n enablePreFetch: false,\n index: 'list',\n externals: [],\n pageDir: 'component',\n reducerName: 'reducer',\n disableBuiltInRoute: false,\n };\n this.options = deepmerge(defaultOptions, this.options);\n }\n}\n"],"mappings":";;;;;;AACA,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,SAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,UAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,kBAAA,GAAAJ,OAAA;AACA,IAAAK,eAAA,GAAAL,OAAA;AACA,IAAAM,iBAAA,GAAAN,OAAA;AAEA,IAAAO,SAAA,GAAAR,sBAAA,CAAAC,OAAA;AAA6B,SAAAD,uBAAAS,GAAA,WAAAA,GAAA,IAAAA,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AO,GAAG,IAAAqH,kBAAS,EAACL,cAAc,EAAE,IAAI,CAAChH,OAAO,CAAC;EACxD;AACF;AAACsH,OAAA,CAAAxH,OAAA,GAAAC,sBAAA"}
1
+ {"version":3,"file":"index.js","names":["_globby","_interopRequireDefault","require","_chokidar","_deepmerge","_utils","_ReducersGenerator","_SagasGenerator","_RoutersGenerator","_nodePath","obj","__esModule","default","LcdRouterWebpackPlugin","options","constructor","apply","compiler","mergeOptions","hooks","afterPlugins","tap","pathService","PathService","resolver","Resolver","fileService","FileService","reducersGenerator","ReducersGenerator","sagasGenerator","SagasGenerator","routersGenerator","RoutersGenerator","isDev","mode","process","env","NODE_ENV","writeCode","writeCodeToFile","getReducersCacheFileAbs","getSagasCacheFileAbs","getRoutersCacheFileAbs","resolveFile","filepath","absFilePath","getCurrentFileAbs","currentDir","path","dirname","absCurrentDir","isExternal","externals","some","x","chunkCode","meJSON","readJSONSync","reducerPath","getReducerFile","getReducerPath","push","e","mobx","Error","viewPath","getViewPath","theme","hash","sagaPath","getSagaFile","getSagaPath","errorComponent","getErrorComFile","themePath","getThemePath","writeThemeFile","meJSONPath","getMeJSONCacheFileAbs","meJSONRelativePath","getMeJSONRelativePath","writeMeJSONFile","hasChildStore","globby","sync","reducerName","cwd","length","set","namespace","page","exact","RegExp","index","test","_key","replace","list","getPageRootAbs","console","warn","sortedList","map","sort","a","b","startsWith","localeCompare","dir","forEach","watcher","chokidar","watch","ignoreInitial","fn","on","environment","disableBabelLoaderRule","module","rules","exclude","use","loader","resolve","presets","babelrc","parserOpts","plugins","defaultOptions","context","enablePreFetch","pageDir","disableBuiltInRoute","deepmerge","exports"],"sources":["../index.ts"],"sourcesContent":["import type { Compiler, WebpackPluginInstance } from 'webpack';\nimport globby from 'globby';\nimport chokidar from 'chokidar';\nimport deepmerge from 'deepmerge';\nimport { PathService, Resolver, type Options, FileService } from './utils';\nimport { ReducersGenerator } from './ReducersGenerator';\nimport { SagasGenerator } from './SagasGenerator';\nimport { RoutersGenerator } from './RoutersGenerator';\n\nimport path from 'node:path';\n\nexport { Options };\n\nexport default class LcdRouterWebpackPlugin implements WebpackPluginInstance {\n options: Options;\n constructor(options: Options) {\n this.options = options;\n }\n\n apply(compiler: Compiler) {\n this.mergeOptions(compiler);\n\n // 处理 lcd 中的路由体系\n compiler.hooks.afterPlugins.tap('LcdRouterWebpackPlugin', (compiler) => {\n const options = this.options;\n\n const pathService = new PathService(options);\n const resolver = new Resolver(compiler, options);\n const fileService = new FileService(pathService);\n\n const reducersGenerator = new ReducersGenerator();\n const sagasGenerator = new SagasGenerator();\n const routersGenerator = new RoutersGenerator(options, pathService);\n\n function isDev(compiler) {\n if (compiler.options.mode === 'production' || process.env.NODE_ENV === 'production') return false;\n return true;\n }\n\n function writeCode() {\n reducersGenerator.writeCodeToFile(pathService.getReducersCacheFileAbs());\n sagasGenerator.writeCodeToFile(pathService.getSagasCacheFileAbs());\n routersGenerator.writeCodeToFile(pathService.getRoutersCacheFileAbs());\n }\n\n function resolveFile(filepath: string) {\n const absFilePath = pathService.getCurrentFileAbs(filepath);\n const currentDir = path.dirname(filepath);\n const absCurrentDir = path.dirname(absFilePath);\n const isExternal = options.externals?.some?.((x) => x === path.dirname(filepath)) ?? false;\n const chunkCode = [] as string[];\n const meJSON = fileService.readJSONSync(absFilePath);\n let reducerPath = '';\n try {\n resolver.getReducerFile(absCurrentDir);\n reducerPath = pathService.getReducerPath(filepath);\n chunkCode.push(`export { default as reducer } from '${reducerPath}';`);\n } catch (e) {\n // feat: reducers 可以不存在, 方便结合reactive 和 ak,默认创建一个reducers\n if (meJSON.mobx) {\n /**\n * mobx 模式下, 需要垫一个被 mobx-adapter 包裹的 reducer 函数\n * 如果存在reducer文件,是默认会被 babel-plugin-enhance-reducer 处理的\n *\n * import storeHoc from 'rrc-loader-helper/lib/mobx-adapter';\n * export const reducer = storeHoc({\n * state: {},\n * }, 'report/other-table')\n *\n * 不太方便去垫一个 reducer 函数,reducer 的路径计算比较复杂, 所以直接报错\n * 同时,从逻辑上讲,如果开启了 mobx,那么必须要有 reducer 文件\n */\n throw Error(`开启 mobx 后,reducer 文件必须存在 ${absFilePath}`);\n }\n chunkCode.push(`export function reducer(){ return {} }`);\n }\n\n if (!isExternal) {\n const viewPath = pathService.getViewPath(filepath);\n chunkCode.push(`export { default as view } from '${viewPath}';`);\n }\n\n if (meJSON.theme && !options.theme?.hash) {\n throw Error(`开启页面级主题之前,请优先开启全局主题 ${absFilePath}`);\n }\n\n let sagaPath = '';\n if (!meJSON.mobx) {\n try {\n resolver.getSagaFile(absCurrentDir);\n sagaPath = pathService.getSagaPath(filepath);\n chunkCode.push(`export { default as saga } from '${sagaPath}';`);\n } catch (e) {\n // feat: saga 也可以不存在, 方便结合reactive 和 ak,默认创建一个reducers\n chunkCode.push(`export function* saga(){ return {} }`);\n }\n }\n\n if (meJSON.errorComponent) {\n resolver.getErrorComFile(absCurrentDir, meJSON.errorComponent);\n chunkCode.push(`export { default as ErrorComponent } from '${meJSON.errorComponent}';`);\n }\n\n if (options.theme?.hash) {\n const themePath = pathService.getThemePath(options.theme.hash);\n chunkCode.push(`export * from '${themePath}';`);\n }\n\n if (meJSON.theme) {\n fileService.writeThemeFile(meJSON.theme, 'toGlobalTheme');\n const themePath = pathService.getThemePath(meJSON.theme);\n chunkCode.push(`export * from '${themePath}';`);\n }\n\n const meJSONPath = pathService.getMeJSONCacheFileAbs(filepath);\n const meJSONRelativePath = pathService.getMeJSONRelativePath(filepath);\n\n fileService.writeMeJSONFile(meJSONPath, chunkCode);\n\n // 处理是否存在多store的场景\n const hasChildStore = globby.sync(`**/*.${options.reducerName}.{t,j}s`, { cwd: absCurrentDir }).length > 0;\n if (hasChildStore && (meJSON.sync || isExternal)) {\n throw Error(`如果开启了Sync模式或当前页面存在于LCD的external中,那么则不支持多Store功能,${absCurrentDir}`);\n }\n\n /** reducers.js */\n reducersGenerator.set(filepath, {\n meJSON,\n isExternal,\n namespace: currentDir,\n reducerPath,\n });\n\n /** saga.js */\n sagasGenerator.set(currentDir, {\n meJSON,\n isExternal,\n namespace: currentDir,\n reducerPath,\n sagaPath,\n });\n\n /** router */\n routersGenerator.set(currentDir, {\n meJSON,\n isExternal,\n page: currentDir,\n path: currentDir,\n exact: false,\n meJSONRelativePath,\n });\n\n /** 处理 /list 的路由 */\n if (new RegExp(`\\/${options.index}$`).test(currentDir)) {\n const _key = currentDir.replace(new RegExp(`\\/${options.index}$`), '');\n routersGenerator.set(_key, {\n meJSON,\n isExternal,\n page: currentDir,\n path: _key,\n exact: true,\n meJSONRelativePath,\n });\n }\n }\n\n if (options.theme?.hash) {\n fileService.writeThemeFile(options.theme.hash, 'toGlobalTheme');\n }\n\n const list = globby.sync('**/me.json', {\n cwd: pathService.getPageRootAbs(),\n });\n\n if (list.length === 0) {\n console.warn('没有找到me.json文件');\n }\n\n /**\n * glob 的排序 是包含文件名 me.json 的完整路径,存在问题\n * 比如 会将 /xx/ss/me.json 排到 /xx/ss/zz/me.json 前面\n * glob 的 noSort option 会将 文件夹排到前面, 因此需要手动排序, 并且统一成 globby, 速度更快\n */\n const sortedList = list\n .map((filepath) => filepath?.replace(/me.json$/, ''))\n .sort((a, b) => {\n if (a?.startsWith(b)) return -1;\n return a.localeCompare(b, 'en');\n })\n .map((dir) => `${dir}me.json`);\n\n sortedList.forEach((filepath) => {\n resolveFile(filepath);\n });\n\n writeCode();\n\n if (isDev(compiler)) {\n const watcher = chokidar.watch('**/me.json', {\n cwd: pathService.getPageRootAbs(),\n ignoreInitial: true,\n });\n const fn = async (filepath) => {\n await resolveFile(filepath);\n writeCode();\n };\n watcher.on('add', fn);\n watcher.on('addDir', fn);\n watcher.on('change', fn);\n watcher.on('unlink', fn);\n watcher.on('unlinkDir', fn);\n watcher.on('error', fn);\n }\n });\n\n // lcd 中包含一些语法转换处理\n compiler.hooks.environment.tap('lcd-preset', () => {\n if (this.options.disableBabelLoaderRule) return;\n compiler.options.module.rules.push({\n test: /\\.(js|ts)x?$/,\n exclude: /node_modules/,\n use: [\n {\n loader: require.resolve('babel-loader'),\n options: {\n presets: [[require.resolve('./babel/index'), this.options]],\n babelrc: false,\n // 需要支持语法解析, 但不需要做转换\n parserOpts: {\n plugins: [\n 'jsx',\n 'typescript',\n 'asyncDoExpressions',\n 'decimal',\n 'decorators-legacy',\n 'decoratorAutoAccessors',\n 'destructuringPrivate',\n 'doExpressions',\n 'exportDefaultFrom',\n 'functionBind',\n 'functionSent',\n 'importAssertions',\n 'moduleBlocks',\n 'partialApplication',\n 'throwExpressions',\n ],\n },\n },\n },\n ],\n });\n });\n }\n\n mergeOptions(compiler: Compiler) {\n const defaultOptions = {\n context: compiler.context,\n enablePreFetch: false,\n index: 'list',\n externals: [],\n pageDir: 'component',\n reducerName: 'reducer',\n disableBuiltInRoute: false,\n };\n this.options = deepmerge(defaultOptions, this.options);\n }\n}\n"],"mappings":";;;;;;AACA,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,SAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,UAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,kBAAA,GAAAJ,OAAA;AACA,IAAAK,eAAA,GAAAL,OAAA;AACA,IAAAM,iBAAA,GAAAN,OAAA;AAEA,IAAAO,SAAA,GAAAR,sBAAA,CAAAC,OAAA;AAA6B,SAAAD,uBAAAS,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAId,MAAMG,sBAAsB,CAAkC;EAC3EC,OAAO;EACPC,WAAWA,CAACD,OAAgB,EAAE;IAC5B,IAAI,CAACA,OAAO,GAAGA,OAAO;EACxB;EAEAE,KAAKA,CAACC,QAAkB,EAAE;IACxB,IAAI,CAACC,YAAY,CAACD,QAAQ,CAAC;;IAE3B;IACAA,QAAQ,CAACE,KAAK,CAACC,YAAY,CAACC,GAAG,CAAC,wBAAwB,EAAGJ,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*/
8
8
  export declare class PathService {
9
- options: Pick<Options, 'context' | 'pageDir'>;
9
+ options: Pick<Options, 'context' | 'pageDir' | 'reducerName'>;
10
10
  legoAbs: string;
11
11
  constructor(options: any);
12
12
  /**
@@ -25,14 +25,19 @@ export declare class PathService {
25
25
  getCurrentDirAbs(relativeFilePath: string): string;
26
26
  /** 生成的 reducers 文件路径 */
27
27
  getReducersCacheFileAbs(): string;
28
+ getReducerPath(relativeFilePath: string): string;
29
+ getViewPath(relativeFilePath: string): string;
30
+ getSagaPath(relativeFilePath: string): string;
28
31
  /** 生成的 sagas 文件路径 */
29
32
  getSagasCacheFileAbs(): string;
30
33
  /** 生成的 routers 文件路径 */
31
34
  getRoutersCacheFileAbs(): string;
32
35
  /** 主题文件cache 的路径 */
33
36
  getThemeJSCacheFileAbs(hash: string): string;
37
+ getThemePath(hash: string): string;
34
38
  /** 获取 mejson 编译后的文件路径 */
35
39
  getMeJSONCacheFileAbs(relativeFilePath: string): string;
40
+ getMeJSONRelativePath(relativeFilePath: string): string;
36
41
  getMeJsonCacheFileName(relativeFilePath: string): string;
37
42
  }
38
43
  //# sourceMappingURL=paths.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../../src/utils/paths.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,GAAG,CAAC;AAEjC,eAAO,MAAM,GAAG,eAAe,CAAC;AAEhC,eAAO,MAAM,MAAM,WAAW,CAAC;AAE/B,eAAO,MAAM,UAAU,UAAU,CAAC;AAElC;;GAEG;AACH,qBAAa,WAAW;IACtB,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,SAAS,GAAG,SAAS,CAAC,CAAC;IAE9C,OAAO,EAAE,MAAM,CAAC;gBAEJ,OAAO,KAAA;IAKnB;;;;;SAKK;IACL,cAAc;IAId,aAAa;IAIb;;SAEK;IACL,iBAAiB,CAAC,gBAAgB,EAAE,MAAM;IAI1C,kBAAkB;IACl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MAAM;IAI9C,sBAAsB,CAAC,gBAAgB,EAAE,MAAM;CAGhD"}
@@ -53,6 +53,28 @@ class PathService {
53
53
  getReducersCacheFileAbs() {
54
54
  return _path.default.join(this.legoAbs, dir, 'reducers.js');
55
55
  }
56
+ getReducerPath(relativeFilePath) {
57
+ const currentDir = _path.default.dirname(relativeFilePath);
58
+ const {
59
+ pageDir,
60
+ reducerName
61
+ } = this.options;
62
+ return `@/${pageDir}/${currentDir}/${reducerName}`;
63
+ }
64
+ getViewPath(relativeFilePath) {
65
+ const currentDir = _path.default.dirname(relativeFilePath);
66
+ const {
67
+ pageDir
68
+ } = this.options;
69
+ return `@/${pageDir}/${currentDir}/view`;
70
+ }
71
+ getSagaPath(relativeFilePath) {
72
+ const currentDir = _path.default.dirname(relativeFilePath);
73
+ const {
74
+ pageDir
75
+ } = this.options;
76
+ return `@/${pageDir}/${currentDir}/saga`;
77
+ }
56
78
 
57
79
  /** 生成的 sagas 文件路径 */
58
80
  getSagasCacheFileAbs() {
@@ -68,11 +90,17 @@ class PathService {
68
90
  getThemeJSCacheFileAbs(hash) {
69
91
  return _path.default.join(this.legoAbs, dir, themes, `${hash}.js`);
70
92
  }
93
+ getThemePath(hash) {
94
+ return `@@/${dir}/${themes}/${hash}.js`;
95
+ }
71
96
 
72
97
  /** 获取 mejson 编译后的文件路径 */
73
98
  getMeJSONCacheFileAbs(relativeFilePath) {
74
99
  return _path.default.join(this.legoAbs, dir, 'me-json', this.getMeJsonCacheFileName(relativeFilePath));
75
100
  }
101
+ getMeJSONRelativePath(relativeFilePath) {
102
+ return `./me-json/${this.getMeJsonCacheFileName(relativeFilePath)}`;
103
+ }
76
104
  getMeJsonCacheFileName(relativeFilePath) {
77
105
  return relativeFilePath.replace(/(.*)\/me\.json$/, '$1.js').replace(/\//g, '-_-');
78
106
  }
@@ -1 +1 @@
1
- {"version":3,"file":"paths.js","names":["_path","_interopRequireDefault","require","obj","__esModule","default","dir","exports","themes","LcdTempDir","PathService","options","legoAbs","constructor","path","join","context","getPageRootAbs","pageDir","getSrcRootAbs","getCurrentFileAbs","relativeFilePath","getCurrentDirAbs","dirname","getReducersCacheFileAbs","getSagasCacheFileAbs","getRoutersCacheFileAbs","getThemeJSCacheFileAbs","hash","getMeJSONCacheFileAbs","getMeJsonCacheFileName","replace"],"sources":["../../paths.ts"],"sourcesContent":["import path from 'path';\nimport type { Options } from '.';\n\nexport const dir = 'lessCoding';\n\nexport const themes = 'themes';\n\nexport const LcdTempDir = '.lego';\n\n/**\n * 路径处理服务\n */\nexport class PathService {\n options: Pick<Options, 'context' | 'pageDir'>;\n\n legoAbs: string;\n\n constructor(options) {\n this.options = options;\n this.legoAbs = path.join(this.options.context!, 'src', LcdTempDir);\n }\n\n /**\n * 页面根目录绝对路径\n * 通常都是\n * - src\n * - components\n * */\n getPageRootAbs() {\n return path.join(this.options.context!, 'src', this.options.pageDir);\n }\n\n getSrcRootAbs() {\n return path.join(this.options.context!, 'src');\n }\n\n /**\n * 当前文件的绝对路径\n * */\n getCurrentFileAbs(relativeFilePath: string) {\n return path.join(this.getPageRootAbs(), relativeFilePath);\n }\n\n /** 当前文件的绝对目录路径 */\n getCurrentDirAbs(relativeFilePath: string) {\n return path.join(this.getPageRootAbs(), path.dirname(relativeFilePath));\n }\n\n /** 生成的 reducers 文件路径 */\n getReducersCacheFileAbs() {\n return path.join(this.legoAbs, dir, 'reducers.js');\n }\n\n /** 生成的 sagas 文件路径 */\n getSagasCacheFileAbs() {\n return path.join(this.legoAbs, dir, 'sagas.js');\n }\n\n /** 生成的 routers 文件路径 */\n getRoutersCacheFileAbs() {\n return path.join(this.legoAbs, dir, 'routers.js');\n }\n\n /** 主题文件cache 的路径 */\n getThemeJSCacheFileAbs(hash: string) {\n return path.join(this.legoAbs, dir, themes, `${hash}.js`);\n }\n\n /** 获取 mejson 编译后的文件路径 */\n getMeJSONCacheFileAbs(relativeFilePath: string) {\n return path.join(this.legoAbs, dir, 'me-json', this.getMeJsonCacheFileName(relativeFilePath));\n }\n\n getMeJsonCacheFileName(relativeFilePath: string) {\n return relativeFilePath.replace(/(.*)\\/me\\.json$/, '$1.js').replace(/\\//g, '-_-');\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,KAAA,GAAAC,sBAAA,CAAAC,OAAA;AAAwB,SAAAD,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAGjB,MAAMG,GAAG,GAAG,YAAY;AAACC,OAAA,CAAAD,GAAA,GAAAA,GAAA;AAEzB,MAAME,MAAM,GAAG,QAAQ;AAACD,OAAA,CAAAC,MAAA,GAAAA,MAAA;AAExB,MAAMC,UAAU,GAAG,OAAO;;AAEjC;AACA;AACA;AAFAF,OAAA,CAAAE,UAAA,GAAAA,UAAA;AAGO,MAAMC,WAAW,CAAC;EACvBC,OAAO;EAEPC,OAAO;EAEPC,WAAWA,CAACF,OAAO,EAAE;IACnB,IAAI,CAACA,OAAO,GAAGA,OAAO;IACtB,IAAI,CAACC,OAAO,GAAGE,aAAI,CAACC,IAAI,CAAC,IAAI,CAACJ,OAAO,CAACK,OAAO,EAAG,KAAK,EAAEP,UAAU,CAAC;EACpE;;EAEA;AACF;AACA;AACA;AACA;AACA;EACEQ,cAAcA,CAAA,EAAG;IACf,OAAOH,aAAI,CAACC,IAAI,CAAC,IAAI,CAACJ,OAAO,CAACK,OAAO,EAAG,KAAK,EAAE,IAAI,CAACL,OAAO,CAACO,OAAO,CAAC;EACtE;EAEAC,aAAaA,CAAA,EAAG;IACd,OAAOL,aAAI,CAACC,IAAI,CAAC,IAAI,CAACJ,OAAO,CAACK,OAAO,EAAG,KAAK,CAAC;EAChD;;EAEA;AACF;AACA;EACEI,iBAAiBA,CAACC,gBAAwB,EAAE;IAC1C,OAAOP,aAAI,CAACC,IAAI,CAAC,IAAI,CAACE,cAAc,EAAE,EAAEI,gBAAgB,CAAC;EAC3D;;EAEA;EACAC,gBAAgBA,CAACD,gBAAwB,EAAE;IACzC,OAAOP,aAAI,CAACC,IAAI,CAAC,IAAI,CAACE,cAAc,EAAE,EAAEH,aAAI,CAACS,OAAO,CAACF,gBAAgB,CAAC,CAAC;EACzE;;EAEA;EACAG,uBAAuBA,CAAA,EAAG;IACxB,OAAOV,aAAI,CAACC,IAAI,CAAC,IAAI,CAACH,OAAO,EAAEN,GAAG,EAAE,aAAa,CAAC;EACpD;;EAEA;EACAmB,oBAAoBA,CAAA,EAAG;IACrB,OAAOX,aAAI,CAACC,IAAI,CAAC,IAAI,CAACH,OAAO,EAAEN,GAAG,EAAE,UAAU,CAAC;EACjD;;EAEA;EACAoB,sBAAsBA,CAAA,EAAG;IACvB,OAAOZ,aAAI,CAACC,IAAI,CAAC,IAAI,CAACH,OAAO,EAAEN,GAAG,EAAE,YAAY,CAAC;EACnD;;EAEA;EACAqB,sBAAsBA,CAACC,IAAY,EAAE;IACnC,OAAOd,aAAI,CAACC,IAAI,CAAC,IAAI,CAACH,OAAO,EAAEN,GAAG,EAAEE,MAAM,EAAG,GAAEoB,IAAK,KAAI,CAAC;EAC3D;;EAEA;EACAC,qBAAqBA,CAACR,gBAAwB,EAAE;IAC9C,OAAOP,aAAI,CAACC,IAAI,CAAC,IAAI,CAACH,OAAO,EAAEN,GAAG,EAAE,SAAS,EAAE,IAAI,CAACwB,sBAAsB,CAACT,gBAAgB,CAAC,CAAC;EAC/F;EAEAS,sBAAsBA,CAACT,gBAAwB,EAAE;IAC/C,OAAOA,gBAAgB,CAACU,OAAO,CAAC,iBAAiB,EAAE,OAAO,CAAC,CAACA,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC;EACnF;AACF;AAACxB,OAAA,CAAAG,WAAA,GAAAA,WAAA"}
1
+ {"version":3,"file":"paths.js","names":["_path","_interopRequireDefault","require","obj","__esModule","default","dir","exports","themes","LcdTempDir","PathService","options","legoAbs","constructor","path","join","context","getPageRootAbs","pageDir","getSrcRootAbs","getCurrentFileAbs","relativeFilePath","getCurrentDirAbs","dirname","getReducersCacheFileAbs","getReducerPath","currentDir","reducerName","getViewPath","getSagaPath","getSagasCacheFileAbs","getRoutersCacheFileAbs","getThemeJSCacheFileAbs","hash","getThemePath","getMeJSONCacheFileAbs","getMeJsonCacheFileName","getMeJSONRelativePath","replace"],"sources":["../../paths.ts"],"sourcesContent":["import path from 'path';\nimport type { Options } from '.';\n\nexport const dir = 'lessCoding';\n\nexport const themes = 'themes';\n\nexport const LcdTempDir = '.lego';\n\n/**\n * 路径处理服务\n */\nexport class PathService {\n options: Pick<Options, 'context' | 'pageDir' | 'reducerName'>;\n\n legoAbs: string;\n\n constructor(options) {\n this.options = options;\n this.legoAbs = path.join(this.options.context!, 'src', LcdTempDir);\n }\n\n /**\n * 页面根目录绝对路径\n * 通常都是\n * - src\n * - components\n * */\n getPageRootAbs() {\n return path.join(this.options.context!, 'src', this.options.pageDir);\n }\n\n getSrcRootAbs() {\n return path.join(this.options.context!, 'src');\n }\n\n /**\n * 当前文件的绝对路径\n * */\n getCurrentFileAbs(relativeFilePath: string) {\n return path.join(this.getPageRootAbs(), relativeFilePath);\n }\n\n /** 当前文件的绝对目录路径 */\n getCurrentDirAbs(relativeFilePath: string) {\n return path.join(this.getPageRootAbs(), path.dirname(relativeFilePath));\n }\n\n /** 生成的 reducers 文件路径 */\n getReducersCacheFileAbs() {\n return path.join(this.legoAbs, dir, 'reducers.js');\n }\n\n getReducerPath(relativeFilePath: string) {\n const currentDir = path.dirname(relativeFilePath);\n const { pageDir, reducerName } = this.options;\n return `@/${pageDir}/${currentDir}/${reducerName}`;\n }\n\n getViewPath(relativeFilePath: string) {\n const currentDir = path.dirname(relativeFilePath);\n const { pageDir } = this.options;\n return `@/${pageDir}/${currentDir}/view`;\n }\n\n getSagaPath(relativeFilePath: string) {\n const currentDir = path.dirname(relativeFilePath);\n const { pageDir } = this.options;\n return `@/${pageDir}/${currentDir}/saga`;\n }\n\n /** 生成的 sagas 文件路径 */\n getSagasCacheFileAbs() {\n return path.join(this.legoAbs, dir, 'sagas.js');\n }\n\n /** 生成的 routers 文件路径 */\n getRoutersCacheFileAbs() {\n return path.join(this.legoAbs, dir, 'routers.js');\n }\n\n /** 主题文件cache 的路径 */\n getThemeJSCacheFileAbs(hash: string) {\n return path.join(this.legoAbs, dir, themes, `${hash}.js`);\n }\n\n getThemePath(hash: string) {\n return `@@/${dir}/${themes}/${hash}.js`;\n }\n\n /** 获取 mejson 编译后的文件路径 */\n getMeJSONCacheFileAbs(relativeFilePath: string) {\n return path.join(this.legoAbs, dir, 'me-json', this.getMeJsonCacheFileName(relativeFilePath));\n }\n\n getMeJSONRelativePath(relativeFilePath: string) {\n return `./me-json/${this.getMeJsonCacheFileName(relativeFilePath)}`;\n }\n\n getMeJsonCacheFileName(relativeFilePath: string) {\n return relativeFilePath.replace(/(.*)\\/me\\.json$/, '$1.js').replace(/\\//g, '-_-');\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,KAAA,GAAAC,sBAAA,CAAAC,OAAA;AAAwB,SAAAD,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAGjB,MAAMG,GAAG,GAAG,YAAY;AAACC,OAAA,CAAAD,GAAA,GAAAA,GAAA;AAEzB,MAAME,MAAM,GAAG,QAAQ;AAACD,OAAA,CAAAC,MAAA,GAAAA,MAAA;AAExB,MAAMC,UAAU,GAAG,OAAO;;AAEjC;AACA;AACA;AAFAF,OAAA,CAAAE,UAAA,GAAAA,UAAA;AAGO,MAAMC,WAAW,CAAC;EACvBC,OAAO;EAEPC,OAAO;EAEPC,WAAWA,CAACF,OAAO,EAAE;IACnB,IAAI,CAACA,OAAO,GAAGA,OAAO;IACtB,IAAI,CAACC,OAAO,GAAGE,aAAI,CAACC,IAAI,CAAC,IAAI,CAACJ,OAAO,CAACK,OAAO,EAAG,KAAK,EAAEP,UAAU,CAAC;EACpE;;EAEA;AACF;AACA;AACA;AACA;AACA;EAC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",
3
- "version": "9.2.1-alpha.1",
3
+ "version": "9.2.1-alpha.3",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "files": [