@moneko/core 3.0.0-beta.102 → 3.0.0-beta.104
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/lib/app.js +22 -1
- package/lib/cleanup.js +19 -1
- package/lib/common/rem.js +5 -4
- package/lib/common.d.ts +1 -0
- package/lib/common.js +241 -2
- package/lib/coverage.js +30 -1
- package/lib/define.js +9 -1
- package/lib/docs.js +113 -1
- package/lib/done.js +12 -1
- package/lib/esm.js +7 -1
- package/lib/generate-api.js +330 -1
- package/lib/has-pkg.js +14 -1
- package/lib/html-add-entry-attr.js +24 -1
- package/lib/html-plugin-option.js +44 -1
- package/lib/index.js +3 -1
- package/lib/minify.js +46 -1
- package/lib/modifyVars.js +11 -1
- package/lib/module-federation.js +46 -1
- package/lib/module.config.js +211 -1
- package/lib/net.js +33 -1
- package/lib/object-listener.js +28 -1
- package/lib/process-env.js +65 -1
- package/lib/resolver-sync.js +21 -1
- package/lib/routes.js +187 -1
- package/lib/seo.js +39 -1
- package/lib/swcrc.js +105 -1
- package/lib/tsloader.config.js +25 -1
- package/lib/utils.js +49 -1
- package/lib/virtual-module-plugin.js +54 -1
- package/lib/virtual-modules.js +34 -4
- package/lib/webpack.common.d.ts +0 -1
- package/lib/webpack.common.js +216 -1
- package/lib/webpack.dev.js +93 -3
- package/lib/webpack.prod.js +67 -1
- package/lib/yarn-argv.js +9 -1
- package/package.json +3 -3
package/lib/module.config.js
CHANGED
|
@@ -1 +1,211 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { resolve } from 'path';
|
|
2
|
+
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
|
|
3
|
+
import svgToMiniDataURI from 'mini-svg-data-uri';
|
|
4
|
+
import { CONFIG, PUBLICPATH } from './common.js';
|
|
5
|
+
import { hasPkg } from './has-pkg.js';
|
|
6
|
+
import modifyVars from './modifyVars.js';
|
|
7
|
+
import { APPTYPE, DEV, FRAMEWORK, __dirname } from './process-env.js';
|
|
8
|
+
import swcOption from './swcrc.js';
|
|
9
|
+
import tsLoaderConfig from './tsloader.config.js';
|
|
10
|
+
import { resolveNodeModulesPath, resolveProgramPath } from './utils.js';
|
|
11
|
+
const cssAssetsPublicPath = APPTYPE === 'single-spa' ? PUBLICPATH : '../';
|
|
12
|
+
let styleLoader = {
|
|
13
|
+
loader: MiniCssExtractPlugin.loader,
|
|
14
|
+
options: {
|
|
15
|
+
publicPath: cssAssetsPublicPath !== '/' ? cssAssetsPublicPath : '../'
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
const postcssLoader = hasPkg('@moneko/postcss') && {
|
|
19
|
+
loader: 'postcss-loader',
|
|
20
|
+
options: {
|
|
21
|
+
postcssOptions: await import('@moneko/postcss')
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
if (DEV) {
|
|
25
|
+
styleLoader = 'style-loader';
|
|
26
|
+
}
|
|
27
|
+
const customCssModules = [
|
|
28
|
+
...CONFIG.cssModules,
|
|
29
|
+
`@moneko/${FRAMEWORK}`,
|
|
30
|
+
'neko-ui'
|
|
31
|
+
].map(resolveNodeModulesPath);
|
|
32
|
+
const styleResources = [
|
|
33
|
+
...[
|
|
34
|
+
'src/styles/variables/*.less',
|
|
35
|
+
'src/styles/mixins/*.less',
|
|
36
|
+
'site/styles/variables/*.less',
|
|
37
|
+
'site/styles/mixins/*.less'
|
|
38
|
+
].map(resolveProgramPath)
|
|
39
|
+
];
|
|
40
|
+
const entryResolveProgramPath = [
|
|
41
|
+
'components',
|
|
42
|
+
'example',
|
|
43
|
+
'mock',
|
|
44
|
+
'site',
|
|
45
|
+
'src'
|
|
46
|
+
].map(resolveProgramPath);
|
|
47
|
+
const lessLoaderRule = [
|
|
48
|
+
styleLoader,
|
|
49
|
+
{
|
|
50
|
+
loader: '@teamsupercell/typings-for-css-modules-loader',
|
|
51
|
+
options: {
|
|
52
|
+
verifyOnly: !DEV
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
loader: 'css-loader',
|
|
57
|
+
options: {
|
|
58
|
+
modules: {
|
|
59
|
+
auto: (resourcePath)=>{
|
|
60
|
+
for(let i = 0, len = customCssModules.length; i < len; i++){
|
|
61
|
+
if (resourcePath && resourcePath?.includes(customCssModules[i])) {
|
|
62
|
+
return /(.*(?<!\.global\.(le|c)ss)$)/i.test(resourcePath);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return /(^(?!.*node_modules))(.*(?<!\.global\.(le|c)ss)$)/i.test(resourcePath);
|
|
66
|
+
},
|
|
67
|
+
localIdentName: '[path][name]__[local]',
|
|
68
|
+
exportLocalsConvention: 'dashesOnly'
|
|
69
|
+
},
|
|
70
|
+
importLoaders: 2
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
postcssLoader,
|
|
74
|
+
'css-unicode-loader',
|
|
75
|
+
{
|
|
76
|
+
loader: 'less-loader',
|
|
77
|
+
options: {
|
|
78
|
+
sourceMap: !!CONFIG.sourceMap,
|
|
79
|
+
lessOptions: {
|
|
80
|
+
modifyVars: modifyVars,
|
|
81
|
+
javascriptEnabled: true
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
loader: 'style-resources-loader',
|
|
87
|
+
options: {
|
|
88
|
+
patterns: styleResources
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
].filter(Boolean);
|
|
92
|
+
const tsLoader = {
|
|
93
|
+
loader: CONFIG.compiler === 'tsc' ? 'ts-loader' : 'swc-loader',
|
|
94
|
+
options: CONFIG.compiler === 'tsc' ? tsLoaderConfig : swcOption(DEV)
|
|
95
|
+
};
|
|
96
|
+
const moduleOptions = {
|
|
97
|
+
rules: [
|
|
98
|
+
{
|
|
99
|
+
test: /\.mdx?$/,
|
|
100
|
+
include: [
|
|
101
|
+
resolveProgramPath('components')
|
|
102
|
+
],
|
|
103
|
+
exclude: [
|
|
104
|
+
/(.+)\/examples\/(.+).mdx?$/i
|
|
105
|
+
],
|
|
106
|
+
enforce: 'pre',
|
|
107
|
+
use: [
|
|
108
|
+
{
|
|
109
|
+
loader: resolve(__dirname, './loader/frontmatter.cjs')
|
|
110
|
+
}
|
|
111
|
+
]
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
oneOf: [
|
|
115
|
+
{
|
|
116
|
+
resourceQuery: /raw/,
|
|
117
|
+
type: 'asset/source'
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
test: /\.wasm$/,
|
|
121
|
+
type: 'webassembly/async'
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
test: /\.txt$/,
|
|
125
|
+
type: 'asset/source'
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
test: /\.(gif|png|jpe?g|ico|mp4)$/i,
|
|
129
|
+
type: 'asset',
|
|
130
|
+
dependency: {
|
|
131
|
+
not: [
|
|
132
|
+
'url'
|
|
133
|
+
]
|
|
134
|
+
},
|
|
135
|
+
generator: {
|
|
136
|
+
filename: 'assets/images/[name][ext][query]'
|
|
137
|
+
},
|
|
138
|
+
include: entryResolveProgramPath.concat(CONFIG.rulesInclude?.media?.map(resolveNodeModulesPath) || [])
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
test: /\.svg$/,
|
|
142
|
+
type: 'asset/inline',
|
|
143
|
+
generator: {
|
|
144
|
+
dataUrl: (content)=>svgToMiniDataURI(typeof content !== 'string' ? content.toString() : content)
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
test: /\.(eot|ttf|otf|woff(|2))$/,
|
|
149
|
+
type: 'asset',
|
|
150
|
+
generator: {
|
|
151
|
+
filename: 'assets/fonts/[name][ext][query]'
|
|
152
|
+
},
|
|
153
|
+
include: entryResolveProgramPath.concat(CONFIG.rulesInclude?.fonts?.map(resolveNodeModulesPath) || [])
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
test: /\.less$/,
|
|
157
|
+
use: lessLoaderRule,
|
|
158
|
+
include: entryResolveProgramPath.concat(CONFIG.rulesInclude?.less?.map(resolveNodeModulesPath) || [])
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
test: /\.css$/,
|
|
162
|
+
use: [
|
|
163
|
+
styleLoader,
|
|
164
|
+
'css-loader',
|
|
165
|
+
postcssLoader,
|
|
166
|
+
'css-unicode-loader'
|
|
167
|
+
].filter(Boolean),
|
|
168
|
+
include: entryResolveProgramPath.concat(CONFIG.rulesInclude?.css?.map(resolveNodeModulesPath) || [])
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
test: /\.(cj|mj|t|j)s(|x)$/,
|
|
172
|
+
use: [
|
|
173
|
+
...CONFIG.prefixJsLoader,
|
|
174
|
+
tsLoader
|
|
175
|
+
].filter(Boolean),
|
|
176
|
+
include: entryResolveProgramPath.concat(CONFIG.rulesInclude?.js?.map(resolveNodeModulesPath) || [])
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
test: /\.mdx?$/,
|
|
180
|
+
use: [
|
|
181
|
+
...CONFIG.prefixJsLoader,
|
|
182
|
+
tsLoader,
|
|
183
|
+
{
|
|
184
|
+
loader: '@mdx-js/loader',
|
|
185
|
+
options: CONFIG.mdx
|
|
186
|
+
}
|
|
187
|
+
].filter(Boolean),
|
|
188
|
+
include: entryResolveProgramPath,
|
|
189
|
+
exclude: [
|
|
190
|
+
/(.+)\/examples\/(.+).mdx?$/i
|
|
191
|
+
]
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
test: /\.mdx?$/,
|
|
195
|
+
type: 'asset/source',
|
|
196
|
+
include: [
|
|
197
|
+
/(.+)\/examples\/(.+).mdx?$/i
|
|
198
|
+
]
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
type: 'asset/source',
|
|
202
|
+
include: [
|
|
203
|
+
/(.+)\/examples\/(.+).*?$/i
|
|
204
|
+
]
|
|
205
|
+
}
|
|
206
|
+
]
|
|
207
|
+
},
|
|
208
|
+
...CONFIG.moduleRules
|
|
209
|
+
]
|
|
210
|
+
};
|
|
211
|
+
export default moduleOptions;
|
package/lib/net.js
CHANGED
|
@@ -1 +1,33 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { createConnection } from 'net';
|
|
2
|
+
import { networkInterfaces } from 'os';
|
|
3
|
+
import devServer from 'webpack-dev-server';
|
|
4
|
+
const { internalIPSync } = devServer;
|
|
5
|
+
export function getNetworkAdress() {
|
|
6
|
+
const interfaces = networkInterfaces();
|
|
7
|
+
for(const devName in interfaces){
|
|
8
|
+
if (Object.prototype.hasOwnProperty.call(interfaces, devName)) {
|
|
9
|
+
const iface = interfaces[devName];
|
|
10
|
+
for(let i = 0; i < iface.length; i++){
|
|
11
|
+
const alias = iface[i];
|
|
12
|
+
if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.address.startsWith('169.254') && !alias.internal) {
|
|
13
|
+
return alias.address;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export function getIPv4() {
|
|
20
|
+
return internalIPSync('v4');
|
|
21
|
+
}
|
|
22
|
+
export function getPort(start, end, host = '0.0.0.0') {
|
|
23
|
+
return new Promise((resolve)=>{
|
|
24
|
+
const tester = createConnection(start, host);
|
|
25
|
+
tester.on('connect', ()=>{
|
|
26
|
+
tester.destroy();
|
|
27
|
+
resolve(getPort(start + 1, end, host));
|
|
28
|
+
});
|
|
29
|
+
tester.on('error', ()=>{
|
|
30
|
+
resolve(start);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
}
|
package/lib/object-listener.js
CHANGED
|
@@ -1 +1,28 @@
|
|
|
1
|
-
export default function
|
|
1
|
+
export default function objectListener(initialData) {
|
|
2
|
+
const listeners = [];
|
|
3
|
+
function notifyListeners(target) {
|
|
4
|
+
listeners.forEach((callback)=>{
|
|
5
|
+
callback(target);
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
function listener(callback) {
|
|
9
|
+
listeners.push(callback);
|
|
10
|
+
return ()=>{
|
|
11
|
+
const index = listeners.indexOf(callback);
|
|
12
|
+
if (index !== -1) {
|
|
13
|
+
listeners.splice(index, 1);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
const data = new Proxy(initialData, {
|
|
18
|
+
set (target, property, value) {
|
|
19
|
+
target[property] = value;
|
|
20
|
+
notifyListeners(target);
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
return {
|
|
25
|
+
data,
|
|
26
|
+
listener
|
|
27
|
+
};
|
|
28
|
+
}
|
package/lib/process-env.js
CHANGED
|
@@ -1 +1,65 @@
|
|
|
1
|
-
import{existsSync
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync } from 'fs';
|
|
2
|
+
import { join } from 'path';
|
|
3
|
+
import url from 'url';
|
|
4
|
+
import { hasPkg } from './has-pkg.js';
|
|
5
|
+
import { resolveProgramPath } from './utils.js';
|
|
6
|
+
import yarnArgv from './yarn-argv.js';
|
|
7
|
+
export const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
|
|
8
|
+
export const APPTYPE = process.env.APPTYPE;
|
|
9
|
+
export const FRAMEWORK = process.env.FRAMEWORK;
|
|
10
|
+
export const isReact = FRAMEWORK === 'react';
|
|
11
|
+
export const isSolid = FRAMEWORK === 'solid-js';
|
|
12
|
+
export const jsxImportSource = {
|
|
13
|
+
react: 'react',
|
|
14
|
+
'solid-js': 'solid-js/h'
|
|
15
|
+
}[FRAMEWORK];
|
|
16
|
+
export const PROGRAMPATH = process.cwd();
|
|
17
|
+
export const PACKAGENAME = process.env.npm_package_name;
|
|
18
|
+
export const PACKAGEVERSION = process.env.npm_package_version;
|
|
19
|
+
const pkg = readFileSync(join(__dirname, '../package.json'), {
|
|
20
|
+
encoding: 'utf-8'
|
|
21
|
+
});
|
|
22
|
+
export const pkgName = JSON.parse(pkg).name;
|
|
23
|
+
export const DEV = process.env.NODE_ENV === 'development';
|
|
24
|
+
export const cacheDir = join(PROGRAMPATH, './node_modules/.cache/.mo/');
|
|
25
|
+
if (!existsSync(cacheDir)) {
|
|
26
|
+
mkdirSync(cacheDir, {
|
|
27
|
+
recursive: true
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
export const NODE_ENV = process.env.NODE_ENV;
|
|
31
|
+
export const CUSTOMCONFIG = process.env.npm_config_config || yarnArgv.config;
|
|
32
|
+
export let hasEslintConfig = !!Object.keys(process.env).filter((k)=>k.startsWith('npm_package_eslintConfig_')).length;
|
|
33
|
+
export let hasStylelintConfig = !!Object.keys(process.env).filter((k)=>k.startsWith('npm_package_stylelint_')).length;
|
|
34
|
+
export const hasAntd = hasPkg('antd');
|
|
35
|
+
export const programInfo = {
|
|
36
|
+
name: PACKAGENAME,
|
|
37
|
+
version: PACKAGEVERSION,
|
|
38
|
+
type: APPTYPE,
|
|
39
|
+
description: process.env.npm_package_description,
|
|
40
|
+
author: {
|
|
41
|
+
name: process.env.npm_package_author_name,
|
|
42
|
+
email: process.env.npm_package_author_email,
|
|
43
|
+
url: process.env.npm_package_author_url
|
|
44
|
+
},
|
|
45
|
+
repository: {
|
|
46
|
+
type: process.env.npm_package_repository_type,
|
|
47
|
+
url: process.env.npm_package_repository_url,
|
|
48
|
+
directory: process.env.npm_package_repository_directory
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
if (parseInt(process.versions.node) > 14) {
|
|
52
|
+
const ikpg = readFileSync(resolveProgramPath('package.json'), {
|
|
53
|
+
encoding: 'utf-8'
|
|
54
|
+
});
|
|
55
|
+
const { description , author , repository , eslintConfig , stylelint } = JSON.parse(ikpg);
|
|
56
|
+
programInfo.author = typeof author === 'string' ? {
|
|
57
|
+
name: author
|
|
58
|
+
} : author;
|
|
59
|
+
programInfo.repository = typeof author === 'string' ? {
|
|
60
|
+
url: repository
|
|
61
|
+
} : repository;
|
|
62
|
+
programInfo.description = description;
|
|
63
|
+
hasEslintConfig = !!eslintConfig;
|
|
64
|
+
hasStylelintConfig = !!stylelint;
|
|
65
|
+
}
|
package/lib/resolver-sync.js
CHANGED
|
@@ -1 +1,21 @@
|
|
|
1
|
-
import*as
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import enhancedResolve from 'enhanced-resolve';
|
|
3
|
+
const { CachedInputFileSystem , ResolverFactory } = enhancedResolve;
|
|
4
|
+
const resolverSync = ResolverFactory.createResolver({
|
|
5
|
+
fileSystem: new CachedInputFileSystem(fs, 4000),
|
|
6
|
+
conditionNames: [
|
|
7
|
+
'node'
|
|
8
|
+
],
|
|
9
|
+
extensions: [
|
|
10
|
+
'.js',
|
|
11
|
+
'.json',
|
|
12
|
+
'.node'
|
|
13
|
+
],
|
|
14
|
+
useSyncFileSystemCalls: true,
|
|
15
|
+
mainFields: [
|
|
16
|
+
'esm',
|
|
17
|
+
'module',
|
|
18
|
+
'main'
|
|
19
|
+
]
|
|
20
|
+
});
|
|
21
|
+
export default resolverSync;
|
package/lib/routes.js
CHANGED
|
@@ -1 +1,187 @@
|
|
|
1
|
-
|
|
1
|
+
import { readFileSync, readdirSync, statSync } from 'fs';
|
|
2
|
+
import { join, relative } from 'path';
|
|
3
|
+
import { watch } from 'chokidar';
|
|
4
|
+
import { load } from 'js-yaml';
|
|
5
|
+
import { hasCustomRouter } from './common.js';
|
|
6
|
+
import objectListener from './object-listener.js';
|
|
7
|
+
import { APPTYPE, FRAMEWORK, PROGRAMPATH } from './process-env.js';
|
|
8
|
+
const frontmatterRegex = /^---\n([\s\S]+?)\n---\n/;
|
|
9
|
+
function extractFrontmatter(md) {
|
|
10
|
+
const matches = md.match(frontmatterRegex);
|
|
11
|
+
return matches && matches[1] ? matches[1].trim() : null;
|
|
12
|
+
}
|
|
13
|
+
function extractCode(codeStr) {
|
|
14
|
+
const codes = {};
|
|
15
|
+
const regex = /```(.+?)\n([\s\S]*?)\n```/g;
|
|
16
|
+
let match;
|
|
17
|
+
while((match = regex.exec(codeStr)) !== null){
|
|
18
|
+
const [, language = 'jsx', source] = match;
|
|
19
|
+
const lang = language.split(' ').pop() || 'jsx';
|
|
20
|
+
codes[lang] = source.trim();
|
|
21
|
+
}
|
|
22
|
+
return Object.keys(codes).length ? codes : {
|
|
23
|
+
jsx: codeStr
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function getTree(directory, option) {
|
|
27
|
+
const { regex , alia , base =directory , outputSource } = option;
|
|
28
|
+
const files = readdirSync(directory);
|
|
29
|
+
return files.reduce((tree, file)=>{
|
|
30
|
+
const filePath = join(directory, file);
|
|
31
|
+
const stats = statSync(filePath);
|
|
32
|
+
if (stats.isDirectory()) {
|
|
33
|
+
const children = getTree(filePath, {
|
|
34
|
+
...option,
|
|
35
|
+
base
|
|
36
|
+
});
|
|
37
|
+
if (children.length > 0) {
|
|
38
|
+
const item = {};
|
|
39
|
+
const baseItem = {
|
|
40
|
+
path: file,
|
|
41
|
+
key: relative(base, filePath)
|
|
42
|
+
};
|
|
43
|
+
if (outputSource) {
|
|
44
|
+
Object.assign(item, {
|
|
45
|
+
children
|
|
46
|
+
});
|
|
47
|
+
} else {
|
|
48
|
+
const frist = children.splice(0, 1)[0];
|
|
49
|
+
if (children.length) {
|
|
50
|
+
Object.assign(item, {
|
|
51
|
+
children: [
|
|
52
|
+
{
|
|
53
|
+
...frist,
|
|
54
|
+
path: '/',
|
|
55
|
+
key: baseItem.key
|
|
56
|
+
},
|
|
57
|
+
...children
|
|
58
|
+
]
|
|
59
|
+
});
|
|
60
|
+
} else {
|
|
61
|
+
Object.assign(item, frist);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
tree.push(Object.assign(item, baseItem));
|
|
65
|
+
}
|
|
66
|
+
} else if (regex.test(filePath)) {
|
|
67
|
+
const source = readFileSync(filePath, {
|
|
68
|
+
encoding: 'utf-8'
|
|
69
|
+
});
|
|
70
|
+
const frontmatter = extractFrontmatter(source);
|
|
71
|
+
const meta = frontmatter ? load(frontmatter) : {};
|
|
72
|
+
const reslove = relative(base, filePath);
|
|
73
|
+
tree.push(Object.assign({
|
|
74
|
+
path: file,
|
|
75
|
+
key: reslove,
|
|
76
|
+
meta: {
|
|
77
|
+
...meta
|
|
78
|
+
}
|
|
79
|
+
}, alia && {
|
|
80
|
+
component: `rr(() => import(/* webpackChunkName: '${reslove}' */'${join(alia, reslove)}'))rr`
|
|
81
|
+
}, outputSource && {
|
|
82
|
+
codes: extractCode(source.replace(frontmatterRegex, '').replace(/^\n+|\n+$/g, ''))
|
|
83
|
+
}));
|
|
84
|
+
}
|
|
85
|
+
return tree;
|
|
86
|
+
}, []);
|
|
87
|
+
}
|
|
88
|
+
const compPath = join(PROGRAMPATH, './components');
|
|
89
|
+
export const route = objectListener({
|
|
90
|
+
name: '@app/routes',
|
|
91
|
+
data: 'export default []'
|
|
92
|
+
});
|
|
93
|
+
export const example = objectListener({
|
|
94
|
+
name: '@app/example',
|
|
95
|
+
data: {}
|
|
96
|
+
});
|
|
97
|
+
const createElement = {
|
|
98
|
+
react: 'createElement',
|
|
99
|
+
'solid-js': 'createComponent'
|
|
100
|
+
}[FRAMEWORK];
|
|
101
|
+
let replaceStr = `() => ${createElement}(SuspenseComp, { comp: $1 })`;
|
|
102
|
+
let prefixStr = `import { ${createElement} } from "${FRAMEWORK}";import { SuspenseComp } from "@moneko/${FRAMEWORK}";`;
|
|
103
|
+
if (hasCustomRouter) {
|
|
104
|
+
prefixStr += `import merge from "@moneko/${FRAMEWORK}/lib/merge.js";import customRouter from "@/router";`;
|
|
105
|
+
}
|
|
106
|
+
if (![
|
|
107
|
+
'react',
|
|
108
|
+
'solid-js'
|
|
109
|
+
].includes(FRAMEWORK)) {
|
|
110
|
+
replaceStr = '$1';
|
|
111
|
+
prefixStr = '';
|
|
112
|
+
}
|
|
113
|
+
export let routes = [];
|
|
114
|
+
let timerRoutes;
|
|
115
|
+
function generatorLibraryRouter() {
|
|
116
|
+
clearTimeout(timerRoutes);
|
|
117
|
+
timerRoutes = setTimeout(()=>{
|
|
118
|
+
clearTimeout(timerRoutes);
|
|
119
|
+
routes = getTree(compPath, {
|
|
120
|
+
regex: /README\.mdx?$/,
|
|
121
|
+
alia: '@pkg'
|
|
122
|
+
});
|
|
123
|
+
const tree = JSON.stringify(routes).replace(/"rr\((.+?)\)rr"/g, replaceStr).slice(1, -1);
|
|
124
|
+
Object.assign(route.data, {
|
|
125
|
+
data: `${prefixStr}const routes = [{ path: "/", children: [{ path: "/" }, ${tree}] }];
|
|
126
|
+
export default ${hasCustomRouter ? 'merge([...routes, ...customRouter], "path")' : 'routes'}`
|
|
127
|
+
});
|
|
128
|
+
}, 100);
|
|
129
|
+
}
|
|
130
|
+
let timerExample;
|
|
131
|
+
function generatorLibraryDemo() {
|
|
132
|
+
clearTimeout(timerExample);
|
|
133
|
+
timerExample = setTimeout(()=>{
|
|
134
|
+
clearTimeout(timerExample);
|
|
135
|
+
const exampleNext = {};
|
|
136
|
+
getTree(compPath, {
|
|
137
|
+
regex: /\/examples\/(.+)\.md$/,
|
|
138
|
+
outputSource: true
|
|
139
|
+
}).forEach((item)=>{
|
|
140
|
+
const _name = [
|
|
141
|
+
example.data.name,
|
|
142
|
+
item.key
|
|
143
|
+
].filter(Boolean).join('/');
|
|
144
|
+
const data = item.children?.[0].children?.filter((e)=>e.codes)?.map((e)=>({
|
|
145
|
+
title: e.path.replace(/.md$/, ''),
|
|
146
|
+
order: 0,
|
|
147
|
+
...e.meta,
|
|
148
|
+
codes: e.codes
|
|
149
|
+
})).sort((a, b)=>a.order - b.order);
|
|
150
|
+
Object.assign(exampleNext, {
|
|
151
|
+
[_name]: `export default ${JSON.stringify(data)};`
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
Object.assign(example.data, {
|
|
155
|
+
data: exampleNext
|
|
156
|
+
});
|
|
157
|
+
}, 100);
|
|
158
|
+
}
|
|
159
|
+
function watchFiles(root, ignored, call) {
|
|
160
|
+
const ignoredRouter = (src, stats)=>{
|
|
161
|
+
if (stats) {
|
|
162
|
+
if (stats?.isDirectory()) {
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
return ignored.test(src);
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
const watcher = watch(root, {
|
|
169
|
+
ignored: ignoredRouter,
|
|
170
|
+
persistent: true,
|
|
171
|
+
ignoreInitial: false
|
|
172
|
+
});
|
|
173
|
+
watcher.on('add', ()=>{
|
|
174
|
+
call();
|
|
175
|
+
}).on('change', ()=>{
|
|
176
|
+
call();
|
|
177
|
+
}).on('unlink', ()=>{
|
|
178
|
+
call();
|
|
179
|
+
});
|
|
180
|
+
process.on('SIGINT', function() {
|
|
181
|
+
watcher.close();
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
if (APPTYPE === 'library') {
|
|
185
|
+
watchFiles(compPath, /(?<!README\.mdx?)$/, generatorLibraryRouter);
|
|
186
|
+
watchFiles(compPath, /(?<!\/examples\/(.+)\.md)$/, generatorLibraryDemo);
|
|
187
|
+
}
|
package/lib/seo.js
CHANGED
|
@@ -1 +1,39 @@
|
|
|
1
|
-
import{existsSync
|
|
1
|
+
import { existsSync, mkdirSync, writeFileSync } from 'fs';
|
|
2
|
+
import { join } from 'path';
|
|
3
|
+
import { CONFIG } from './common.js';
|
|
4
|
+
import { routes } from './routes.js';
|
|
5
|
+
import { resolveProgramPath } from './utils.js';
|
|
6
|
+
import { outputConfig } from './webpack.common.js';
|
|
7
|
+
function writeFile(path, data) {
|
|
8
|
+
try {
|
|
9
|
+
writeFileSync(path, data, 'utf-8');
|
|
10
|
+
} catch (error) {}
|
|
11
|
+
}
|
|
12
|
+
export const seo = ()=>{
|
|
13
|
+
const { domain , nojekyll , path } = CONFIG.seo || {};
|
|
14
|
+
if (!domain) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const routeBase = CONFIG.routeBaseName;
|
|
18
|
+
const base = routeBase.endsWith('/') ? routeBase : `${routeBase}/`;
|
|
19
|
+
const baseDir = path && resolveProgramPath(path) || outputConfig?.path || process.cwd();
|
|
20
|
+
if (!existsSync(baseDir)) {
|
|
21
|
+
mkdirSync(baseDir);
|
|
22
|
+
}
|
|
23
|
+
writeFile(join(baseDir, 'CNAME'), domain);
|
|
24
|
+
writeFile(join(baseDir, 'robots'), `Sitemap: https://${domain}${base}sitemap.txt`);
|
|
25
|
+
const sitemap = [];
|
|
26
|
+
function getSiteMap(list) {
|
|
27
|
+
list.forEach((item)=>{
|
|
28
|
+
sitemap.push(`https://${domain}${base}${item.key}`);
|
|
29
|
+
if (Array.isArray(item.children)) {
|
|
30
|
+
getSiteMap(item.children);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
getSiteMap(routes);
|
|
35
|
+
writeFile(join(baseDir, 'sitemap.txt'), sitemap.join('\n'));
|
|
36
|
+
if (nojekyll) {
|
|
37
|
+
writeFile(join(baseDir, '.nojekyll'), '');
|
|
38
|
+
}
|
|
39
|
+
};
|