@modern-js/plugin-docsite 1.1.3 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +48 -0
- package/dist/js/modern/build-task.js +4 -2
- package/dist/js/modern/features/index.js +2 -1
- package/dist/js/modern/index.js +6 -2
- package/dist/js/node/build-task.js +4 -2
- package/dist/js/node/features/index.js +2 -1
- package/dist/js/node/index.js +6 -2
- package/dist/types/features/index.d.ts +2 -0
- package/dist/types/index.d.ts +2 -0
- package/jest.config.js +8 -0
- package/package.json +17 -11
- package/tests/index.test.ts +7 -0
- package/tests/tsconfig.json +13 -0
- package/tsconfig.json +1 -3
- package/src/build-task.ts +0 -35
- package/src/features/build.ts +0 -31
- package/src/features/constant.ts +0 -8
- package/src/features/dev.ts +0 -37
- package/src/features/index.ts +0 -68
- package/src/features/utils/chokidar.ts +0 -44
- package/src/features/utils/generate-files.ts +0 -238
- package/src/features/utils/valid.ts +0 -23
- package/src/features/utils/webpack.ts +0 -114
- package/src/index.ts +0 -42
- package/src/type.d.ts +0 -4
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,53 @@
|
|
1
1
|
# @modern-js/plugin-docsite
|
2
2
|
|
3
|
+
## 1.2.2
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- 24f616ca: feat: support custom meta info
|
8
|
+
- Updated dependencies [d9cc5ea9]
|
9
|
+
- Updated dependencies [ddf0c3a6]
|
10
|
+
- Updated dependencies [bd819a8d]
|
11
|
+
- Updated dependencies [ec4dbffb]
|
12
|
+
- Updated dependencies [d099e5c5]
|
13
|
+
- Updated dependencies [bada2879]
|
14
|
+
- Updated dependencies [24f616ca]
|
15
|
+
- Updated dependencies [bd819a8d]
|
16
|
+
- @modern-js/core@1.4.0
|
17
|
+
- @modern-js/webpack@1.3.0
|
18
|
+
- @modern-js/utils@1.3.0
|
19
|
+
|
20
|
+
## 1.2.1
|
21
|
+
|
22
|
+
### Patch Changes
|
23
|
+
|
24
|
+
- 83166714: change .npmignore
|
25
|
+
- Updated dependencies [83166714]
|
26
|
+
- Updated dependencies [c3de9882]
|
27
|
+
- Updated dependencies [33ff48af]
|
28
|
+
- @modern-js/core@1.3.2
|
29
|
+
- @modern-js/webpack@1.2.1
|
30
|
+
- @modern-js/utils@1.2.2
|
31
|
+
|
32
|
+
## 1.2.0
|
33
|
+
|
34
|
+
### Minor Changes
|
35
|
+
|
36
|
+
- cfe11628: Make Modern.js self bootstraping
|
37
|
+
|
38
|
+
### Patch Changes
|
39
|
+
|
40
|
+
- Updated dependencies [2da09c69]
|
41
|
+
- Updated dependencies [5597289b]
|
42
|
+
- Updated dependencies [fc71e36f]
|
43
|
+
- Updated dependencies [4a85378c]
|
44
|
+
- Updated dependencies [e453e421]
|
45
|
+
- Updated dependencies [c3d46ee4]
|
46
|
+
- Updated dependencies [cfe11628]
|
47
|
+
- @modern-js/utils@1.2.0
|
48
|
+
- @modern-js/webpack@1.2.0
|
49
|
+
- @modern-js/core@1.3.0
|
50
|
+
|
3
51
|
## 1.1.3
|
4
52
|
|
5
53
|
### Patch Changes
|
@@ -8,6 +8,7 @@ const glob = Import.lazy('glob', require);
|
|
8
8
|
const DEFAULT_PORT = 5000;
|
9
9
|
export async function buildDocs({
|
10
10
|
appDirectory,
|
11
|
+
internalDirectory,
|
11
12
|
isDev = false,
|
12
13
|
port = DEFAULT_PORT
|
13
14
|
}) {
|
@@ -34,7 +35,7 @@ export async function buildDocs({
|
|
34
35
|
return;
|
35
36
|
}
|
36
37
|
|
37
|
-
const tmpDir = path.join(
|
38
|
+
const tmpDir = path.join(internalDirectory, './docs');
|
38
39
|
fs.ensureDirSync(tmpDir);
|
39
40
|
const finalWebpackConfig = wp.generatorWebpackConfig(appDirectory, tmpDir, isDev);
|
40
41
|
|
package/dist/js/modern/index.js
CHANGED
@@ -6,7 +6,8 @@ export default core.createPlugin(() => ({
|
|
6
6
|
program
|
7
7
|
}) {
|
8
8
|
const {
|
9
|
-
appDirectory
|
9
|
+
appDirectory,
|
10
|
+
internalDirectory
|
10
11
|
} = core.useAppContext();
|
11
12
|
const devCommand = program.commandsMap.get('dev');
|
12
13
|
|
@@ -14,6 +15,7 @@ export default core.createPlugin(() => ({
|
|
14
15
|
devCommand.command('docs').action(async () => {
|
15
16
|
await features.buildDocs({
|
16
17
|
appDirectory,
|
18
|
+
internalDirectory,
|
17
19
|
isDev: true
|
18
20
|
});
|
19
21
|
});
|
@@ -23,13 +25,15 @@ export default core.createPlugin(() => ({
|
|
23
25
|
// module-tools menu mode
|
24
26
|
moduleToolsMenu() {
|
25
27
|
const {
|
26
|
-
appDirectory
|
28
|
+
appDirectory,
|
29
|
+
internalDirectory
|
27
30
|
} = core.useAppContext();
|
28
31
|
return {
|
29
32
|
name: 'Docsite 调试',
|
30
33
|
value: 'docsite',
|
31
34
|
runTask: async () => features.buildDocs({
|
32
35
|
appDirectory,
|
36
|
+
internalDirectory,
|
33
37
|
isDev: true
|
34
38
|
})
|
35
39
|
};
|
@@ -25,6 +25,7 @@ const DEFAULT_PORT = 5000;
|
|
25
25
|
|
26
26
|
async function buildDocs({
|
27
27
|
appDirectory,
|
28
|
+
internalDirectory,
|
28
29
|
isDev = false,
|
29
30
|
port = DEFAULT_PORT
|
30
31
|
}) {
|
@@ -52,7 +53,7 @@ async function buildDocs({
|
|
52
53
|
return;
|
53
54
|
}
|
54
55
|
|
55
|
-
const tmpDir = _path.default.join(
|
56
|
+
const tmpDir = _path.default.join(internalDirectory, './docs');
|
56
57
|
|
57
58
|
_utils.fs.ensureDirSync(tmpDir);
|
58
59
|
|
package/dist/js/node/index.js
CHANGED
@@ -16,7 +16,8 @@ var _default = core.createPlugin(() => ({
|
|
16
16
|
program
|
17
17
|
}) {
|
18
18
|
const {
|
19
|
-
appDirectory
|
19
|
+
appDirectory,
|
20
|
+
internalDirectory
|
20
21
|
} = core.useAppContext();
|
21
22
|
const devCommand = program.commandsMap.get('dev');
|
22
23
|
|
@@ -24,6 +25,7 @@ var _default = core.createPlugin(() => ({
|
|
24
25
|
devCommand.command('docs').action(async () => {
|
25
26
|
await features.buildDocs({
|
26
27
|
appDirectory,
|
28
|
+
internalDirectory,
|
27
29
|
isDev: true
|
28
30
|
});
|
29
31
|
});
|
@@ -33,13 +35,15 @@ var _default = core.createPlugin(() => ({
|
|
33
35
|
// module-tools menu mode
|
34
36
|
moduleToolsMenu() {
|
35
37
|
const {
|
36
|
-
appDirectory
|
38
|
+
appDirectory,
|
39
|
+
internalDirectory
|
37
40
|
} = core.useAppContext();
|
38
41
|
return {
|
39
42
|
name: 'Docsite 调试',
|
40
43
|
value: 'docsite',
|
41
44
|
runTask: async () => features.buildDocs({
|
42
45
|
appDirectory,
|
46
|
+
internalDirectory,
|
43
47
|
isDev: true
|
44
48
|
})
|
45
49
|
};
|
@@ -1,12 +1,14 @@
|
|
1
1
|
import type { Configuration } from 'webpack';
|
2
2
|
interface IBuildDocsParams {
|
3
3
|
appDirectory: string;
|
4
|
+
internalDirectory: string;
|
4
5
|
webpackConfig?: Configuration;
|
5
6
|
isDev?: boolean;
|
6
7
|
port?: number;
|
7
8
|
}
|
8
9
|
export declare function buildDocs({
|
9
10
|
appDirectory,
|
11
|
+
internalDirectory,
|
10
12
|
isDev,
|
11
13
|
port
|
12
14
|
}: IBuildDocsParams): Promise<void>;
|
package/dist/types/index.d.ts
CHANGED
@@ -11,8 +11,10 @@ declare const _default: import("@modern-js/core").AsyncPlugin<Partial<import("@m
|
|
11
11
|
watchFiles: import("@modern-js/core").ParallelWorkflow<void, unknown>;
|
12
12
|
fileChange: import("@modern-js/core").AsyncWorkflow<{
|
13
13
|
filename: string;
|
14
|
+
eventType: "add" | "unlink" | "change";
|
14
15
|
}, void>;
|
15
16
|
beforeExit: import("@modern-js/core").AsyncWorkflow<void, void>;
|
17
|
+
beforeRestart: import("@modern-js/core").AsyncWorkflow<void, void>;
|
16
18
|
} & import("@modern-js/core").ClearDraftProgress<import("@modern-js/core").Hooks>>>>;
|
17
19
|
|
18
20
|
export default _default;
|
package/jest.config.js
ADDED
package/package.json
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
"modern",
|
12
12
|
"modern.js"
|
13
13
|
],
|
14
|
-
"version": "1.
|
14
|
+
"version": "1.2.2",
|
15
15
|
"jsnext:source": "./src/index.ts",
|
16
16
|
"types": "./dist/types/index.d.ts",
|
17
17
|
"main": "./dist/js/node/index.js",
|
@@ -20,12 +20,16 @@
|
|
20
20
|
"exports": {
|
21
21
|
".": {
|
22
22
|
"node": {
|
23
|
+
"jsnext:source": "./src/index.ts",
|
23
24
|
"import": "./dist/js/modern/index.js",
|
24
25
|
"require": "./dist/js/node/index.js"
|
25
26
|
},
|
26
27
|
"default": "./dist/js/treeshaking/index.js"
|
27
28
|
},
|
28
|
-
"./cli":
|
29
|
+
"./cli": {
|
30
|
+
"jsnext:source": "./src/index.ts",
|
31
|
+
"default": "./dist/js/node/index.js"
|
32
|
+
},
|
29
33
|
"./package.json": "./package.json"
|
30
34
|
},
|
31
35
|
"dependencies": {
|
@@ -33,8 +37,8 @@
|
|
33
37
|
"@babel/runtime": "^7",
|
34
38
|
"@mdx-js/mdx": "^1.6.22",
|
35
39
|
"@mdx-js/react": "^1.6.22",
|
36
|
-
"@modern-js/utils": "^1.
|
37
|
-
"@modern-js/webpack": "^1.
|
40
|
+
"@modern-js/utils": "^1.3.0",
|
41
|
+
"@modern-js/webpack": "^1.3.0",
|
38
42
|
"antd": "^4.16.13",
|
39
43
|
"chokidar": "^3.5.2",
|
40
44
|
"core-js": "^3.17.2",
|
@@ -58,7 +62,7 @@
|
|
58
62
|
"webpack-dev-server": "^4.1.1"
|
59
63
|
},
|
60
64
|
"devDependencies": {
|
61
|
-
"@modern-js/module-tools-hooks": "^1.
|
65
|
+
"@modern-js/module-tools-hooks": "^1.2.1",
|
62
66
|
"@types/core-js": "^2.5.5",
|
63
67
|
"@types/github-slugger": "^1.3.0",
|
64
68
|
"@types/glob": "^7.1.4",
|
@@ -69,12 +73,13 @@
|
|
69
73
|
"@types/react-dom": "^17",
|
70
74
|
"@types/webpack-dev-server": "^4.1.0",
|
71
75
|
"typescript": "^4",
|
72
|
-
"@modern-js/core": "^1.
|
73
|
-
"@
|
74
|
-
"
|
76
|
+
"@modern-js/core": "^1.4.0",
|
77
|
+
"@scripts/build": "0.0.0",
|
78
|
+
"jest": "^27",
|
79
|
+
"@scripts/jest-config": "0.0.0"
|
75
80
|
},
|
76
81
|
"peerDependencies": {
|
77
|
-
"@modern-js/core": "^1.
|
82
|
+
"@modern-js/core": "^1.4.0"
|
78
83
|
},
|
79
84
|
"sideEffects": false,
|
80
85
|
"modernConfig": {
|
@@ -90,12 +95,13 @@
|
|
90
95
|
},
|
91
96
|
"publishConfig": {
|
92
97
|
"registry": "https://registry.npmjs.org/",
|
93
|
-
"access": "public"
|
98
|
+
"access": "public",
|
99
|
+
"types": "./dist/types/index.d.ts"
|
94
100
|
},
|
95
101
|
"scripts": {
|
96
102
|
"new": "modern new",
|
97
103
|
"build": "modern build",
|
98
|
-
"test": "
|
104
|
+
"test": "jest --passWithNoTests"
|
99
105
|
},
|
100
106
|
"readme": "\n<p align=\"center\">\n <a href=\"https://modernjs.dev\" target=\"blank\"><img src=\"https://lf3-static.bytednsdoc.com/obj/eden-cn/ylaelkeh7nuhfnuhf/modernjs-cover.png\" width=\"300\" alt=\"Modern.js Logo\" /></a>\n</p>\n<p align=\"center\">\n现代 Web 工程体系\n <br/>\n <a href=\"https://modernjs.dev\" target=\"blank\">\n modernjs.dev\n </a>\n</p>\n<p align=\"center\">\n The meta-framework suite designed from scratch for frontend-focused modern web development\n</p>\n\n# Introduction\n\n> The doc site ([modernjs.dev](https://modernjs.dev)) and articles are only available in Chinese for now, we are planning to add English versions soon.\n\n- [Modern.js: Hello, World!](https://zhuanlan.zhihu.com/p/426707646)\n\n## Getting Started\n\n- [Quick Start](https://modernjs.dev/docs/start)\n- [Guides](https://modernjs.dev/docs/guides)\n- [API References](https://modernjs.dev/docs/apis)\n\n## Contributing\n\n- [Contributing Guide](https://github.com/modern-js-dev/modern.js/blob/main/CONTRIBUTING.md)\n"
|
101
107
|
}
|
@@ -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
|
+
}
|
package/tsconfig.json
CHANGED
package/src/build-task.ts
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
import type { IAppContext, CoreOptions } from '@modern-js/core';
|
2
|
-
import { Import } from '@modern-js/utils';
|
3
|
-
|
4
|
-
const core: typeof import('@modern-js/core') = Import.lazy(
|
5
|
-
'@modern-js/core',
|
6
|
-
require,
|
7
|
-
);
|
8
|
-
const features: typeof import('./features') = Import.lazy(
|
9
|
-
'./features',
|
10
|
-
require,
|
11
|
-
);
|
12
|
-
|
13
|
-
interface IBuildTaskOption {
|
14
|
-
appContext: IAppContext;
|
15
|
-
}
|
16
|
-
|
17
|
-
const taskMain = async ({ appContext }: IBuildTaskOption) => {
|
18
|
-
const { appDirectory } = appContext;
|
19
|
-
await features.buildDocs({ appDirectory });
|
20
|
-
};
|
21
|
-
|
22
|
-
(async () => {
|
23
|
-
let options: CoreOptions | undefined;
|
24
|
-
if (process.env.CORE_INIT_OPTION_FILE) {
|
25
|
-
({ options } = require(process.env.CORE_INIT_OPTION_FILE));
|
26
|
-
}
|
27
|
-
const { appContext } = await core.cli.init([], options);
|
28
|
-
await core.manager.run(async () => {
|
29
|
-
try {
|
30
|
-
await taskMain({ appContext });
|
31
|
-
} catch (e: any) {
|
32
|
-
console.error(e.message);
|
33
|
-
}
|
34
|
-
});
|
35
|
-
})();
|
package/src/features/build.ts
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
import { logger, Import, chalk } from '@modern-js/utils';
|
2
|
-
import type { Configuration } from 'webpack';
|
3
|
-
|
4
|
-
const wp: typeof import('./utils/webpack') = Import.lazy(
|
5
|
-
'./utils/webpack',
|
6
|
-
require,
|
7
|
-
);
|
8
|
-
const gen: typeof import('./utils/generate-files') = Import.lazy(
|
9
|
-
'./utils/generate-files',
|
10
|
-
require,
|
11
|
-
);
|
12
|
-
|
13
|
-
// eslint-disable-next-line max-params
|
14
|
-
export async function build(
|
15
|
-
appDirectory: string,
|
16
|
-
tmpDir: string,
|
17
|
-
files: string[],
|
18
|
-
webpackConfig: Configuration,
|
19
|
-
isDev: boolean,
|
20
|
-
) {
|
21
|
-
const meta = await gen.generateFiles(appDirectory, tmpDir, files, isDev);
|
22
|
-
try {
|
23
|
-
await wp.runWebpack(webpackConfig);
|
24
|
-
logger.log(chalk.green('build docs successful'));
|
25
|
-
return meta;
|
26
|
-
} catch (err: any) {
|
27
|
-
logger.error('failed to build docs');
|
28
|
-
logger.error(err);
|
29
|
-
return null;
|
30
|
-
}
|
31
|
-
}
|
package/src/features/constant.ts
DELETED
package/src/features/dev.ts
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
import path from 'path';
|
2
|
-
import { logger } from '@modern-js/utils';
|
3
|
-
import webpack, { Configuration } from 'webpack';
|
4
|
-
import WebpackDevServer from 'webpack-dev-server';
|
5
|
-
import { chokidarFile } from './utils/chokidar';
|
6
|
-
import { generateFiles } from './utils/generate-files';
|
7
|
-
|
8
|
-
// eslint-disable-next-line max-params
|
9
|
-
export async function dev(
|
10
|
-
appDirectory: string,
|
11
|
-
tmpDir: string,
|
12
|
-
files: string[],
|
13
|
-
webpackConfig: Configuration,
|
14
|
-
isDev: boolean,
|
15
|
-
port: number,
|
16
|
-
) {
|
17
|
-
await generateFiles(appDirectory, tmpDir, files, isDev);
|
18
|
-
const compiler = webpack(webpackConfig);
|
19
|
-
const server = new WebpackDevServer(
|
20
|
-
{
|
21
|
-
host: '0.0.0.0',
|
22
|
-
port,
|
23
|
-
historyApiFallback: true,
|
24
|
-
static: {
|
25
|
-
directory: path.resolve(appDirectory, 'assets'),
|
26
|
-
publicPath: '/assets',
|
27
|
-
},
|
28
|
-
} as WebpackDevServer.Configuration,
|
29
|
-
compiler as any,
|
30
|
-
);
|
31
|
-
|
32
|
-
server.startCallback(() => {
|
33
|
-
logger.info(`Starting server on http://localhost:${port}`);
|
34
|
-
});
|
35
|
-
|
36
|
-
chokidarFile(appDirectory, tmpDir, isDev);
|
37
|
-
}
|
package/src/features/index.ts
DELETED
@@ -1,68 +0,0 @@
|
|
1
|
-
import path from 'path';
|
2
|
-
import { fs, Import, logger } from '@modern-js/utils';
|
3
|
-
import type { Configuration } from 'webpack';
|
4
|
-
import { valid } from './utils/valid';
|
5
|
-
|
6
|
-
const buildFeat: typeof import('./build') = Import.lazy('./build', require);
|
7
|
-
const devFeat: typeof import('./dev') = Import.lazy('./dev', require);
|
8
|
-
const wp: typeof import('./utils/webpack') = Import.lazy(
|
9
|
-
'./utils/webpack',
|
10
|
-
require,
|
11
|
-
);
|
12
|
-
const glob: typeof import('glob') = Import.lazy('glob', require);
|
13
|
-
|
14
|
-
const DEFAULT_PORT = 5000;
|
15
|
-
|
16
|
-
interface IBuildDocsParams {
|
17
|
-
appDirectory: string;
|
18
|
-
webpackConfig?: Configuration;
|
19
|
-
isDev?: boolean;
|
20
|
-
port?: number;
|
21
|
-
}
|
22
|
-
export async function buildDocs({
|
23
|
-
appDirectory,
|
24
|
-
isDev = false,
|
25
|
-
port = DEFAULT_PORT,
|
26
|
-
}: IBuildDocsParams) {
|
27
|
-
if (!valid({ appDirectory, docsDir: 'docs' })) {
|
28
|
-
return;
|
29
|
-
}
|
30
|
-
const docsDir = path.resolve(appDirectory, 'docs');
|
31
|
-
if (!fs.pathExistsSync(docsDir)) {
|
32
|
-
return;
|
33
|
-
}
|
34
|
-
const files = glob.sync('**/*.{md,mdx}', {
|
35
|
-
cwd: docsDir,
|
36
|
-
ignore: '**/_*',
|
37
|
-
});
|
38
|
-
if (files.length === 0) {
|
39
|
-
logger.warn('not find md(x) files');
|
40
|
-
return;
|
41
|
-
}
|
42
|
-
const tmpDir = path.join(appDirectory, './node_modules/.modern-js/docs');
|
43
|
-
fs.ensureDirSync(tmpDir);
|
44
|
-
const finalWebpackConfig = wp.generatorWebpackConfig(
|
45
|
-
appDirectory,
|
46
|
-
tmpDir,
|
47
|
-
isDev,
|
48
|
-
);
|
49
|
-
if (!isDev) {
|
50
|
-
logger.info('build docs');
|
51
|
-
await buildFeat.build(
|
52
|
-
appDirectory,
|
53
|
-
tmpDir,
|
54
|
-
files,
|
55
|
-
finalWebpackConfig,
|
56
|
-
false,
|
57
|
-
);
|
58
|
-
} else {
|
59
|
-
await devFeat.dev(
|
60
|
-
appDirectory,
|
61
|
-
tmpDir,
|
62
|
-
files,
|
63
|
-
finalWebpackConfig,
|
64
|
-
true,
|
65
|
-
port,
|
66
|
-
);
|
67
|
-
}
|
68
|
-
}
|
@@ -1,44 +0,0 @@
|
|
1
|
-
import path from 'path';
|
2
|
-
import { logger } from '@modern-js/utils';
|
3
|
-
import chokidar from 'chokidar';
|
4
|
-
import glob from 'glob';
|
5
|
-
import { generateFiles } from './generate-files';
|
6
|
-
|
7
|
-
export function chokidarFile(
|
8
|
-
appDirectory: string,
|
9
|
-
tmpDir: string,
|
10
|
-
isDev: boolean,
|
11
|
-
) {
|
12
|
-
let dirty = false;
|
13
|
-
let building = false;
|
14
|
-
chokidar
|
15
|
-
.watch('docs/**/*.{md,mdx}', {
|
16
|
-
cwd: appDirectory,
|
17
|
-
ignoreInitial: true,
|
18
|
-
})
|
19
|
-
.on('all', async () => {
|
20
|
-
if (building) {
|
21
|
-
dirty = true;
|
22
|
-
} else {
|
23
|
-
building = true;
|
24
|
-
dirty = false;
|
25
|
-
|
26
|
-
logger.info('changed, collect and rebuild docs');
|
27
|
-
const files = glob.sync('**/*.{md,mdx}', {
|
28
|
-
cwd: path.resolve(appDirectory, 'docs'),
|
29
|
-
ignore: '**/_*',
|
30
|
-
});
|
31
|
-
|
32
|
-
if (files.length) {
|
33
|
-
await generateFiles(appDirectory, tmpDir, files, isDev);
|
34
|
-
logger.info('built');
|
35
|
-
}
|
36
|
-
// eslint-disable-next-line require-atomic-updates
|
37
|
-
building = false;
|
38
|
-
|
39
|
-
if (dirty) {
|
40
|
-
await generateFiles(appDirectory, tmpDir, files, isDev);
|
41
|
-
}
|
42
|
-
}
|
43
|
-
});
|
44
|
-
}
|
@@ -1,238 +0,0 @@
|
|
1
|
-
import path from 'path';
|
2
|
-
import { logger, fs } from '@modern-js/utils';
|
3
|
-
import matter from 'gray-matter';
|
4
|
-
import { startCase, camelCase, union, template, difference } from 'lodash';
|
5
|
-
import GithubSlugger from 'github-slugger';
|
6
|
-
import sortPaths from 'sort-paths';
|
7
|
-
import visit from 'unist-util-visit';
|
8
|
-
import toString from 'mdast-util-to-string';
|
9
|
-
import u from 'unist-builder';
|
10
|
-
import mdx from '@mdx-js/mdx';
|
11
|
-
import babelParser, { ParserOptions } from '@babel/parser';
|
12
|
-
import {
|
13
|
-
DOCS_RENDER_PATH,
|
14
|
-
MDX_DEFAULT_RENDERER,
|
15
|
-
UTILS_STATIC,
|
16
|
-
} from '../constant';
|
17
|
-
|
18
|
-
const loadTemplate = async (file: string, customPath = false) => {
|
19
|
-
let result = '';
|
20
|
-
if (customPath) {
|
21
|
-
result = await fs.readFile(file, 'utf-8');
|
22
|
-
} else {
|
23
|
-
result = await fs.readFile(path.join(UTILS_STATIC, file), 'utf-8');
|
24
|
-
}
|
25
|
-
|
26
|
-
return template(result, { interpolate: /<%=([\s\S]+?)%>/g });
|
27
|
-
};
|
28
|
-
|
29
|
-
interface Node {
|
30
|
-
value?: string;
|
31
|
-
type: string;
|
32
|
-
depth?: number;
|
33
|
-
url?: string;
|
34
|
-
data?: {
|
35
|
-
hProperties: {
|
36
|
-
id: string;
|
37
|
-
};
|
38
|
-
};
|
39
|
-
children?: Node[];
|
40
|
-
}
|
41
|
-
|
42
|
-
// eslint-disable-next-line max-statements
|
43
|
-
async function handleFile(
|
44
|
-
appDirectory: string,
|
45
|
-
tmpDir: string,
|
46
|
-
file: string,
|
47
|
-
images: string[],
|
48
|
-
) {
|
49
|
-
const moduleName = file.replace(/\.(md|mdx)$/, '');
|
50
|
-
const content = await fs.readFile(path.resolve(appDirectory, 'docs', file));
|
51
|
-
const parsed = matter(content);
|
52
|
-
if (!parsed.data.title) {
|
53
|
-
parsed.data.title = startCase(camelCase(path.basename(moduleName)));
|
54
|
-
}
|
55
|
-
|
56
|
-
const slugger = new GithubSlugger();
|
57
|
-
slugger.reset();
|
58
|
-
|
59
|
-
const babelOptions: ParserOptions = {
|
60
|
-
allowUndeclaredExports: true,
|
61
|
-
sourceType: 'module',
|
62
|
-
};
|
63
|
-
const imported: { id: string; node: any }[] = [];
|
64
|
-
const exported: { id: string; node: any }[] = [];
|
65
|
-
const toc: { slug: string; text: string }[] = [];
|
66
|
-
|
67
|
-
const modifier = () => (tree: any) => {
|
68
|
-
visit<Node>(tree, 'import', node => {
|
69
|
-
const parsedNode = babelParser.parse(node.value!, babelOptions);
|
70
|
-
const nodes = parsedNode.program.body;
|
71
|
-
nodes.forEach((n: any) => {
|
72
|
-
if (n.type === 'ImportDeclaration') {
|
73
|
-
n.specifiers.forEach((sp: any) => {
|
74
|
-
imported.push({
|
75
|
-
id: sp.local.name,
|
76
|
-
node,
|
77
|
-
});
|
78
|
-
});
|
79
|
-
}
|
80
|
-
});
|
81
|
-
});
|
82
|
-
visit<Node>(tree, 'export', node => {
|
83
|
-
const parsedNode = babelParser.parse(node.value!, babelOptions);
|
84
|
-
const nodes = parsedNode.program.body;
|
85
|
-
nodes.forEach((n: any) => {
|
86
|
-
if (n.type === 'ExportNamedDeclaration') {
|
87
|
-
n.specifiers.forEach((sp: any) => {
|
88
|
-
exported.push({
|
89
|
-
id: sp.exported.name,
|
90
|
-
node,
|
91
|
-
});
|
92
|
-
});
|
93
|
-
}
|
94
|
-
});
|
95
|
-
});
|
96
|
-
const extraImported = difference(
|
97
|
-
imported.map(n => n.id),
|
98
|
-
exported.map(n => n.id),
|
99
|
-
);
|
100
|
-
// we have to put the export statement with the import,
|
101
|
-
// otherwise the mdx's babel transformer cannot found
|
102
|
-
// the corresponding imports
|
103
|
-
extraImported.forEach(id => {
|
104
|
-
const { node } = imported.find(n => n.id === id)!;
|
105
|
-
node.value += `\nexport { ${id} };`;
|
106
|
-
});
|
107
|
-
visit<Node>(tree, 'heading', node => {
|
108
|
-
if (node.depth === 2) {
|
109
|
-
const slug = slugger.slug(toString(node));
|
110
|
-
node.data = { hProperties: { id: slug } };
|
111
|
-
toc.push({
|
112
|
-
slug,
|
113
|
-
text: toString(node),
|
114
|
-
});
|
115
|
-
}
|
116
|
-
});
|
117
|
-
visit<Node>(tree, 'root', node => {
|
118
|
-
(node.children || []).unshift(
|
119
|
-
u('heading', {
|
120
|
-
depth: 1,
|
121
|
-
children: [u('text', { value: parsed.data.title })],
|
122
|
-
}),
|
123
|
-
);
|
124
|
-
});
|
125
|
-
visit<Node>(tree, 'image', node => {
|
126
|
-
const { url } = node;
|
127
|
-
if (!url!.startsWith('http')) {
|
128
|
-
const fullPath = path.resolve(
|
129
|
-
path.dirname(path.resolve(appDirectory, 'docs', file)),
|
130
|
-
url!,
|
131
|
-
);
|
132
|
-
const relativePath = path.relative(
|
133
|
-
path.resolve(appDirectory, 'assets'),
|
134
|
-
fullPath,
|
135
|
-
);
|
136
|
-
if (relativePath.startsWith('..')) {
|
137
|
-
logger.warn(
|
138
|
-
`${url!} referenced in ${file} is not under the "assets" folder`,
|
139
|
-
);
|
140
|
-
} else {
|
141
|
-
images.push(relativePath);
|
142
|
-
node.url = `/${path.relative(
|
143
|
-
path.dirname(path.resolve(appDirectory, 'docs', file)),
|
144
|
-
path.resolve(appDirectory, 'docs/assets', relativePath),
|
145
|
-
)}`;
|
146
|
-
}
|
147
|
-
}
|
148
|
-
});
|
149
|
-
};
|
150
|
-
|
151
|
-
const transpiled = await mdx(parsed.content, { remarkPlugins: [modifier] });
|
152
|
-
const totalExported = union(
|
153
|
-
imported.map(n => n.id),
|
154
|
-
exported.map(n => n.id),
|
155
|
-
);
|
156
|
-
const outputFile = path.resolve(tmpDir, `${moduleName}/mdx.jsx`);
|
157
|
-
await fs.outputFile(outputFile, MDX_DEFAULT_RENDERER + transpiled, {
|
158
|
-
encoding: 'utf8',
|
159
|
-
});
|
160
|
-
|
161
|
-
const pageFile = path.resolve(tmpDir, `${moduleName}/index.jsx`);
|
162
|
-
const pageTemplate = await loadTemplate('docs-page.jsx.tpl');
|
163
|
-
const pageContent = pageTemplate({
|
164
|
-
moduleName,
|
165
|
-
toc: JSON.stringify(toc),
|
166
|
-
relRoot: path.relative(path.dirname(outputFile), tmpDir),
|
167
|
-
imports: totalExported.length
|
168
|
-
? `import { ${totalExported.join(', ')} } from './mdx';`
|
169
|
-
: '',
|
170
|
-
imported: totalExported.join(','),
|
171
|
-
});
|
172
|
-
await fs.outputFile(pageFile, pageContent, { encoding: 'utf8' });
|
173
|
-
return {
|
174
|
-
...parsed.data,
|
175
|
-
moduleName,
|
176
|
-
pageFile,
|
177
|
-
};
|
178
|
-
}
|
179
|
-
export async function generateFiles(
|
180
|
-
appDirectory: string,
|
181
|
-
tmpDir: string,
|
182
|
-
files: string[],
|
183
|
-
isDev: boolean,
|
184
|
-
) {
|
185
|
-
await fs.remove(tmpDir);
|
186
|
-
await fs.ensureDir(tmpDir);
|
187
|
-
const images: string[] = [];
|
188
|
-
|
189
|
-
const meta = await Promise.all(
|
190
|
-
files.map(file => handleFile(appDirectory, tmpDir, file, images)),
|
191
|
-
);
|
192
|
-
const sorted: { moduleName: string; title: string }[] = sortPaths(
|
193
|
-
meta,
|
194
|
-
(e: { moduleName: string; title: string }) =>
|
195
|
-
e.moduleName.endsWith('index')
|
196
|
-
? e.moduleName.replace(/index$/, '')
|
197
|
-
: `${e.moduleName}/`,
|
198
|
-
'/',
|
199
|
-
);
|
200
|
-
const routesTemplate = await loadTemplate('DocsRoutes.jsx.tpl');
|
201
|
-
await fs.outputFile(
|
202
|
-
path.resolve(tmpDir, 'DocsRoutes.jsx'),
|
203
|
-
routesTemplate({ meta: sorted }),
|
204
|
-
);
|
205
|
-
const pkgInfo = await fs.readJson(path.resolve(appDirectory, 'package.json'));
|
206
|
-
const entryTemplate = await loadTemplate('docs-entry.jsx.tpl');
|
207
|
-
await fs.outputFile(
|
208
|
-
path.resolve(tmpDir, 'docs-entry.jsx'),
|
209
|
-
entryTemplate({
|
210
|
-
basename: isDev
|
211
|
-
? '/'
|
212
|
-
: `${DOCS_RENDER_PATH}/${pkgInfo.name}/${pkgInfo.version}`,
|
213
|
-
}),
|
214
|
-
);
|
215
|
-
await Promise.all(
|
216
|
-
['DocsNav.jsx.tpl', 'DocsToc.jsx.tpl', 'docs.css'].map(async file =>
|
217
|
-
fs.copyFile(
|
218
|
-
path.resolve(UTILS_STATIC, file),
|
219
|
-
path.resolve(tmpDir, file.replace('.tpl', '')),
|
220
|
-
),
|
221
|
-
),
|
222
|
-
);
|
223
|
-
await fs.outputJson(
|
224
|
-
path.resolve(tmpDir, 'meta.json'),
|
225
|
-
sorted.map(({ title, moduleName }) => ({ title, moduleName })),
|
226
|
-
{ spaces: 2 },
|
227
|
-
);
|
228
|
-
await fs.ensureDir(path.resolve(appDirectory, 'dist/docs/assets'));
|
229
|
-
await Promise.all(
|
230
|
-
Array.from(new Set(images)).map(file =>
|
231
|
-
fs.copyFile(
|
232
|
-
path.resolve(appDirectory, 'assets', file),
|
233
|
-
path.resolve(appDirectory, 'dist/docs/assets', file),
|
234
|
-
),
|
235
|
-
),
|
236
|
-
);
|
237
|
-
return sorted;
|
238
|
-
}
|
@@ -1,23 +0,0 @@
|
|
1
|
-
import path from 'path';
|
2
|
-
import * as glob from 'glob';
|
3
|
-
import { chalk, fs } from '@modern-js/utils';
|
4
|
-
|
5
|
-
interface ValidOption {
|
6
|
-
appDirectory: string;
|
7
|
-
docsDir: string;
|
8
|
-
}
|
9
|
-
|
10
|
-
export const valid = ({ appDirectory, docsDir }: ValidOption) => {
|
11
|
-
const docsAbsPath = path.join(appDirectory, docsDir);
|
12
|
-
const files: string[] = glob.sync(`${docsAbsPath}/**/*.{md,mdx}`);
|
13
|
-
if (!fs.existsSync(docsAbsPath) || files.length <= 0) {
|
14
|
-
console.info(
|
15
|
-
chalk.yellow(
|
16
|
-
'No docs found, create directory "./docs" and add md(x) files',
|
17
|
-
),
|
18
|
-
);
|
19
|
-
return false;
|
20
|
-
}
|
21
|
-
|
22
|
-
return true;
|
23
|
-
};
|
@@ -1,114 +0,0 @@
|
|
1
|
-
import path from 'path';
|
2
|
-
import { fs } from '@modern-js/utils';
|
3
|
-
import HtmlWebpackPlugin from 'html-webpack-plugin';
|
4
|
-
import webpack, { Configuration, WebpackPluginInstance } from 'webpack';
|
5
|
-
import { getWebpackConfig, WebpackConfigTarget } from '@modern-js/webpack';
|
6
|
-
import { UTILS_STATIC } from '../constant';
|
7
|
-
|
8
|
-
interface Alias {
|
9
|
-
[index: string]: string | false | string[];
|
10
|
-
}
|
11
|
-
|
12
|
-
export function generatorWebpackConfig(
|
13
|
-
appDirectory: string,
|
14
|
-
tmpDir: string,
|
15
|
-
isDev: boolean,
|
16
|
-
): Configuration {
|
17
|
-
const originConfig: any = getWebpackConfig(WebpackConfigTarget.CLIENT);
|
18
|
-
const plugins = (
|
19
|
-
(originConfig.plugins || []) as WebpackPluginInstance[]
|
20
|
-
).filter(p => p.constructor !== webpack.HotModuleReplacementPlugin);
|
21
|
-
const config: Configuration = {
|
22
|
-
mode: isDev ? 'development' : 'production',
|
23
|
-
context: tmpDir,
|
24
|
-
entry: { index: path.resolve(tmpDir, 'docs-entry.jsx') },
|
25
|
-
output: { path: path.resolve(appDirectory, 'dist/docs') },
|
26
|
-
resolve: originConfig.resolve || { alias: {} },
|
27
|
-
module: originConfig.module,
|
28
|
-
plugins: [
|
29
|
-
...plugins,
|
30
|
-
new HtmlWebpackPlugin({
|
31
|
-
templateContent: fs.readFileSync(
|
32
|
-
path.resolve(UTILS_STATIC, 'index.html.ejs'),
|
33
|
-
'utf8',
|
34
|
-
),
|
35
|
-
}),
|
36
|
-
],
|
37
|
-
};
|
38
|
-
const docsiteNodeModules = [
|
39
|
-
// for yarn
|
40
|
-
path.dirname(require.resolve('@modern-js/plugin-docsite/package.json')),
|
41
|
-
// for pnpm
|
42
|
-
path.resolve(
|
43
|
-
path.dirname(require.resolve('@modern-js/plugin-docsite/package.json')),
|
44
|
-
'../..',
|
45
|
-
),
|
46
|
-
];
|
47
|
-
|
48
|
-
// maybe check if outside appDir or monorepoDir
|
49
|
-
config.resolve!.modules = [
|
50
|
-
...(config.resolve!.modules || []),
|
51
|
-
...docsiteNodeModules,
|
52
|
-
];
|
53
|
-
(config.resolve!.alias as Alias)['@assets'] = path.resolve(
|
54
|
-
appDirectory,
|
55
|
-
'assets',
|
56
|
-
);
|
57
|
-
(config.resolve!.alias as Alias)['@styles'] = path.resolve(
|
58
|
-
appDirectory,
|
59
|
-
'styles',
|
60
|
-
);
|
61
|
-
// fix this since react-live relies on core-js@2
|
62
|
-
(config.resolve!.alias as Alias)[
|
63
|
-
`${path.dirname(require.resolve('core-js'))}/fn`
|
64
|
-
] = 'core-js/es';
|
65
|
-
|
66
|
-
// const pkgJSON = JSON.parse(
|
67
|
-
// fs.readFileSync(path.join(appDirectory, 'package.json'), 'utf-8'),
|
68
|
-
// );
|
69
|
-
|
70
|
-
// if (pkgJSON.dependencies.react || pkgJSON.devDependencies.react) {
|
71
|
-
// (config.resolve!.alias as Alias).react = path.resolve('node_modules/react');
|
72
|
-
// } else {
|
73
|
-
// (config.resolve!.alias as Alias).react = path.resolve(
|
74
|
-
// __dirname,
|
75
|
-
// '../../../../../',
|
76
|
-
// 'node_modules',
|
77
|
-
// 'react',
|
78
|
-
// );
|
79
|
-
// }
|
80
|
-
// if (
|
81
|
-
// pkgJSON.dependencies['react-dom'] ||
|
82
|
-
// pkgJSON.devDependencies['react-dom']
|
83
|
-
// ) {
|
84
|
-
// (config.resolve!.alias as Alias)['react-dom'] = path.resolve(
|
85
|
-
// 'node_modules/react-dom',
|
86
|
-
// );
|
87
|
-
// } else {
|
88
|
-
// (config.resolve!.alias as Alias)['react-dom'] = path.resolve(
|
89
|
-
// __dirname,
|
90
|
-
// '../../../../../',
|
91
|
-
// 'node_modules',
|
92
|
-
// 'react-dom',
|
93
|
-
// );
|
94
|
-
// }
|
95
|
-
|
96
|
-
config.resolve!.fallback = {
|
97
|
-
path: require.resolve('path-browserify'),
|
98
|
-
};
|
99
|
-
return config;
|
100
|
-
}
|
101
|
-
|
102
|
-
export async function runWebpack(config: Configuration) {
|
103
|
-
await new Promise((resolve, reject) => {
|
104
|
-
webpack(config).run((err, stats) => {
|
105
|
-
if (err) {
|
106
|
-
reject(err);
|
107
|
-
} else if (stats?.hasErrors()) {
|
108
|
-
reject(stats?.compilation.errors);
|
109
|
-
} else {
|
110
|
-
resolve(stats);
|
111
|
-
}
|
112
|
-
});
|
113
|
-
});
|
114
|
-
}
|
package/src/index.ts
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
import { Import } from '@modern-js/utils';
|
2
|
-
|
3
|
-
const core: typeof import('@modern-js/core') = Import.lazy(
|
4
|
-
'@modern-js/core',
|
5
|
-
require,
|
6
|
-
);
|
7
|
-
const features: typeof import('./features') = Import.lazy(
|
8
|
-
'./features',
|
9
|
-
require,
|
10
|
-
);
|
11
|
-
|
12
|
-
export default core.createPlugin(
|
13
|
-
() => ({
|
14
|
-
commands({ program }: any) {
|
15
|
-
const { appDirectory } = core.useAppContext();
|
16
|
-
const devCommand = program.commandsMap.get('dev');
|
17
|
-
if (devCommand) {
|
18
|
-
devCommand.command('docs').action(async () => {
|
19
|
-
await features.buildDocs({ appDirectory, isDev: true });
|
20
|
-
});
|
21
|
-
}
|
22
|
-
},
|
23
|
-
// module-tools menu mode
|
24
|
-
moduleToolsMenu() {
|
25
|
-
const { appDirectory } = core.useAppContext();
|
26
|
-
return {
|
27
|
-
name: 'Docsite 调试',
|
28
|
-
value: 'docsite',
|
29
|
-
runTask: async () => features.buildDocs({ appDirectory, isDev: true }),
|
30
|
-
};
|
31
|
-
},
|
32
|
-
platformBuild() {
|
33
|
-
return {
|
34
|
-
name: 'docsite',
|
35
|
-
title: 'Run Docsite log',
|
36
|
-
taskPath: require.resolve('./build-task'),
|
37
|
-
params: [],
|
38
|
-
};
|
39
|
-
},
|
40
|
-
}),
|
41
|
-
{ name: '@modern-js/plugin-docsite' },
|
42
|
-
);
|
package/src/type.d.ts
DELETED