@modern-js/app-tools 1.3.0 → 1.4.1

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 (51) hide show
  1. package/CHANGELOG.md +87 -0
  2. package/dist/js/modern/commands/build.js +24 -8
  3. package/dist/js/modern/commands/dev.js +32 -12
  4. package/dist/js/modern/index.js +30 -6
  5. package/dist/js/modern/locale/en.js +2 -1
  6. package/dist/js/modern/locale/zh.js +2 -1
  7. package/dist/js/modern/utils/createServer.js +8 -1
  8. package/dist/js/modern/utils/getSpecifiedEntries.js +36 -0
  9. package/dist/js/modern/utils/printInstructions.js +4 -1
  10. package/dist/js/modern/utils/routes.js +15 -0
  11. package/dist/js/modern/utils/types.js +0 -0
  12. package/dist/js/node/commands/build.js +24 -7
  13. package/dist/js/node/commands/dev.js +36 -11
  14. package/dist/js/node/index.js +32 -5
  15. package/dist/js/node/locale/en.js +2 -1
  16. package/dist/js/node/locale/zh.js +2 -1
  17. package/dist/js/node/utils/createServer.js +15 -2
  18. package/dist/js/node/utils/getSpecifiedEntries.js +48 -0
  19. package/dist/js/node/utils/printInstructions.js +4 -1
  20. package/dist/js/node/utils/routes.js +25 -0
  21. package/dist/js/node/utils/types.js +0 -0
  22. package/dist/types/commands/dev.d.ts +2 -1
  23. package/dist/types/index.d.ts +2 -0
  24. package/dist/types/locale/en.d.ts +1 -0
  25. package/dist/types/locale/index.d.ts +2 -0
  26. package/dist/types/locale/zh.d.ts +1 -0
  27. package/dist/types/utils/createServer.d.ts +2 -0
  28. package/dist/types/utils/getSpecifiedEntries.d.ts +2 -0
  29. package/dist/types/utils/routes.d.ts +3 -0
  30. package/dist/types/utils/types.d.ts +3 -0
  31. package/lib/types.d.ts +0 -10
  32. package/package.json +16 -16
  33. package/tests/commands/build.test.ts +37 -0
  34. package/tests/commands/dev.test.ts +7 -0
  35. package/tests/routes.test.ts +27 -0
  36. package/tests/tsconfig.json +13 -0
  37. package/tests/utils.test.ts +67 -0
  38. package/src/commands/build.ts +0 -129
  39. package/src/commands/deploy.ts +0 -6
  40. package/src/commands/dev.ts +0 -80
  41. package/src/commands/index.ts +0 -3
  42. package/src/commands/start.ts +0 -30
  43. package/src/index.ts +0 -100
  44. package/src/lifecycle.ts +0 -43
  45. package/src/locale/en.ts +0 -18
  46. package/src/locale/index.ts +0 -9
  47. package/src/locale/zh.ts +0 -18
  48. package/src/utils/createCompiler.ts +0 -81
  49. package/src/utils/createServer.ts +0 -16
  50. package/src/utils/language.ts +0 -6
  51. package/src/utils/printInstructions.ts +0 -25
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getSpecifiedEntries = void 0;
7
+
8
+ var _inquirer = _interopRequireDefault(require("inquirer"));
9
+
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+
12
+ const getSpecifiedEntries = async (entry, entrypoints) => {
13
+ const entryNames = entrypoints.map(e => e.entryName);
14
+
15
+ if (!entry) {
16
+ return entryNames;
17
+ }
18
+
19
+ if (typeof entry === 'boolean') {
20
+ const {
21
+ selected
22
+ } = await _inquirer.default.prompt([{
23
+ type: 'checkbox',
24
+ name: 'selected',
25
+ choices: entryNames,
26
+ message: '请选择需要构建的入口',
27
+
28
+ validate(answer) {
29
+ if (answer.length < 1) {
30
+ return 'You must choose at least one topping.';
31
+ }
32
+
33
+ return true;
34
+ }
35
+
36
+ }]);
37
+ return selected;
38
+ }
39
+
40
+ entry.forEach(name => {
41
+ if (!entryNames.includes(name)) {
42
+ throw new Error(`can not found entry ${name}, compiler entry should in ${entryNames.join(', ')}`);
43
+ }
44
+ });
45
+ return entry;
46
+ };
47
+
48
+ exports.getSpecifiedEntries = getSpecifiedEntries;
@@ -11,8 +11,11 @@ var _core = require("@modern-js/core");
11
11
 
