@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.
@@ -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
- };
@@ -1,6 +0,0 @@
1
- import { I18CLILanguageDetector } from '@modern-js/i18n-cli-language-detector';
2
-
3
- export function getLocaleLanguage() {
4
- const detector = new I18CLILanguageDetector();
5
- return detector.detect();
6
- }
@@ -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
- };