@modern-js/plugin-docsite 0.0.0-bundle-deps-202110123508

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 (67) hide show
  1. package/CHANGELOG.md +342 -0
  2. package/LICENSE +21 -0
  3. package/README.md +30 -0
  4. package/dist/js/modern/build-task.js +29 -0
  5. package/dist/js/modern/features/build.js +17 -0
  6. package/dist/js/modern/features/constant.js +7 -0
  7. package/dist/js/modern/features/dev.js +24 -0
  8. package/dist/js/modern/features/index.js +47 -0
  9. package/dist/js/modern/features/utils/chokidar.js +37 -0
  10. package/dist/js/modern/features/utils/generate-files.js +197 -0
  11. package/dist/js/modern/features/utils/valid.js +17 -0
  12. package/dist/js/modern/features/utils/webpack.js +63 -0
  13. package/dist/js/modern/index.js +49 -0
  14. package/dist/js/node/build-task.js +33 -0
  15. package/dist/js/node/features/build.js +31 -0
  16. package/dist/js/node/features/constant.js +21 -0
  17. package/dist/js/node/features/dev.js +39 -0
  18. package/dist/js/node/features/index.js +68 -0
  19. package/dist/js/node/features/utils/chokidar.js +55 -0
  20. package/dist/js/node/features/utils/generate-files.js +223 -0
  21. package/dist/js/node/features/utils/valid.js +36 -0
  22. package/dist/js/node/features/utils/webpack.js +80 -0
  23. package/dist/js/node/index.js +61 -0
  24. package/dist/js/static/DocsNav.jsx.tpl +42 -0
  25. package/dist/js/static/DocsRoutes.jsx.tpl +19 -0
  26. package/dist/js/static/DocsToc.jsx.tpl +20 -0
  27. package/dist/js/static/docs-entry.jsx.tpl +41 -0
  28. package/dist/js/static/docs-page.jsx.tpl +107 -0
  29. package/dist/js/static/docs.css +1008 -0
  30. package/dist/js/static/index.html.ejs +15 -0
  31. package/dist/js/static/stories-entry.ts.tpl +6 -0
  32. package/dist/js/static/storybook-config.js.tpl +32 -0
  33. package/dist/js/static/tsconfig.json +25 -0
  34. package/dist/types/build-task.d.ts +1 -0
  35. package/dist/types/features/build.d.ts +5 -0
  36. package/dist/types/features/constant.d.ts +3 -0
  37. package/dist/types/features/dev.d.ts +2 -0
  38. package/dist/types/features/index.d.ts +13 -0
  39. package/dist/types/features/utils/chokidar.d.ts +1 -0
  40. package/dist/types/features/utils/generate-files.d.ts +4 -0
  41. package/dist/types/features/utils/valid.d.ts +9 -0
  42. package/dist/types/features/utils/webpack.d.ts +3 -0
  43. package/dist/types/index.d.ts +15 -0
  44. package/modern.config.js +2 -0
  45. package/package.json +98 -0
  46. package/src/build-task.ts +31 -0
  47. package/src/features/build.ts +31 -0
  48. package/src/features/constant.ts +8 -0
  49. package/src/features/dev.ts +37 -0
  50. package/src/features/index.ts +68 -0
  51. package/src/features/utils/chokidar.ts +44 -0
  52. package/src/features/utils/generate-files.ts +238 -0
  53. package/src/features/utils/valid.ts +23 -0
  54. package/src/features/utils/webpack.ts +107 -0
  55. package/src/index.ts +42 -0
  56. package/src/type.d.ts +4 -0
  57. package/static/DocsNav.jsx.tpl +42 -0
  58. package/static/DocsRoutes.jsx.tpl +19 -0
  59. package/static/DocsToc.jsx.tpl +20 -0
  60. package/static/docs-entry.jsx.tpl +41 -0
  61. package/static/docs-page.jsx.tpl +107 -0
  62. package/static/docs.css +1008 -0
  63. package/static/index.html.ejs +15 -0
  64. package/static/stories-entry.ts.tpl +6 -0
  65. package/static/storybook-config.js.tpl +32 -0
  66. package/static/tsconfig.json +25 -0
  67. package/tsconfig.json +13 -0