12
12
  const printInstructions = async (appContext, config) => {
13
13
  let message = (0, _utils.prettyInstructions)(appContext, config);
14
+ const {
15
+ existSrc
16
+ } = appContext;
14
17
 
15
- if ((0, _utils.isDev)()) {
18
+ if ((0, _utils.isDev)() && existSrc) {
16
19
  message += `\n${_utils.chalk.cyanBright([`Note that the development build is not optimized.`, `To create a production build, execute build command.`].join('\n'))}`;
17
20
  } // call beforePrintInstructions hook.
18
21
 
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.generateRoutes = void 0;
7
+
8
+ var _path = _interopRequireDefault(require("path"));
9
+
10
+ var _utils = require("@modern-js/utils");
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+
14
+ const generateRoutes = async appContext => {
15
+ const {
16
+ serverRoutes,
17
+ distDirectory
18
+ } = appContext;
19
+ const output = JSON.stringify({
20
+ routes: serverRoutes
21
+ }, null, 2);
22
+ await _utils.fs.outputFile(_path.default.join(distDirectory, _utils.ROUTE_SPEC_FILE), output);
23
+ };
24
+
25
+ exports.generateRoutes = generateRoutes;
File without changes
@@ -1 +1,2 @@
1
- export declare const dev: () => Promise<void>;
1
+ import { DevOptions } from '../utils/types';
2
+ export declare const dev: (options: DevOptions) => Promise<void>;
@@ -14,8 +14,10 @@ declare const _default: import("@modern-js/core").AsyncPlugin<Partial<import("@m
14
14
  watchFiles: import("@modern-js/core").ParallelWorkflow<void, unknown>;
15
15
  fileChange: import("@modern-js/core").AsyncWorkflow<{
16
16
  filename: string;
17
+ eventType: "add" | "unlink" | "change";
17
18
  }, void>;
18
19
  beforeExit: import("@modern-js/core").AsyncWorkflow<void, void>;
20
+ beforeRestart: import("@modern-js/core").AsyncWorkflow<void, void>;
19
21
  } & import("@modern-js/core").ClearDraftProgress<import("@modern-js/core").Hooks>>>>;
20
22
 
21
23
  export default _default;
@@ -3,6 +3,7 @@ export declare const EN_LOCALE: {
3
3
  dev: {
4
4
  describe: string;
5
5
  config: string;
6
+ entry: string;
6
7
  };
7
8
  build: {
8
9
  describe: string;
@@ -5,6 +5,7 @@ declare const localeKeys: {
5
5
  dev: {
6
6
  describe: string;
7
7
  config: string;
8
+ entry: string;
8
9
  };
9
10
  build: {
10
11
  describe: string;
@@ -29,6 +30,7 @@ declare const localeKeys: {
29
30
  dev: {
30
31
  describe: string;
31
32
  config: string;
33
+ entry: string;
32
34
  };
33
35
  build: {
34
36
  describe: string;
@@ -3,6 +3,7 @@ export declare const ZH_LOCALE: {
3
3
  dev: {
4
4
  describe: string;
5
5
  config: string;
6
+ entry: string;
6
7
  };
7
8
  build: {
8
9
  describe: string;
@@ -1,2 +1,4 @@
1
1
  import { Server, ModernServerOptions } from '@modern-js/server';
2
+ export declare const getServer: () => Server | null;
3
+ export declare const closeServer: () => Promise<void>;
2
4
  export declare const createServer: (options: ModernServerOptions) => Promise<Server>;
@@ -0,0 +1,2 @@
1
+ import { Entrypoint } from '@modern-js/types';
2
+ export declare const getSpecifiedEntries: (entry: string[] | boolean, entrypoints: Entrypoint[]) => Promise<string[]>;
@@ -0,0 +1,3 @@
1
+ import { IAppContext } from '@modern-js/core';
2
+ declare const generateRoutes: (appContext: IAppContext) => Promise<void>;
3
+ export { generateRoutes };
@@ -0,0 +1,3 @@
1
+ export declare type DevOptions = {
2
+ entry: string[] | boolean;
3
+ };
package/lib/types.d.ts CHANGED
@@ -71,11 +71,6 @@ declare module '*.less' {
71
71
  export default classes;
72
72
  }
73
73
 
74
- declare module '*.styl' {
75
- const classes: { readonly [key: string]: string };
76
- export default classes;
77
- }
78
-
79
74
  declare module '*.sass' {
80
75
  const classes: { readonly [key: string]: string };
81
76
  export default classes;
@@ -96,11 +91,6 @@ declare module '*.module.less' {
96
91
  export default classes;
97
92
  }
98
93
 
99
- declare module '*.module.styl' {
100
- const classes: { readonly [key: string]: string };
101
- export default classes;
102
- }
103
-
104
94
  declare module '*.module.sass' {
105
95
  const classes: { readonly [key: string]: string };
106
96
  export default classes;
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.3.0",
14
+ "version": "1.4.1",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",
@@ -50,18 +50,18 @@
50
50
  },
51
51
  "dependencies": {
52
52
  "@babel/runtime": "^7",
53
- "@modern-js/core": "^1.3.0",
54
- "@modern-js/types": "^1.2.0",
55
- "@modern-js/i18n-cli-language-detector": "^1.2.0",
56
- "@modern-js/new-action": "^1.3.0",
57
- "@modern-js/plugin": "^1.2.0",
58
- "@modern-js/plugin-analyze": "^1.2.0",
59
- "@modern-js/plugin-fast-refresh": "^1.2.0",
60
- "@modern-js/plugin-i18n": "^1.2.0",
61
- "@modern-js/plugin-polyfill": "^1.2.0",
62
- "@modern-js/server": "^1.3.0",
63
- "@modern-js/utils": "^1.2.0",
64
- "@modern-js/webpack": "^1.2.0",
53
+ "@modern-js/core": "^1.4.1",
54
+ "@modern-js/types": "^1.3.1",
55
+ "@modern-js/i18n-cli-language-detector": "^1.2.1",
56
+ "@modern-js/new-action": "^1.3.1",
57
+ "@modern-js/plugin": "^1.2.1",
58
+ "@modern-js/plugin-analyze": "^1.3.1",
59
+ "@modern-js/plugin-fast-refresh": "^1.2.1",
60
+ "@modern-js/plugin-i18n": "^1.2.1",
61
+ "@modern-js/server": "^1.4.1",
62
+ "@modern-js/utils": "^1.3.1",
63
+ "@modern-js/webpack": "^1.3.1",
64
+ "inquirer": "^8.2.0",
65
65
  "webpack": "^5.54.0"
66
66
  },
67
67
  "devDependencies": {
@@ -72,7 +72,8 @@
72
72
  "typescript": "^4",
73
73
  "@scripts/build": "0.0.0",
74
74
  "jest": "^27",
75
- "@scripts/jest-config": "0.0.0"
75
+ "@scripts/jest-config": "0.0.0",
76
+ "@types/inquirer": "^8.2.0"
76
77
  },
77
78
  "sideEffects": false,
78
79
  "modernConfig": {
@@ -82,8 +83,7 @@
82
83
  },
83
84
  "publishConfig": {
84
85
  "registry": "https://registry.npmjs.org/",
85
- "access": "public",
86
- "types": "./dist/types/index.d.ts"
86
+ "access": "public"
87
87
  },
88
88
  "scripts": {
89
89
  "new": "modern new",
@@ -0,0 +1,37 @@
1
+ import { build } from '../../src/commands/build';
2
+
3
+ const mockBeforeBuild = jest.fn();
4
+ const mockAfterBuild = jest.fn();
5
+ const mockGenerateRoutes = jest.fn();
6
+
7
+ jest.mock('@modern-js/core', () => ({
8
+ __esModule: true,
9
+ mountHook() {
10
+ return {
11
+ beforeBuild: mockBeforeBuild,
12
+ afterBuild: mockAfterBuild,
13
+ };
14
+ },
15
+ useAppContext: jest.fn(() => ({
16
+ existSrc: false,
17
+ })),
18
+ useResolvedConfigContext: jest.fn(),
19
+ }));
20
+
21
+ jest.mock('../../src/utils/routes', () => ({
22
+ __esModule: true,
23
+ generateRoutes: () => mockGenerateRoutes(),
24
+ }));
25
+
26
+ describe('command build', () => {
27
+ afterAll(() => {
28
+ jest.resetAllMocks();
29
+ });
30
+
31
+ test('existSrc is false', async () => {
32
+ await build();
33
+ expect(mockBeforeBuild).toBeCalled();
34
+ expect(mockGenerateRoutes).toBeCalled();
35
+ expect(mockAfterBuild).toBeCalled();
36
+ });
37
+ });
@@ -0,0 +1,7 @@
1
+ import { dev } from '../../src/commands/dev';
2
+
3
+ describe('command', () => {
4
+ test('dev', () => {
5
+ expect(dev).toBeDefined();
6
+ });
7
+ });
@@ -0,0 +1,27 @@
1
+ import { fs } from '@modern-js/utils';
2
+ import { generateRoutes } from '../src/utils/routes';
3
+
4
+ jest.mock('@modern-js/utils', () => {
5
+ const originalModule = jest.requireActual('@modern-js/utils');
6
+ return {
7
+ __esModule: true,
8
+ ...originalModule,
9
+ fs: {
10
+ outputFile: jest.fn((filename: string, output: string) => ({
11
+ filename,
12
+ output,
13
+ })),
14
+ },
15
+ };
16
+ });
17
+
18
+ describe('routes', () => {
19
+ test('generateRoutes', async () => {
20
+ const mockAppContext = {
21
+ serverRoutes: [],
22
+ distDirectory: './dist',
23
+ };
24
+ await generateRoutes(mockAppContext as any);
25
+ expect(fs.outputFile).toHaveBeenCalledTimes(1);
26
+ });
27
+ });
@@ -0,0 +1,13 @@
1
+ {
2
+ "extends": "@modern-js/tsconfig/base",
3
+ "compilerOptions": {
4
+ "declaration": true,
5
+ "jsx": "preserve",
6
+ "baseUrl": "./",
7
+ "outDir": "./out",
8
+ "emitDeclarationOnly": true,
9
+ "isolatedModules": true,
10
+ "paths": {},
11
+ "types": ["node", "jest"]
12
+ }
13
+ }
@@ -0,0 +1,67 @@
1
+ import inquirer from 'inquirer';
2
+ import { Server } from '@modern-js/server';
3
+ import {
4
+ closeServer,
5
+ createServer,
6
+ getServer,
7
+ } from '../src/utils/createServer';
8
+ import { getSpecifiedEntries } from '../src/utils/getSpecifiedEntries';
9
+
10
+ describe('test app-tools utils', () => {
11
+ it('should return all entryNames correctly', async () => {
12
+ const checked = await getSpecifiedEntries(false, [
13
+ { entryName: 'a' },
14
+ { entryName: 'b' },
15
+ ] as any);
16
+
17
+ expect(checked).toEqual(['a', 'b']);
18
+ });
19
+
20
+ it('should return spec entry', async () => {
21
+ const checked = await getSpecifiedEntries(['a'], [
22
+ { entryName: 'a' },
23
+ { entryName: 'b' },
24
+ ] as any);
25
+
26
+ expect(checked).toEqual(['a']);
27
+ });
28
+
29
+ it('should return select entry', async () => {
30
+ inquirer.prompt = jest.fn().mockResolvedValue({ selected: ['b'] }) as any;
31
+ const checked = await getSpecifiedEntries(true, [
32
+ { entryName: 'a' },
33
+ { entryName: 'b' },
34
+ ] as any);
35
+
36
+ expect(checked).toEqual(['b']);
37
+ });
38
+
39
+ it('should get error if entry not allow', resolve => {
40
+ getSpecifiedEntries(['c'], [
41
+ { entryName: 'a' },
42
+ { entryName: 'b' },
43
+ // eslint-disable-next-line promise/prefer-await-to-then
44
+ ] as any).catch(e => {
45
+ expect((e as Error).message).toMatch('can not found entry c');
46
+ resolve();
47
+ });
48
+ });
49
+
50
+ it('should create and close server correctly', async () => {
51
+ const app = await createServer({
52
+ dev: false,
53
+ pwd: '.',
54
+ config: {
55
+ output: {
56
+ path: 'dist',
57
+ },
58
+ },
59
+ } as any);
60
+
61
+ expect(app instanceof Server).toBe(true);
62
+ expect(getServer()).toBe(app);
63
+
64
+ await closeServer();
65
+ expect(getServer()).toBeNull();
66
+ });
67
+ });
@@ -1,129 +0,0 @@
1
- import { Configuration, webpack } from 'webpack';
2
- import { WebpackConfigTarget, getWebpackConfig } from '@modern-js/webpack';
3
- import {
4
- useAppContext,
5
- useResolvedConfigContext,
6
- mountHook,
7
- ResolvedConfigContext,
8
- manager,
9
- } from '@modern-js/core';
10
- import {
11
- fs,
12
- formatWebpackMessages,
13
- measureFileSizesBeforeBuild,
14
- printFileSizesAfterBuild,
15
- printBuildError,
16
- logger,
17
- isUseSSRBundle,
18
- } from '@modern-js/utils';
19
-
20
- // These sizes are pretty large. We'll warn for bundles exceeding them.
21
- const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024;
22
- const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024;
23
-
24
- interface CliOptions {
25
- analyze?: boolean;
26
- }
27
-
28
- export const build = async (options?: CliOptions) => {
29
- const webpackBuild = async (webpackConfig: Configuration, type?: string) => {
30
- const compiler = webpack(webpackConfig);
31
-
32
- return new Promise((resolve, reject) => {
33
- let label = process.env.NODE_ENV || '';
34
- if (type && type !== 'legacy') {
35
- label += ` ${type}`;
36
- }
37
- logger.info(`Creating a ${label} build...`);
38
-
39
- compiler.run((err, stats) => {
40
- let messages: {
41
- errors: any;
42
- warnings: any;
43
- };
44
- if (!err) {
45
- messages = formatWebpackMessages(
46
- stats!.toJson({ all: false, warnings: true, errors: true }),
47
- );
48
-
49
- if (messages.errors.length === 0) {
50
- logger.info(`File sizes after ${label} build:\n`);
51
- printFileSizesAfterBuild(
52
- stats,
53
- previousFileSizes,
54
- outputPath,
55
- WARN_AFTER_BUNDLE_GZIP_SIZE,
56
- WARN_AFTER_CHUNK_GZIP_SIZE,
57
- );
58
- logger.log();
59
- }
60
- }
61
-
62
- // When using run or watch, call close and wait for it to finish before calling run or watch again.
63
- // Concurrent compilations will corrupt the output files.
64
- compiler.close(closeErr => {
65
- if (closeErr) {
66
- logger.error(closeErr);
67
- }
68
- if (err) {
69
- reject(err);
70
- } else {
71
- if (messages.errors.length) {
72
- reject(new Error(messages.errors.join('\n\n')));
73
- return;
74
- }
75
- resolve({ warnings: messages.warnings });
76
- }
77
- });
78
- });
79
- });
80
- };
81
-
82
- /* eslint-disable react-hooks/rules-of-hooks */
83
- const resolvedConfig = useResolvedConfigContext();
84
- const appContext = useAppContext();
85
- /* eslint-enable react-hooks/rules-of-hooks */
86
-
87
- manager.run(() => {
88
- ResolvedConfigContext.set({ ...resolvedConfig, cliOptions: options });
89
- });
90
-
91
- const outputPath = appContext.distDirectory;
92
- const previousFileSizes = await measureFileSizesBeforeBuild(outputPath);
93
- fs.emptyDirSync(outputPath);
94
-
95
- const buildConfigs = [];
96
-
97
- buildConfigs.push({
98
- type: 'legacy',
99
- config: getWebpackConfig(WebpackConfigTarget.CLIENT)!,
100
- });
101
-
102
- if (resolvedConfig.output.enableModernMode) {
103
- buildConfigs.push({
104
- type: 'modern',
105
- config: getWebpackConfig(WebpackConfigTarget.MODERN)!,
106
- });
107
- }
108
-
109
- if (isUseSSRBundle(resolvedConfig)) {
110
- buildConfigs.push({
111
- type: 'ssr',
112
- config: getWebpackConfig(WebpackConfigTarget.NODE)!,
113
- });
114
- }
115
-
116
- await (mountHook() as any).beforeBuild({
117
- webpackConfigs: buildConfigs.map(({ config }) => config),
118
- });
119
-
120
- for (const buildConfig of buildConfigs) {
121
- const { type: buildType, config } = buildConfig;
122
- try {
123
- await webpackBuild(config, buildType);
124
- } catch (error) {
125
- printBuildError(error as Error);
126
- }
127
- }
128
- await (mountHook() as any).afterBuild();
129
- };
@@ -1,6 +0,0 @@
1
- import { mountHook } from '@modern-js/core';
2
-
3
- export const deploy = async (options: any) => {
4
- await (mountHook() as any).beforeDeploy(options);
5
- await (mountHook() as any).afterDeploy(options);
6
- };
@@ -1,80 +0,0 @@
1
- import {
2
- Configuration,
3
- getWebpackConfig,
4
- WebpackConfigTarget,
5
- } from '@modern-js/webpack';
6
- import {
7
- fs,
8
- logger,
9
- HMR_SOCK_PATH,
10
- clearConsole,
11
- chalk,
12
- isSSR,
13
- } from '@modern-js/utils';
14
- import {
15
- useAppContext,
16
- useResolvedConfigContext,
17
- mountHook,
18
- } from '@modern-js/core';
19
- import { createCompiler } from '../utils/createCompiler';
20
- import { createServer } from '../utils/createServer';
21
-
22
- export const dev = async () => {
23
- /* eslint-disable react-hooks/rules-of-hooks */
24
- const appContext = useAppContext();
25
- const userConfig = useResolvedConfigContext();
26
- /* eslint-enable react-hooks/rules-of-hooks */
27
-
28
- const { appDirectory, distDirectory, port } = appContext;
29
-
30
- fs.emptyDirSync(distDirectory);
31
-
32
- await (mountHook() as any).beforeDev();
33
-
34
- const webpackConfigs = [
35
- isSSR(userConfig) && getWebpackConfig(WebpackConfigTarget.NODE),
36
- getWebpackConfig(WebpackConfigTarget.CLIENT),
37
- ].filter(Boolean) as Configuration[];
38
-
39
- const compiler = await createCompiler({
40
- webpackConfigs,
41
- userConfig,
42
- appContext,
43
- });
44
-
45
- const app = await createServer({
46
- dev: {
47
- ...{
48
- client: {
49
- port: port!.toString(),
50
- overlay: false,
51
- logging: 'none',
52
- path: HMR_SOCK_PATH,
53
- host: 'localhost',
54
- },
55
- dev: { writeToDisk: (file: string) => !file.includes('.hot-update.') },
56
- hot: true,
57
- liveReload: true,
58
- port,
59
- https: userConfig.dev.https,
60
- },
61
- ...userConfig.tools.devServer,
62
- },
63
- compiler,
64
- pwd: appDirectory,
65
- config: userConfig as any,
66
- plugins: appContext.plugins
67
- .filter((p: any) => p.server)
68
- .map((p: any) => p.server),
69
- });
70
-
71
- app.listen(port, (err: Error) => {
72
- if (err) {
73
- throw err;
74
- }
75
-
76
- clearConsole();
77
-
78
- logger.log(chalk.cyan(`Starting the development server...`));
79
- });
80
- };
@@ -1,3 +0,0 @@
1
- export * from './dev';
2
- export * from './build';
3
- export * from './start';
@@ -1,30 +0,0 @@
1
- import { logger, chalk } from '@modern-js/utils';
2
- import { useAppContext, useResolvedConfigContext } from '@modern-js/core';
3
- import server from '@modern-js/server';
4
- import { printInstructions } from '../utils/printInstructions';
5
-
6
- export const start = async () => {
7
- /* eslint-disable react-hooks/rules-of-hooks */
8
- const appContext = useAppContext();
9
- const userConfig = useResolvedConfigContext();
10
- /* eslint-enable react-hooks/rules-of-hooks */
11
-
12
- const { appDirectory, port } = appContext;
13
-
14
- logger.log(chalk.cyan(`Starting the modern server...`));
15
-
16
- const app = await server({
17
- pwd: appDirectory,
18
- config: userConfig as any,
19
- plugins: appContext.plugins
20
- .filter((p: any) => p.server)
21
- .map((p: any) => p.server),
22
- });
23
-
24
- app.listen(port, async (err: Error) => {
25
- if (err) {
26
- throw err;
27
- }
28
- await printInstructions(appContext, userConfig);
29
- });
30
- };