@modern-js/plugin-docsite 1.1.3-rc.0 → 1.2.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.
package/CHANGELOG.md CHANGED
@@ -1,19 +1,49 @@
1
1
  # @modern-js/plugin-docsite
2
2
 
3
- ## 1.1.3-rc.0
3
+ ## 1.2.1
4
4
 
5
5
  ### Patch Changes
6
6
 
7
- - Updated dependencies [d927bc83]
8
- - Updated dependencies [d73ff455]
9
- - Updated dependencies [9c1ab865]
10
- - Updated dependencies [d73ff455]
11
- - Updated dependencies [d73ff455]
12
- - Updated dependencies [d73ff455]
13
- - Updated dependencies [d73ff455]
14
- - @modern-js/utils@1.1.4-rc.0
15
- - @modern-js/core@1.1.4-rc.0
16
- - @modern-js/webpack@1.1.4-rc.0
7
+ - 83166714: change .npmignore
8
+ - Updated dependencies [83166714]
9
+ - Updated dependencies [c3de9882]
10
+ - Updated dependencies [33ff48af]
11
+ - @modern-js/core@1.3.2
12
+ - @modern-js/webpack@1.2.1
13
+ - @modern-js/utils@1.2.2
14
+
15
+ ## 1.2.0
16
+
17
+ ### Minor Changes
18
+
19
+ - cfe11628: Make Modern.js self bootstraping
20
+
21
+ ### Patch Changes
22
+
23
+ - Updated dependencies [2da09c69]
24
+ - Updated dependencies [5597289b]
25
+ - Updated dependencies [fc71e36f]
26
+ - Updated dependencies [4a85378c]
27
+ - Updated dependencies [e453e421]
28
+ - Updated dependencies [c3d46ee4]
29
+ - Updated dependencies [cfe11628]
30
+ - @modern-js/utils@1.2.0
31
+ - @modern-js/webpack@1.2.0
32
+ - @modern-js/core@1.3.0
33
+
34
+ ## 1.1.3
35
+
36
+ ### Patch Changes
37
+
38
+ - ca7dcb32: add CORE_INIT_OPTION_FILE env
39
+ - Updated dependencies [90eeb72c]
40
+ - Updated dependencies [e04914ce]
41
+ - Updated dependencies [5a4c557e]
42
+ - Updated dependencies [e04914ce]
43
+ - Updated dependencies [ca7dcb32]
44
+ - Updated dependencies [ecb344dc]
45
+ - @modern-js/core@1.2.0
46
+ - @modern-js/utils@1.1.5
17
47
 
18
48
  ## 1.1.2
19
49
 
@@ -14,9 +14,17 @@ const taskMain = async ({
14
14
  };
15
15
 
16
16
  (async () => {
17
+ let options;
18
+
19
+ if (process.env.CORE_INIT_OPTION_FILE) {
20
+ ({
21
+ options
22
+ } = require(process.env.CORE_INIT_OPTION_FILE));
23
+ }
24
+
17
25
  const {
18
26
  appContext
19
- } = await core.cli.init();
27
+ } = await core.cli.init([], options);
20
28
  await core.manager.run(async () => {
21
29
  try {
22
30
  await taskMain({
@@ -18,9 +18,17 @@ const taskMain = async ({
18
18
  };
19
19
 
20
20
  (async () => {
21
+ let options;
22
+
23
+ if (process.env.CORE_INIT_OPTION_FILE) {
24
+ ({
25
+ options
26
+ } = require(process.env.CORE_INIT_OPTION_FILE));
27
+ }
28
+
21
29
  const {
22
30
  appContext
23
- } = await core.cli.init();
31
+ } = await core.cli.init([], options);
24
32
  await core.manager.run(async () => {
25
33
  try {
26
34
  await taskMain({
package/jest.config.js ADDED
@@ -0,0 +1,8 @@
1
+ const sharedConfig = require('@scripts/jest-config');
2
+
3
+ /** @type {import('@jest/types').Config.InitialOptions} */
4
+ module.exports = {
5
+ // eslint-disable-next-line node/no-unsupported-features/es-syntax
6
+ ...sharedConfig,
7
+ rootDir: __dirname,
8
+ };
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.1.3-rc.0",
14
+ "version": "1.2.1",
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": "./dist/js/node/index.js",
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.1.4-rc.0",
37
- "@modern-js/webpack": "^1.1.4-rc.0",
40
+ "@modern-js/utils": "^1.2.2",
41
+ "@modern-js/webpack": "^1.2.1",
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.1.2-rc.0",
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.1.4-rc.0",
73
- "@modern-js/plugin-testing": "^1.1.1",
74
- "@modern-js/module-tools": "^1.1.1"
76
+ "@modern-js/core": "^1.3.2",
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.1.4-rc.0"
82
+ "@modern-js/core": "^1.3.2"
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": "modern test --passWithNoTests"
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,7 @@
1
+ import plugin from '../src';
2
+
3
+ describe('plugin-docset', () => {
4
+ it('default', () => {
5
+ expect(plugin).toBeDefined();
6
+ });
7
+ });
package/tsconfig.json CHANGED
@@ -5,9 +5,7 @@
5
5
  "jsx": "preserve",
6
6
  "baseUrl": "./",
7
7
  "isolatedModules": true,
8
- "paths": {
9
- "@/*": ["./src/*"]
10
- }
8
+ "paths": {}
11
9
  },
12
10
  "include": ["src"]
13
11
  }
package/src/build-task.ts DELETED
@@ -1,31 +0,0 @@
1
- import type { IAppContext } 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
- const { appContext } = await core.cli.init();
24
- await core.manager.run(async () => {
25
- try {
26
- await taskMain({ appContext });
27
- } catch (e: any) {
28
- console.error(e.message);
29
- }
30
- });
31
- })();
@@ -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
- }
@@ -1,8 +0,0 @@
1
- import path from 'path';
2
-
3
- export const UTILS_STATIC = path.join(__dirname, '../../static');
4
- export const DOCS_RENDER_PATH = '/api/v1/docs/render';
5
- export const MDX_DEFAULT_RENDERER = `
6
- import React from 'react'
7
- import { mdx } from '@mdx-js/react'
8
- `;
@@ -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
- }
@@ -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
@@ -1,4 +0,0 @@
1
- /// <reference types="@modern-js/module-tools-hooks" />
2
- declare module 'find-node-modules';
3
- declare module '@mdx-js/mdx';
4
- declare module 'sort-paths';