@@ -0,0 +1,15 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <!-- <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" /> -->
6
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
7
+ <meta name="theme-color" content="#000000" />
8
+ <!-- <link rel="manifest" href="%PUBLIC_URL%/manifest.json" /> -->
9
+ <title>Docs</title>
10
+ </head>
11
+ <body>
12
+ <noscript>You need to enable JavaScript to run this app.</noscript>
13
+ <div id="root"></div>
14
+ </body>
15
+ </html>
@@ -0,0 +1,6 @@
1
+ <% _.forEach(entries, function(entry) { %>
2
+ import * as <%= entry.name %> from '<%= entry.path %>';
3
+ <% }) %>
4
+
5
+ export { <%= entries.map(({ name }) => name).join(', ') %> };
6
+
@@ -0,0 +1,32 @@
1
+ module.exports = {
2
+ stories: [
3
+ '<%= rootDir %>/stories/**/*.{js,jsx,ts,tsx}',
4
+ '<%= rootDir %>/src/**/*.stories.{js,jsx,ts,tsx}',
5
+ ],
6
+ addons: [
7
+ '@storybook/addon-actions',
8
+ '@storybook/addon-links',
9
+ {
10
+ name: '@storybook/addon-storysource',
11
+ options: {
12
+ rule: {
13
+ test: {
14
+ or: [
15
+ {
16
+ test: [/.stories.{js,ts}x?$/],
17
+ },
18
+ {
19
+ include: '<%= rootDir %>/stories',
20
+ },
21
+ ],
22
+ },
23
+ },
24
+ loaderOptions: {
25
+ parser: 'typescript',
26
+ prettierConfig: { printWidth: 80, singleQuote: false },
27
+ },
28
+ },
29
+ },
30
+ '@storybook/addon-viewport',
31
+ ],
32
+ };
@@ -0,0 +1,25 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es5",
4
+ "module": "esnext",
5
+ "baseUrl": "./",
6
+ "paths": {
7
+ "@*": ["./*"]
8
+ },
9
+ "lib": ["dom", "dom.iterable", "esnext"],
10
+ "allowJs": true,
11
+ "skipLibCheck": true,
12
+ "esModuleInterop": true,
13
+ "allowSyntheticDefaultImports": true,
14
+ "strict": true,
15
+ "noImplicitReturns": true,
16
+ "noUnusedLocals": true,
17
+ "noUnusedParameters": true,
18
+ "forceConsistentCasingInFileNames": true,
19
+ "moduleResolution": "node",
20
+ "resolveJsonModule": true,
21
+ "noEmit": true,
22
+ "jsx": "react"
23
+ },
24
+ "include": ["src"]
25
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ import type { Configuration } from '@modern-js/deps/compiled/webpack';
2
+ export declare function build(appDirectory: string, tmpDir: string, files: string[], webpackConfig: Configuration, isDev: boolean): Promise<{
3
+ moduleName: string;
4
+ title: string;
5
+ }[] | null>;
@@ -0,0 +1,3 @@
1
+ export declare const UTILS_STATIC: string;
2
+ export declare const DOCS_RENDER_PATH = "/api/v1/docs/render";
3
+ export declare const MDX_DEFAULT_RENDERER = "\nimport React from 'react'\nimport { mdx } from '@mdx-js/react'\n";
@@ -0,0 +1,2 @@
1
+ import { Configuration } from '@modern-js/deps/compiled/webpack';
2
+ export declare function dev(appDirectory: string, tmpDir: string, files: string[], webpackConfig: Configuration, isDev: boolean, port: number): Promise<void>;
@@ -0,0 +1,13 @@
1
+ import type { Configuration } from '@modern-js/deps/compiled/webpack';
2
+ interface IBuildDocsParams {
3
+ appDirectory: string;
4
+ webpackConfig?: Configuration;
5
+ isDev?: boolean;
6
+ port?: number;
7
+ }
8
+ export declare function buildDocs({
9
+ appDirectory,
10
+ isDev,
11
+ port
12
+ }: IBuildDocsParams): Promise<void>;
13
+ export {};
@@ -0,0 +1 @@
1
+ export declare function chokidarFile(appDirectory: string, tmpDir: string, isDev: boolean): void;
@@ -0,0 +1,4 @@
1
+ export declare function generateFiles(appDirectory: string, tmpDir: string, files: string[], isDev: boolean): Promise<{
2
+ moduleName: string;
3
+ title: string;
4
+ }[]>;
@@ -0,0 +1,9 @@
1
+ interface ValidOption {
2
+ appDirectory: string;
3
+ docsDir: string;
4
+ }
5
+ export declare const valid: ({
6
+ appDirectory,
7
+ docsDir
8
+ }: ValidOption) => boolean;
9
+ export {};
@@ -0,0 +1,3 @@
1
+ import { Configuration } from '@modern-js/deps/compiled/webpack';
2
+ export declare function generatorWebpackConfig(appDirectory: string, tmpDir: string, isDev: boolean): Configuration;
3
+ export declare function runWebpack(config: Configuration): Promise<void>;
@@ -0,0 +1,15 @@
1
+ declare const _default: import("@modern-js/core").AsyncPlugin<Partial<import("@modern-js/core").Progresses2Threads<{
2
+ config: import("@modern-js/core").ParallelWorkflow<void, unknown>;
3
+ validateSchema: import("@modern-js/core").ParallelWorkflow<void, unknown>;
4
+ prepare: import("@modern-js/core").AsyncWorkflow<void, void>;
5
+ commands: import("@modern-js/core").AsyncWorkflow<{
6
+ program: import("commander").Command;
7
+ }, void>;
8
+ watchFiles: import("@modern-js/core").ParallelWorkflow<void, unknown>;
9
+ fileChange: import("@modern-js/core").AsyncWorkflow<{
10
+ filename: string;
11
+ }, void>;
12
+ beforeExit: import("@modern-js/core").AsyncWorkflow<void, void>;
13
+ } & import("@modern-js/core").ClearDraftProgress<import("@modern-js/core").Hooks>>>>;
14
+
15
+ export default _default;
@@ -0,0 +1,2 @@
1
+ /** @type {import('@modern-js/module-tools').UserConfig} */
2
+ module.exports = {};
package/package.json ADDED
@@ -0,0 +1,98 @@
1
+ {
2
+ "name": "@modern-js/plugin-docsite",
3
+ "description": "The meta-framework suite designed from scratch for frontend-focused modern web development.",
4
+ "homepage": "https://modernjs.dev",
5
+ "bugs": "https://github.com/modern-js-dev/modern.js/issues",
6
+ "repository": "modern-js-dev/modern.js",
7
+ "license": "MIT",
8
+ "keywords": [
9
+ "react",
10
+ "framework",
11
+ "modern",
12
+ "modern.js"
13
+ ],
14
+ "version": "0.0.0-bundle-deps-202110123508",
15
+ "jsnext:source": "./src/index.ts",
16
+ "types": "./dist/types/index.d.ts",
17
+ "main": "./dist/js/node/index.js",
18
+ "module": "./dist/js/treeshaking/index.js",
19
+ "jsnext:modern": "./dist/js/modern/index.js",
20
+ "exports": {
21
+ ".": {
22
+ "node": {
23
+ "import": "./dist/js/modern/index.js",
24
+ "require": "./dist/js/node/index.js"
25
+ },
26
+ "default": "./dist/js/treeshaking/index.js"
27
+ },
28
+ "./cli": "./dist/js/node/index.js"
29
+ },
30
+ "dependencies": {
31
+ "@babel/parser": "^7.15.2",
32
+ "@babel/runtime": "^7",
33
+ "@mdx-js/mdx": "^1.6.22",
34
+ "@mdx-js/react": "^1.6.22",
35
+ "@modern-js/utils": "^0.0.0-bundle-deps-202110123508",
36
+ "@modern-js/webpack": "^0.0.0-bundle-deps-202110123508",
37
+ "antd": "^4.16.13",
38
+ "chokidar": "^3.5.2",
39
+ "core-js": "^3.17.2",
40
+ "github-slugger": "^1.4.0",
41
+ "glob": "^7.1.6",
42
+ "gray-matter": "^4.0.3",
43
+ "lodash": "^4.17.21",
44
+ "mdast-util-to-string": "^2.0.0",
45
+ "path-browserify": "^1.0.1",
46
+ "prism-react-renderer": "^1.2.1",
47
+ "react": "^17",
48
+ "react-dom": "^17",
49
+ "react-live": "^2.3.0",
50
+ "react-router-dom": "^5.3.0",
51
+ "sort-paths": "^1.1.1",
52
+ "styled-components": "^5.3.1",
53
+ "unist-builder": "^2.0.3",
54
+ "unist-util-visit": "^2.0.3",
55
+ "@modern-js/deps": "^0.0.0-bundle-deps-202110123508",
56
+ "webpack-dev-server": "^4.1.1"
57
+ },
58
+ "devDependencies": {
59
+ "@modern-js/module-tools-hooks": "^0.0.0-bundle-deps-202110123508",
60
+ "@types/core-js": "^2.5.5",
61
+ "@types/github-slugger": "^1.3.0",
62
+ "@types/glob": "^7.1.4",
63
+ "@types/jest": "^26",
64
+ "@types/lodash": "^4.14.168",
65
+ "@types/node": "^14",
66
+ "@types/react": "^17",
67
+ "@types/react-dom": "^17",
68
+ "@types/webpack-dev-server": "^4.1.0",
69
+ "typescript": "^4",
70
+ "@modern-js/core": "^0.0.0-bundle-deps-202110123508",
71
+ "@modern-js/plugin-testing": "^0.0.0-bundle-deps-202110123508",
72
+ "@modern-js/module-tools": "^0.0.0-bundle-deps-202110123508"
73
+ },
74
+ "peerDependencies": {
75
+ "@modern-js/core": "^0.0.0-bundle-deps-202110123508"
76
+ },
77
+ "sideEffects": false,
78
+ "modernConfig": {
79
+ "output": {
80
+ "packageMode": "node-js",
81
+ "copy": [
82
+ {
83
+ "from": "static",
84
+ "to": ""
85
+ }
86
+ ]
87
+ }
88
+ },
89
+ "publishConfig": {
90
+ "registry": "https://registry.npmjs.org/",
91
+ "access": "public"
92
+ },
93
+ "scripts": {
94
+ "new": "modern new",
95
+ "build": "modern build",
96
+ "test": "modern test --passWithNoTests"
97
+ }
98
+ }
@@ -0,0 +1,31 @@
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
+ })();
@@ -0,0 +1,31 @@
1
+ import { logger, Import, chalk } from '@modern-js/utils';
2
+ import type { Configuration } from '@modern-js/deps/compiled/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
+ }
@@ -0,0 +1,8 @@
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
+ `;
@@ -0,0 +1,37 @@
1
+ import path from 'path';
2
+ import { logger } from '@modern-js/utils';
3
+ import webpack, { Configuration } from '@modern-js/deps/compiled/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
+ }
@@ -0,0 +1,68 @@
1
+ import path from 'path';
2
+ import { fs, Import, logger } from '@modern-js/utils';
3
+ import type { Configuration } from '@modern-js/deps/compiled/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
+ }
@@ -0,0 +1,44 @@
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
+ }