@modern-js/app-tools 1.2.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +100 -0
- package/dist/js/modern/commands/build.js +24 -8
- package/dist/js/modern/commands/dev.js +23 -10
- package/dist/js/modern/index.js +26 -4
- package/dist/js/modern/utils/createCompiler.js +2 -1
- package/dist/js/modern/utils/printInstructions.js +4 -1
- package/dist/js/modern/utils/routes.js +15 -0
- package/dist/js/node/commands/build.js +24 -7
- package/dist/js/node/commands/dev.js +25 -10
- package/dist/js/node/index.js +27 -3
- package/dist/js/node/utils/createCompiler.js +2 -1
- package/dist/js/node/utils/printInstructions.js +4 -1
- package/dist/js/node/utils/routes.js +25 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/utils/routes.d.ts +3 -0
- package/jest.config.js +8 -0
- package/package.json +27 -19
- package/tests/commands/build.test.ts +37 -0
- package/tests/commands/dev.test.ts +7 -0
- package/tests/index.test.ts +7 -0
- package/tests/routes.test.ts +27 -0
- package/tests/tsconfig.json +13 -0
- package/tsconfig.json +1 -3
- package/src/commands/build.ts +0 -129
- package/src/commands/deploy.ts +0 -6
- package/src/commands/dev.ts +0 -80
- package/src/commands/index.ts +0 -3
- package/src/commands/start.ts +0 -30
- package/src/index.ts +0 -100
- package/src/lifecycle.ts +0 -43
- package/src/locale/en.ts +0 -18
- package/src/locale/index.ts +0 -9
- package/src/locale/zh.ts +0 -18
- package/src/utils/createCompiler.ts +0 -80
- package/src/utils/createServer.ts +0 -16
- package/src/utils/language.ts +0 -6
- package/src/utils/printInstructions.ts +0 -25
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import webpack, { Configuration, StatsCompilation } from 'webpack';
|
|
2
|
-
import { IAppContext, NormalizedConfig, mountHook } from '@modern-js/core';
|
|
3
|
-
import {
|
|
4
|
-
chalk,
|
|
5
|
-
logger,
|
|
6
|
-
formatWebpackMessages,
|
|
7
|
-
clearConsole,
|
|
8
|
-
} from '@modern-js/utils';
|
|
9
|
-
import { printInstructions } from './printInstructions';
|
|
10
|
-
|
|
11
|
-
const prettyTime = (stats: StatsCompilation) =>
|
|
12
|
-
Math.max(...(stats.children?.map(child => child.time || 0) || []));
|
|
13
|
-
|
|
14
|
-
export const createCompiler = async ({
|
|
15
|
-
webpackConfigs,
|
|
16
|
-
// TODO: params
|
|
17
|
-
userConfig,
|
|
18
|
-
appContext,
|
|
19
|
-
}: {
|
|
20
|
-
webpackConfigs: Configuration[];
|
|
21
|
-
userConfig: NormalizedConfig;
|
|
22
|
-
appContext: IAppContext;
|
|
23
|
-
}) => {
|
|
24
|
-
try {
|
|
25
|
-
await (mountHook() as any).beforeCreateCompiler({ webpackConfigs });
|
|
26
|
-
const compiler = webpack(webpackConfigs);
|
|
27
|
-
|
|
28
|
-
await (mountHook() as any).afterCreateCompiler({ compiler });
|
|
29
|
-
|
|
30
|
-
let isFirstCompile = true;
|
|
31
|
-
|
|
32
|
-
compiler.hooks.invalid.tap('invalid', () => {
|
|
33
|
-
clearConsole();
|
|
34
|
-
logger.log('Compiling...');
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
compiler.hooks.done.tap('done', async (stats: any) => {
|
|
38
|
-
clearConsole();
|
|
39
|
-
|
|
40
|
-
const statsData = stats.toJson({
|
|
41
|
-
all: false,
|
|
42
|
-
warnings: true,
|
|
43
|
-
errors: true,
|
|
44
|
-
timings: true,
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
const { errors, warnings } = formatWebpackMessages(statsData);
|
|
48
|
-
|
|
49
|
-
if (errors.length) {
|
|
50
|
-
logger.log(chalk.red(`Failed to compile.\n`));
|
|
51
|
-
logger.log(errors.join('\n\n'));
|
|
52
|
-
logger.log();
|
|
53
|
-
} else if (process.stdout.isTTY || isFirstCompile) {
|
|
54
|
-
await (mountHook() as any).afterDev();
|
|
55
|
-
if (warnings.length) {
|
|
56
|
-
logger.log(chalk.yellow(`Compiled with warnings.\n`));
|
|
57
|
-
logger.log(warnings.join('\n\n'));
|
|
58
|
-
logger.log();
|
|
59
|
-
} else {
|
|
60
|
-
logger.log(
|
|
61
|
-
chalk.green(
|
|
62
|
-
`Compiled successfully in ${prettyTime(statsData)} ms.\n`,
|
|
63
|
-
),
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
await printInstructions(appContext, userConfig);
|
|
67
|
-
}
|
|
68
|
-
// eslint-disable-next-line require-atomic-updates
|
|
69
|
-
isFirstCompile = false;
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
return compiler;
|
|
73
|
-
} catch (err) {
|
|
74
|
-
logger.log(chalk.red(`Failed to compile.`));
|
|
75
|
-
logger.log();
|
|
76
|
-
logger.log(err as any);
|
|
77
|
-
// eslint-disable-next-line no-process-exit
|
|
78
|
-
process.exit(1);
|
|
79
|
-
}
|
|
80
|
-
};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Server, ModernServerOptions } from '@modern-js/server';
|
|
2
|
-
|
|
3
|
-
let server: Server;
|
|
4
|
-
|
|
5
|
-
export const createServer = async (options: ModernServerOptions) => {
|
|
6
|
-
if (server) {
|
|
7
|
-
await server.close();
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
// eslint-disable-next-line require-atomic-updates
|
|
11
|
-
server = new Server(options);
|
|
12
|
-
|
|
13
|
-
const app = await server.init();
|
|
14
|
-
|
|
15
|
-
return app;
|
|
16
|
-
};
|
package/src/utils/language.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { prettyInstructions, logger, isDev, chalk } from '@modern-js/utils';
|
|
2
|
-
import { mountHook, IAppContext, NormalizedConfig } from '@modern-js/core';
|
|
3
|
-
|
|
4
|
-
export const printInstructions = async (
|
|
5
|
-
appContext: IAppContext,
|
|
6
|
-
config: NormalizedConfig,
|
|
7
|
-
) => {
|
|
8
|
-
let message = prettyInstructions(appContext, config);
|
|
9
|
-
|
|
10
|
-
if (isDev()) {
|
|
11
|
-
message += `\n${chalk.cyanBright(
|
|
12
|
-
[
|
|
13
|
-
`Note that the development build is not optimized.`,
|
|
14
|
-
`To create a production build, execute build command.`,
|
|
15
|
-
].join('\n'),
|
|
16
|
-
)}`;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// call beforePrintInstructions hook.
|
|
20
|
-
const { instructions } = await (mountHook() as any).beforePrintInstructions({
|
|
21
|
-
instructions: message,
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
logger.log(instructions);
|
|
25
|
-
};
|