sugar-scripts 0.2.0-beta.0 → 1.0.0-beta.2

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.
Files changed (90) hide show
  1. package/lib/bin/cli-ts.d.ts +1 -0
  2. package/lib/bin/cli-ts.js +4 -0
  3. package/lib/bin/cli-ts.js.map +1 -0
  4. package/lib/bin/cli.d.ts +1 -0
  5. package/lib/bin/cli.js +4 -0
  6. package/lib/bin/cli.js.map +1 -0
  7. package/lib/commander/index.d.ts +1 -0
  8. package/lib/commander/index.js +79 -0
  9. package/lib/commander/index.js.map +1 -0
  10. package/lib/constants/index.d.ts +4 -0
  11. package/lib/constants/index.js +8 -0
  12. package/lib/constants/index.js.map +1 -0
  13. package/lib/core/build.d.ts +2 -0
  14. package/lib/core/build.js +74 -0
  15. package/lib/core/build.js.map +1 -0
  16. package/lib/core/cache.d.ts +2 -0
  17. package/lib/core/cache.js +9 -0
  18. package/lib/core/cache.js.map +1 -0
  19. package/lib/core/info.d.ts +1 -0
  20. package/lib/core/info.js +6 -0
  21. package/lib/core/info.js.map +1 -0
  22. package/lib/core/init-running-context.d.ts +2 -0
  23. package/lib/core/init-running-context.js +30 -0
  24. package/lib/core/init-running-context.js.map +1 -0
  25. package/lib/core/run-application.d.ts +2 -0
  26. package/lib/core/run-application.js +9 -0
  27. package/lib/core/run-application.js.map +1 -0
  28. package/lib/core/running-context.d.ts +23 -0
  29. package/lib/core/running-context.js +52 -0
  30. package/lib/core/running-context.js.map +1 -0
  31. package/lib/custom-config.type.d.ts +51 -0
  32. package/lib/custom-config.type.js +8 -0
  33. package/lib/custom-config.type.js.map +1 -0
  34. package/lib/index.d.ts +1 -0
  35. package/lib/index.js +6 -0
  36. package/lib/index.js.map +1 -0
  37. package/lib/shared/file-helpers.d.ts +18 -0
  38. package/lib/shared/file-helpers.js +227 -0
  39. package/lib/shared/file-helpers.js.map +1 -0
  40. package/lib/webpack/dll-dependencies-manifest-plugin.d.ts +15 -0
  41. package/lib/webpack/dll-dependencies-manifest-plugin.js +79 -0
  42. package/lib/webpack/dll-dependencies-manifest-plugin.js.map +1 -0
  43. package/lib/webpack/load-manifest.d.ts +11 -0
  44. package/lib/webpack/load-manifest.js +47 -0
  45. package/lib/webpack/load-manifest.js.map +1 -0
  46. package/lib/webpack/run-webpack.d.ts +2 -0
  47. package/lib/webpack/run-webpack.js +23 -0
  48. package/lib/webpack/run-webpack.js.map +1 -0
  49. package/lib/webpack/server-browser-entry.d.ts +12 -0
  50. package/lib/webpack/server-browser-entry.js +41 -0
  51. package/lib/webpack/server-browser-entry.js.map +1 -0
  52. package/lib/webpack/webpack.browser.d.ts +4 -0
  53. package/lib/webpack/webpack.browser.js +88 -0
  54. package/lib/webpack/webpack.browser.js.map +1 -0
  55. package/lib/webpack/webpack.common.d.ts +7 -0
  56. package/lib/webpack/webpack.common.js +80 -0
  57. package/lib/webpack/webpack.common.js.map +1 -0
  58. package/lib/webpack/webpack.server.d.ts +4 -0
  59. package/lib/webpack/webpack.server.js +74 -0
  60. package/lib/webpack/webpack.server.js.map +1 -0
  61. package/package.json +17 -32
  62. package/src/bin/cli-ts.ts +3 -0
  63. package/src/index.ts +0 -3
  64. package/CHANGELOG.md +0 -26
  65. package/bin/cli-ts.js +0 -3
  66. package/bin/cli.js +0 -3
  67. package/src/app-utils/index.ts +0 -1
  68. package/src/app-utils/static.ts +0 -42
  69. package/src/commander/index.ts +0 -95
  70. package/src/configs/babel.server.config.ts +0 -42
  71. package/src/configs/babel.static.config.ts +0 -43
  72. package/src/constants/index.ts +0 -5
  73. package/src/core/build.ts +0 -98
  74. package/src/core/cache.ts +0 -15
  75. package/src/core/entry.ts +0 -189
  76. package/src/core/info.ts +0 -5
  77. package/src/core/init-running-context.ts +0 -27
  78. package/src/core/run-application.ts +0 -12
  79. package/src/core/running-context.ts +0 -92
  80. package/src/custom-config.type.ts +0 -66
  81. package/src/shared/file-helpers.ts +0 -192
  82. package/src/typings.d.ts +0 -8
  83. package/src/webpack/auto-entries.ts +0 -5
  84. package/src/webpack/dll-dependencies-manifest-plugin.ts +0 -115
  85. package/src/webpack/load-manifest.ts +0 -73
  86. package/src/webpack/run-webpack.ts +0 -22
  87. package/src/webpack/webpack.browser.ts +0 -107
  88. package/src/webpack/webpack.common.ts +0 -146
  89. package/src/webpack/webpack.server.ts +0 -100
  90. package/tsconfig.json +0 -25
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.createCommonChainConfig = void 0;
16
+ const path_1 = __importDefault(require("path"));
17
+ const webpack_1 = __importDefault(require("webpack"));
18
+ const webpack_chain_1 = __importDefault(require("webpack-chain"));
19
+ const mode = process.env.WEBPACK_MODE === 'development' ? 'development' : 'production';
20
+ // const mode = 'development';
21
+ /**
22
+ * common 是创建基础的webpack配置项,基于webpack-chain
23
+ * 用于被 webpack.dll 、webpack.frontend、webpack.server扩展
24
+ */
25
+ function createCommonChainConfig(context, output) {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ let chainConfig = new webpack_chain_1.default();
28
+ chainConfig.merge({
29
+ context: context.root,
30
+ resolve: {
31
+ extensions: [
32
+ '.ts',
33
+ '.tsx',
34
+ '.js',
35
+ '.jsx'
36
+ ],
37
+ },
38
+ output: {
39
+ path: path_1.default.resolve(context.root, output || 'dist'),
40
+ filename: mode === 'development'
41
+ ? '[name].js'
42
+ : '[name].[contenthash].js'
43
+ },
44
+ mode,
45
+ devtool: process.env.NODE_ENV === 'development' ? 'cheap-module-eval-source-map' : false,
46
+ optimization: {
47
+ moduleIds: 'named',
48
+ chunkIds: 'named'
49
+ },
50
+ stats: {
51
+ all: true,
52
+ errorDetails: true
53
+ },
54
+ module: {
55
+ rule: {
56
+ script: {
57
+ test: /\.(ts|tsx|js|jsx)$/,
58
+ use: {
59
+ 'ts-loader': {
60
+ loader: 'ts-loader',
61
+ options: {
62
+ transpileOnly: true
63
+ }
64
+ }
65
+ }
66
+ }
67
+ },
68
+ },
69
+ plugin: {
70
+ 'ProgressPlugin': {
71
+ plugin: webpack_1.default.ProgressPlugin,
72
+ args: []
73
+ }
74
+ }
75
+ });
76
+ return chainConfig;
77
+ });
78
+ }
79
+ exports.createCommonChainConfig = createCommonChainConfig;
80
+ //# sourceMappingURL=webpack.common.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webpack.common.js","sourceRoot":"","sources":["../../src/webpack/webpack.common.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,gDAAwB;AACxB,sDAA8B;AAC9B,kEAA+C;AAM/C,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,KAAK,aAAa,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,YAAY,CAAC;AACvF,8BAA8B;AAE9B;;;GAGG;AAEH,SAAsB,uBAAuB,CAC3C,OAA4B,EAC5B,MAAc;;QAEd,IAAI,WAAW,GAAG,IAAI,uBAAkB,EAAE,CAAC;QAE3C,WAAW,CAAC,KAAK,CAAC;YAChB,OAAO,EAAE,OAAO,CAAC,IAAI;YACrB,OAAO,EAAE;gBACP,UAAU,EAAE;oBACV,KAAK;oBACL,MAAM;oBACN,KAAK;oBACL,MAAM;iBACP;aACF;YACD,MAAM,EAAE;gBACN,IAAI,EAAE,cAAI,CAAC,OAAO,CAChB,OAAO,CAAC,IAAI,EACZ,MAAM,IAAI,MAAM,CACjB;gBACD,QAAQ,EACN,IAAI,KAAK,aAAa;oBACpB,CAAC,CAAC,WAAW;oBACb,CAAC,CAAC,yBAAyB;aAChC;YACD,IAAI;YACJ,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,aAAa,CAAC,CAAC,CAAC,8BAA8B,CAAC,CAAC,CAAC,KAAK;YACxF,YAAY,EAAE;gBACZ,SAAS,EAAE,OAAO;gBAClB,QAAQ,EAAE,OAAO;aAClB;YACD,KAAK,EAAE;gBACL,GAAG,EAAE,IAAI;gBACT,YAAY,EAAE,IAAI;aACnB;YACD,MAAM,EAAE;gBACN,IAAI,EAAE;oBACJ,MAAM,EAAE;wBACN,IAAI,EAAE,oBAAoB;wBAC1B,GAAG,EAAE;4BACH,WAAW,EAAE;gCACX,MAAM,EAAE,WAAW;gCACnB,OAAO,EAAE;oCACP,aAAa,EAAE,IAAI;iCACpB;6BACF;yBACF;qBACF;iBACF;aACF;YACD,MAAM,EAAE;gBACN,gBAAgB,EAAE;oBAChB,MAAM,EAAE,iBAAO,CAAC,cAAc;oBAC9B,IAAI,EAAE,EAAE;iBACT;aACF;SACF,CAAC,CAAA;QAEF,OAAO,WAAW,CAAC;IACrB,CAAC;CAAA;AA5DD,0DA4DC"}
@@ -0,0 +1,4 @@
1
+ import WebpackChainConfig from 'webpack-chain';
2
+ import { SugarScriptsContext } from '../core/running-context';
3
+ export declare function mergeServerEntry(context: SugarScriptsContext, chainConfig: WebpackChainConfig): Promise<void>;
4
+ export declare function mergeServerCustomConfig(context: SugarScriptsContext, chainConfig: WebpackChainConfig): Promise<void>;
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.mergeServerCustomConfig = exports.mergeServerEntry = void 0;
16
+ const path_1 = __importDefault(require("path"));
17
+ const webpack_1 = __importDefault(require("webpack"));
18
+ const server_browser_entry_1 = require("./server-browser-entry");
19
+ function mergeServerEntry(context, chainConfig) {
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ if (!context.packageConfig.server)
22
+ return;
23
+ const serverConfig = context.packageConfig.server;
24
+ chainConfig.entry('main')
25
+ .merge([
26
+ serverConfig.render || '',
27
+ serverConfig.entry
28
+ ].filter((path) => !!path));
29
+ chainConfig.merge({
30
+ target: 'node',
31
+ output: {
32
+ filename: '[name].js',
33
+ library: {
34
+ type: 'commonjs',
35
+ }
36
+ },
37
+ optimization: {
38
+ minimize: false,
39
+ },
40
+ externalsPresets: { node: true },
41
+ plugin: {
42
+ 'SugarServerBrowserEntryPlugin': {
43
+ plugin: server_browser_entry_1.SugarServerBrowserEntryPlugin,
44
+ args: [{
45
+ root: context.root,
46
+ output: (0, server_browser_entry_1.getCacheFilePath)(context)
47
+ }]
48
+ },
49
+ 'DefinePlugin': {
50
+ plugin: webpack_1.default.DefinePlugin,
51
+ args: [{
52
+ 'process.env.SUGAR_PROJECT_RUN': JSON.stringify(true),
53
+ 'process.env.SUGAR_PROJECT_RENDER': JSON.stringify(serverConfig.render
54
+ && path_1.default.resolve(context.root, serverConfig.render)),
55
+ 'process.env.SUGAR_PROJECT_ENTRIES': `require('./browser-manifest.json')`
56
+ }]
57
+ }
58
+ }
59
+ });
60
+ });
61
+ }
62
+ exports.mergeServerEntry = mergeServerEntry;
63
+ function mergeServerCustomConfig(context, chainConfig) {
64
+ return __awaiter(this, void 0, void 0, function* () {
65
+ if (context.projectConfigs.serverWebpackConfig) {
66
+ yield context.projectConfigs.serverWebpackConfig(chainConfig, context);
67
+ }
68
+ if (context.packageConfigs.serverWebpackConfig) {
69
+ yield context.packageConfigs.serverWebpackConfig(chainConfig, context);
70
+ }
71
+ });
72
+ }
73
+ exports.mergeServerCustomConfig = mergeServerCustomConfig;
74
+ //# sourceMappingURL=webpack.server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webpack.server.js","sourceRoot":"","sources":["../../src/webpack/webpack.server.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,gDAAwB;AACxB,sDAA8B;AAO9B,iEAGgC;AAEhC,SAAsB,gBAAgB,CACpC,OAA4B,EAC5B,WAA+B;;QAE/B,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM;YAAE,OAAO;QAC1C,MAAM,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC;QAElD,WAAW,CAAC,KAAK,CAAC,MAAM,CAAC;aACtB,KAAK,CACJ;YACE,YAAY,CAAC,MAAM,IAAI,EAAE;YACzB,YAAY,CAAC,KAAK;SACnB,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAa,CACvC,CAAC;QAEJ,WAAW,CAAC,KAAK,CAAC;YACd,MAAM,EAAE,MAAM;YACd,MAAM,EAAE;gBACN,QAAQ,EAAE,WAAW;gBACrB,OAAO,EAAE;oBACP,IAAI,EAAE,UAAU;iBACjB;aACF;YACD,YAAY,EAAE;gBACZ,QAAQ,EAAE,KAAK;aAChB;YACD,gBAAgB,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE;YAChC,MAAM,EAAE;gBACN,+BAA+B,EAAE;oBAC/B,MAAM,EAAE,oDAA6B;oBACrC,IAAI,EAAE,CAAC;4BACL,IAAI,EAAE,OAAO,CAAC,IAAI;4BAClB,MAAM,EAAE,IAAA,uCAAgB,EAAC,OAAO,CAAC;yBAClC,CAAC;iBACH;gBACD,cAAc,EAAE;oBACd,MAAM,EAAE,iBAAO,CAAC,YAAY;oBAC5B,IAAI,EAAE,CAAC;4BACL,+BAA+B,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;4BACrD,kCAAkC,EAAE,IAAI,CAAC,SAAS,CAChD,YAAY,CAAC,MAAM;mCAChB,cAAI,CAAC,OAAO,CACb,OAAO,CAAC,IAAI,EACZ,YAAY,CAAC,MAAM,CACpB,CACF;4BACD,mCAAmC,EAAE,oCAAoC;yBAC1E,CAAC;iBACH;aACF;SACF,CAAC,CAAA;IACN,CAAC;CAAA;AAnDD,4CAmDC;AAED,SAAsB,uBAAuB,CAC3C,OAA4B,EAC5B,WAA+B;;QAE/B,IAAI,OAAO,CAAC,cAAc,CAAC,mBAAmB,EAAE;YAC9C,MAAM,OAAO,CAAC,cAAc,CAAC,mBAAmB,CAC9C,WAAW,EACX,OAAO,CACR,CAAA;SACF;QAED,IAAI,OAAO,CAAC,cAAc,CAAC,mBAAmB,EAAE;YAC9C,MAAM,OAAO,CAAC,cAAc,CAAC,mBAAmB,CAC9C,WAAW,EACX,OAAO,CACR,CAAA;SACF;IACH,CAAC;CAAA;AAjBD,0DAiBC"}
package/package.json CHANGED
@@ -1,53 +1,38 @@
1
1
  {
2
2
  "name": "sugar-scripts",
3
- "version": "0.2.0-beta.0",
3
+ "version": "1.0.0-beta.2",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "bin": {
7
- "sugar-scripts": "./bin/cli.js"
7
+ "sugar-scripts": "./lib/bin/cli.js"
8
8
  },
9
+ "files": [
10
+ "lib"
11
+ ],
9
12
  "author": "",
10
13
  "license": "MIT",
11
14
  "dependencies": {
12
- "babel-loader": "^8.0.6",
13
- "chalk": "~4.1.2",
14
- "commander": "^8.1.0",
15
- "glob": "~7.2.0",
15
+ "chalk": "^4",
16
+ "commander": "^9.4.0",
17
+ "glob": "^8.0.3",
16
18
  "koa-send": "~5.0.1",
17
- "sugar-scripts": "^0.2.0-beta.0",
18
- "sugar-server": "^0.2.0-beta.0",
19
- "ts-loader": "^9.3.0",
20
- "ts-node": "^10.4.0",
21
- "webpack": "^5",
19
+ "simple-git": "^3.12.0",
20
+ "sugar-server": "^1.0.0-beta.2",
21
+ "webpack": "^5.74.0",
22
22
  "webpack-chain": "~6.5.1",
23
- "webpack-manifest-plugin": "^3.2.0"
23
+ "webpack-manifest-plugin": "^5.0.0"
24
24
  },
25
25
  "devDependencies": {
26
- "@babel/core": "^7.7.0",
27
- "@babel/node": "^7.7.0",
28
- "@babel/plugin-proposal-class-properties": "^7.7.0",
29
- "@babel/plugin-proposal-decorators": "^7.7.0",
30
- "@babel/plugin-proposal-object-rest-spread": "^7.7.4",
31
- "@babel/plugin-transform-arrow-functions": "^7.7.4",
32
- "@babel/plugin-transform-runtime": "^7.8.3",
33
- "@babel/preset-env": "^7.7.0",
34
- "@babel/preset-react": "^7.7.0",
35
- "@babel/preset-typescript": "^7.7.4",
36
- "@babel/runtime": "^7.8.3",
37
- "@babel/runtime-corejs3": "^7.8.3",
38
26
  "@types/glob": "~7.2.0",
39
27
  "@types/koa-send": "~4.1.3",
40
28
  "@types/node": "^18.0.0",
41
29
  "@types/webpack": "^5",
42
- "babel-loader": "^8.0.6",
43
- "babel-plugin-parameter-decorator": "^1.0.16",
44
- "typescript": "^4.3.5"
45
- },
46
- "peerDependencies": {
47
- "ts-loader": "^9.3.0"
30
+ "ts-node": "^10.9.1",
31
+ "typescript": "^4.3.5",
32
+ "rimraf": "^3.0.2"
48
33
  },
49
34
  "scripts": {
50
- "clean": "rm -fr lib",
51
- "build": "npm run clean && tsc"
35
+ "clean": "rimraf lib",
36
+ "build": "npm run clean && tsc -p tsconfig.build.json"
52
37
  }
53
38
  }
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ts-node
2
+
3
+ require('../commander');
package/src/index.ts CHANGED
@@ -1,6 +1,3 @@
1
- export * as entry from './core/entry';
2
- export * as appUtils from './app-utils'
3
-
4
1
  export {
5
2
  SugarScriptsProject
6
3
  } from './custom-config.type';
package/CHANGELOG.md DELETED
@@ -1,26 +0,0 @@
1
- # sugar-scripts
2
-
3
- ## 0.2.0-beta.0
4
-
5
- ### Minor Changes
6
-
7
- - sugar-scripts 添加统一 running-context,命令都基于此运行
8
-
9
- ### Patch Changes
10
-
11
- - 5101c4b: 添加 sugar-scripts,改造为基于 pnpm 的 monorepo
12
- sugar-server 移除 server,整合为 application
13
- - Updated dependencies
14
- - Updated dependencies [5101c4b]
15
- - sugar-scripts@0.2.0-beta.0
16
- - sugar-server@0.2.0-beta.0
17
-
18
- ## 1.0.1
19
-
20
- ### Patch Changes
21
-
22
- - 5101c4b: 添加 sugar-scripts,改造为基于 pnpm 的 monorepo
23
- sugar-server 移除 server,整合为 application
24
- - Updated dependencies [5101c4b]
25
- - sugar-scripts@1.0.1
26
- - sugar-server@0.1.16
package/bin/cli-ts.js DELETED
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env ts-node
2
-
3
- require('../src/commander');
package/bin/cli.js DELETED
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- require('../lib/commander');
@@ -1 +0,0 @@
1
- export * from './static';
@@ -1,42 +0,0 @@
1
- import send from 'koa-send';
2
-
3
- import {
4
- router,
5
- parameter,
6
- Controller
7
- } from 'sugar-server';
8
-
9
- const { GetRoute } = router;
10
-
11
- export function createStaticController ({
12
- staticResourcesPath,
13
- prefix = '/'
14
- }: {
15
- staticResourcesPath: string,
16
- prefix?: string;
17
- }): typeof Controller {
18
- class StaticController extends Controller {
19
- static prefix = prefix;
20
-
21
- @GetRoute('*')
22
- @parameter.getter
23
- async status (
24
- @parameter.Context ctx: any
25
- ) {
26
- const routerPath = ctx.routerPath || ctx.path;
27
- const filePath = routerPath.substr(prefix.length);
28
-
29
- if (filePath) {
30
- await send(
31
- ctx,
32
- filePath,
33
- {
34
- root: staticResourcesPath,
35
- maxAge: 86400000
36
- });
37
- }
38
- }
39
- }
40
-
41
- return StaticController;
42
- }
@@ -1,95 +0,0 @@
1
- import path from 'path';
2
- import chalk from 'chalk';
3
- import { Command } from 'commander';
4
-
5
- import {
6
- initRunningContext
7
- } from '../core/init-running-context';
8
- import {
9
- build
10
- } from '../core/build';
11
- import {
12
- info
13
- } from '../core/info';
14
- import {
15
- clean as cacheClean
16
- } from '../core/cache';
17
- import {
18
- runApplication
19
- } from '../core/run-application';
20
-
21
- const program = new Command();
22
- program
23
- .version('1.0.0');
24
-
25
- program
26
- .command('info')
27
- .description('工程信息')
28
- .option('--dir <dir>', '自定义运行的目录')
29
- .action(async (options, command) => {
30
- const cwd = process.cwd();
31
- const dir = options.dir ? path.resolve(cwd, options.dir) : cwd
32
- // process.exit();
33
- })
34
-
35
- program
36
- .command('build')
37
- .description('构建服务')
38
- .option('--dir <dir>', '自定义运行的目录')
39
- .action(async (options, command) => {
40
- const cwd = process.cwd();
41
- const dir = options.dir ? path.resolve(cwd, options.dir) : cwd
42
-
43
- const context = await initRunningContext(dir);
44
- await build(
45
- context
46
- );
47
- console.log(`✅ ${chalk.bold.green('构建成功')}`);
48
- })
49
-
50
-
51
- const cacheCommand = new Command();
52
- cacheCommand
53
- .name('cache')
54
- .description('构建缓存管理');
55
-
56
- cacheCommand
57
- .command('clean')
58
- .description('清理构建缓存')
59
- .option('--dir <dir>', '自定义运行的目录')
60
- .action(async (options, command) => {
61
- const cwd = process.cwd();
62
- const dir = options.dir ? path.resolve(cwd, options.dir) : cwd;
63
- const context = await initRunningContext(dir);
64
- await cacheClean(context);
65
- console.log(`✅ ${chalk.bold.green('清理构建缓存成功')}`);
66
- })
67
-
68
- program.addCommand(cacheCommand)
69
-
70
- program
71
- .command('start')
72
- .description('启动开发服务')
73
- .option('--dir <dir>', '自定义运行的目录')
74
- .option('--port <port>', '指定运行的端口')
75
- .action(async (options, command) => {
76
- const cwd = process.cwd();
77
- const dir = options.dir ? path.resolve(cwd, options.dir) : cwd
78
- const port = +options.port;
79
-
80
- const context = await initRunningContext(dir);
81
- const appFilePath = context.getStartFilePath()
82
-
83
- if (!appFilePath) return;
84
- const App = require(
85
- appFilePath
86
- ).default;
87
-
88
- runApplication(
89
- App,
90
- port
91
- );
92
- console.log(`✅ ${chalk.bold.green(`启动服务成功,端口:${port}`)}`);
93
- })
94
-
95
- program.parse(process.argv);
@@ -1,42 +0,0 @@
1
- const path = require('path');
2
-
3
- export const babelConfig = {
4
- presets: [
5
- [
6
- '@babel/preset-typescript',
7
- {
8
- 'onlyRemoveTypeImports': true
9
- }
10
- ],
11
- ['@babel/preset-react'],
12
- [
13
- '@babel/preset-env',
14
- {
15
- loose: true,
16
- targets: {
17
- node: 'current'
18
- }
19
- }
20
- ]
21
- ],
22
- plugins: [
23
- // [
24
- // '@babel/plugin-transform-runtime',
25
- // {
26
- // corejs: 3,
27
- // regenerator: true
28
- // }
29
- // ],
30
- '@babel/plugin-transform-arrow-functions',
31
- '@babel/plugin-proposal-object-rest-spread',
32
- [
33
- '@babel/plugin-proposal-decorators',
34
- { legacy: true }
35
- ],
36
- [
37
- '@babel/plugin-proposal-class-properties',
38
- { loose: true }
39
- ],
40
- ['babel-plugin-parameter-decorator']
41
- ]
42
- }
@@ -1,43 +0,0 @@
1
- export const babelConfig = {
2
- presets: [
3
- ['@babel/preset-typescript'],
4
- ['@babel/preset-react'],
5
- [
6
- '@babel/preset-env',
7
- {
8
- loose: true,
9
- targets: {
10
- chrome: '58',
11
- ie: '11'
12
- }
13
- // useBuiltIns: "entry"
14
- // corejs: false
15
- }
16
- ]
17
- ],
18
- plugins: [
19
- [
20
- '@babel/plugin-transform-runtime',
21
- {
22
- // "corejs": 3,
23
- // polyfill: false,
24
- corejs: false,
25
- regenerator: true
26
- }
27
- ],
28
- '@babel/plugin-transform-arrow-functions',
29
- '@babel/plugin-proposal-object-rest-spread',
30
- [
31
- '@babel/plugin-proposal-decorators',
32
- {
33
- legacy: true
34
- }
35
- ],
36
- [
37
- '@babel/plugin-proposal-class-properties',
38
- {
39
- loose: true
40
- }
41
- ]
42
- ]
43
- }
@@ -1,5 +0,0 @@
1
- export const SUGAR_PACKAGE_CONFIG_FILENAME = 'sugar.package';
2
- export const SUGAR_PROJECT_CONFIG_FILENAME = 'sugar.project';
3
-
4
- export const SUGAR_BUILD_EXPORT_BROWSER = 'browserWebpackConfig';
5
- export const SUGAR_BUILD_EXPORT_SERVER = 'serverWebpackConfig';
package/src/core/build.ts DELETED
@@ -1,98 +0,0 @@
1
- import path from 'path';
2
- import * as tsNode from 'ts-node';
3
-
4
- import {
5
- SugarScriptsContext
6
- } from './running-context';
7
-
8
- import {
9
- mergeBrowserEntryFromServer,
10
- mergeBuildDllConfig,
11
- mergeBrowserCustomConfig
12
- } from '../webpack/webpack.browser';
13
- import {
14
- mergeServerEntry,
15
- mergeServerCustomConfig
16
- } from '../webpack/webpack.server';
17
- import {
18
- createCommonChainConfig,
19
- mergeDllReferences
20
- } from '../webpack/webpack.common';
21
- import {
22
- runWebpack
23
- } from '../webpack/run-webpack';
24
-
25
-
26
- export const build = async (
27
- context: SugarScriptsContext
28
- ) => {
29
- tsNode.register({
30
- cwd: context.root,
31
- projectSearchDir: context.root,
32
- project: path.resolve(context.root, './tsconfig.json'),
33
- transpileOnly: true
34
- })
35
-
36
- await buildBrowser(
37
- context
38
- )
39
-
40
- await buildServer(
41
- context
42
- )
43
- }
44
-
45
- const buildBrowser = async (context: SugarScriptsContext) => {
46
- if (!context.packageConfig.browser) return;
47
- const browserConfig = context.packageConfig.browser;
48
-
49
- const chainConfig = await createCommonChainConfig(
50
- context,
51
- browserConfig.output
52
- );
53
-
54
- await mergeBrowserEntryFromServer(
55
- context,
56
- chainConfig
57
- )
58
-
59
- // 合并其他已经构建好的dll
60
- await mergeDllReferences(
61
- context,
62
- chainConfig,
63
- )
64
-
65
- // 如果是dll
66
- await mergeBuildDllConfig(
67
- context,
68
- chainConfig
69
- )
70
-
71
- await mergeBrowserCustomConfig(
72
- context,
73
- chainConfig
74
- )
75
-
76
- await runWebpack(chainConfig);
77
- }
78
-
79
-
80
- const buildServer = async (context: SugarScriptsContext) => {
81
- if (!context.packageConfig.server) return;
82
- const serverConfig = context.packageConfig.server;
83
-
84
- const chainConfig = await createCommonChainConfig(
85
- context,
86
- serverConfig.output
87
- );
88
-
89
- await mergeServerEntry(
90
- context,
91
- chainConfig
92
- );
93
- await mergeServerCustomConfig(
94
- context,
95
- chainConfig
96
- );
97
- await runWebpack(chainConfig);
98
- }
package/src/core/cache.ts DELETED
@@ -1,15 +0,0 @@
1
- import path from 'path';
2
- import {
3
- SugarScriptsContext
4
- } from './running-context';
5
- import {
6
- rm
7
- } from '../shared/file-helpers';
8
-
9
- export const clean = (
10
- context: SugarScriptsContext
11
- ) => {
12
- return rm(
13
- context.getCacheDir()
14
- );
15
- }