@moneko/core 3.0.0-beta.84 → 3.0.0-beta.85
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.d.ts +12 -12
- package/lib/app.js +1 -27
- package/lib/cleanup.js +1 -19
- package/lib/common.js +2 -214
- package/lib/coverage.js +1 -30
- package/lib/define.js +1 -9
- package/lib/docs.js +1 -118
- package/lib/done.js +1 -12
- package/lib/esm.js +1 -7
- package/lib/generate-api.js +1 -331
- package/lib/has-pkg.js +1 -14
- package/lib/html-add-entry-attr.js +1 -24
- package/lib/html-plugin-option.js +1 -44
- package/lib/index.js +1 -3
- package/lib/minify.js +1 -46
- package/lib/modifyVars.js +1 -11
- package/lib/module-federation.js +1 -46
- package/lib/module.config.js +1 -211
- package/lib/net.js +1 -33
- package/lib/object-listener.js +1 -28
- package/lib/process-env.js +1 -65
- package/lib/resolver-sync.js +1 -21
- package/lib/routes.d.ts +10 -0
- package/lib/routes.js +1 -171
- package/lib/seo.js +1 -59
- package/lib/swcrc.js +1 -105
- package/lib/tsloader.config.js +1 -25
- package/lib/utils.js +1 -49
- package/lib/virtual-module-plugin.js +1 -26
- package/lib/virtual-modules.d.ts +12 -12
- package/lib/virtual-modules.js +1 -30
- package/lib/webpack.common.d.ts +1 -0
- package/lib/webpack.common.js +1 -230
- package/lib/webpack.dev.js +3 -92
- package/lib/webpack.prod.js +1 -66
- package/lib/yarn-argv.js +1 -9
- package/package.json +2 -2
package/lib/module.config.js
CHANGED
|
@@ -1,211 +1 @@
|
|
|
1
|
-
import {
|
|
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;
|
|
1
|
+
import{resolve as e}from"path";import s from"mini-css-extract-plugin";import o from"mini-svg-data-uri";import{CONFIG as t,PUBLICPATH as l}from"./common.js";import{hasPkg as r}from"./has-pkg.js";import a from"./modifyVars.js";import{APPTYPE as n,DEV as i,FRAMEWORK as c,__dirname as m}from"./process-env.js";import p from"./swcrc.js";import d from"./tsloader.config.js";import{resolveNodeModulesPath as u,resolveProgramPath as f}from"./utils.js";let y="single-spa"===n?l:"../",x={loader:s.loader,options:{publicPath:"/"!==y?y:"../"}},g=r("@moneko/postcss")&&{loader:"postcss-loader",options:{postcssOptions:await import("@moneko/postcss")}};i&&(x="style-loader");let $=[...t.cssModules,`@moneko/${c}`,"neko-ui"].map(u),j=[...["src/styles/variables/*.less","src/styles/mixins/*.less","site/styles/variables/*.less","site/styles/mixins/*.less"].map(f)],b=["components","example","mock","site","src"].map(f),v=[x,{loader:"@teamsupercell/typings-for-css-modules-loader",options:{verifyOnly:!i}},{loader:"css-loader",options:{modules:{auto:e=>{for(let s=0,o=$.length;s<o;s++)if(e&&e?.includes($[s]))return/(.*(?<!\.global\.(le|c)ss)$)/i.test(e);return/(^(?!.*node_modules))(.*(?<!\.global\.(le|c)ss)$)/i.test(e)},localIdentName:"[path][name]__[local]",exportLocalsConvention:"dashesOnly"},importLoaders:2}},g,"css-unicode-loader",{loader:"less-loader",options:{sourceMap:!!t.sourceMap,lessOptions:{modifyVars:a,javascriptEnabled:!0}}},{loader:"style-resources-loader",options:{patterns:j}}].filter(Boolean),w={loader:"tsc"===t.compiler?"ts-loader":"swc-loader",options:"tsc"===t.compiler?d:p(i)},h={rules:[{test:/\.mdx?$/,include:[f("components")],exclude:[/(.+)\/examples\/(.+).mdx?$/i],enforce:"pre",use:[{loader:e(m,"./loader/frontmatter.cjs")}]},{oneOf:[{resourceQuery:/raw/,type:"asset/source"},{test:/\.wasm$/,type:"webassembly/async"},{test:/\.txt$/,type:"asset/source"},{test:/\.(gif|png|jpe?g|ico|mp4)$/i,type:"asset",dependency:{not:["url"]},generator:{filename:"assets/images/[name][ext][query]"},include:b.concat(t.rulesInclude?.media?.map(u)||[])},{test:/\.svg$/,type:"asset/inline",generator:{dataUrl:e=>o("string"!=typeof e?e.toString():e)}},{test:/\.(eot|ttf|otf|woff(|2))$/,type:"asset",generator:{filename:"assets/fonts/[name][ext][query]"},include:b.concat(t.rulesInclude?.fonts?.map(u)||[])},{test:/\.less$/,use:v,include:b.concat(t.rulesInclude?.less?.map(u)||[])},{test:/\.css$/,use:[x,"css-loader",g,"css-unicode-loader"].filter(Boolean),include:b.concat(t.rulesInclude?.css?.map(u)||[])},{test:/\.(cj|mj|t|j)s(|x)$/,use:[...t.prefixJsLoader,w].filter(Boolean),include:b.concat(t.rulesInclude?.js?.map(u)||[])},{test:/\.mdx?$/,use:[...t.prefixJsLoader,w,{loader:"@mdx-js/loader",options:t.mdx}].filter(Boolean),include:b,exclude:[/(.+)\/examples\/(.+).mdx?$/i]},{test:/\.mdx?$/,type:"asset/source",include:[/(.+)\/examples\/(.+).mdx?$/i]},{type:"asset/source",include:[/(.+)\/examples\/(.+).*?$/i]}]},...t.moduleRules]};export default h;
|
package/lib/net.js
CHANGED
|
@@ -1,33 +1 @@
|
|
|
1
|
-
import {
|
|
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
|
-
}
|
|
1
|
+
import{createConnection as t}from"net";import{networkInterfaces as e}from"os";import r from"webpack-dev-server";let{internalIPSync:o}=r;export function getNetworkAdress(){let t=e();for(let e in t)if(Object.prototype.hasOwnProperty.call(t,e)){let r=t[e];for(let t=0;t<r.length;t++){let e=r[t];if("IPv4"===e.family&&"127.0.0.1"!==e.address&&!e.address.startsWith("169.254")&&!e.internal)return e.address}}}export function getIPv4(){return o("v4")}export function getPort(e,r,o="0.0.0.0"){return new Promise(n=>{let s=t(e,o);s.on("connect",()=>{s.destroy(),n(getPort(e+1,r,o))}),s.on("error",()=>{n(e)})})}
|
package/lib/object-listener.js
CHANGED
|
@@ -1,28 +1 @@
|
|
|
1
|
-
export default function
|
|
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
|
-
}
|
|
1
|
+
export default function e(e){let t=[],n=new Proxy(e,{set:(e,n,r)=>(e[n]=r,t.forEach(t=>{t(e)}),!0)});return{data:n,listener:function(e){return t.push(e),()=>{let n=t.indexOf(e);-1!==n&&t.splice(n,1)}}}}
|
package/lib/process-env.js
CHANGED
|
@@ -1,65 +1 @@
|
|
|
1
|
-
import
|
|
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/@moneko/cli/');
|
|
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
|
-
}
|
|
1
|
+
import{existsSync as e,mkdirSync as o,readFileSync as r}from"fs";import{join as s}from"path";import t from"url";import{hasPkg as n}from"./has-pkg.js";import{resolveProgramPath as p}from"./utils.js";import c from"./yarn-argv.js";export const __dirname=t.fileURLToPath(new URL(".",import.meta.url));export const APPTYPE=process.env.APPTYPE;export const FRAMEWORK=process.env.FRAMEWORK;export const isReact="react"===FRAMEWORK;export const isSolid="solid-js"===FRAMEWORK;export const jsxImportSource={react:"react","solid-js":"solid-js/h"}[FRAMEWORK];export const PROGRAMPATH=process.cwd();export const PACKAGENAME=process.env.npm_package_name;export const PACKAGEVERSION=process.env.npm_package_version;let a=r(s(__dirname,"../package.json"),{encoding:"utf-8"});export const pkgName=JSON.parse(a).name;export const DEV="development"===process.env.NODE_ENV;export const cacheDir=s(PROGRAMPATH,"./node_modules/.cache/.mo/");e(cacheDir)||o(cacheDir,{recursive:!0});export const NODE_ENV=process.env.NODE_ENV;export const CUSTOMCONFIG=process.env.npm_config_config||c.config;export let hasEslintConfig=!!Object.keys(process.env).filter(e=>e.startsWith("npm_package_eslintConfig_")).length;export let hasStylelintConfig=!!Object.keys(process.env).filter(e=>e.startsWith("npm_package_stylelint_")).length;export const hasAntd=n("antd");export const programInfo={name:PACKAGENAME,version:PACKAGEVERSION,type:APPTYPE,description:process.env.npm_package_description,author:{name:process.env.npm_package_author_name,email:process.env.npm_package_author_email,url:process.env.npm_package_author_url},repository:{type:process.env.npm_package_repository_type,url:process.env.npm_package_repository_url,directory:process.env.npm_package_repository_directory}};if(parseInt(process.versions.node)>14){let e=r(p("package.json"),{encoding:"utf-8"}),{description:o,author:s,repository:t,eslintConfig:n,stylelint:c}=JSON.parse(e);programInfo.author="string"==typeof s?{name:s}:s,programInfo.repository="string"==typeof s?{url:t}:t,programInfo.description=o,hasEslintConfig=!!n,hasStylelintConfig=!!c}
|
package/lib/resolver-sync.js
CHANGED
|
@@ -1,21 +1 @@
|
|
|
1
|
-
import
|
|
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;
|
|
1
|
+
import*as e from"fs";import s from"enhanced-resolve";let{CachedInputFileSystem:o,ResolverFactory:n}=s,m=n.createResolver({fileSystem:new o(e,4e3),conditionNames:["node"],extensions:[".js",".json",".node"],useSyncFileSystemCalls:!0,mainFields:["esm","module","main"]});export default m;
|
package/lib/routes.d.ts
CHANGED
package/lib/routes.js
CHANGED
|
@@ -1,171 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { join, relative } from 'path';
|
|
3
|
-
import { watch } from 'chokidar';
|
|
4
|
-
import { load } from 'js-yaml';
|
|
5
|
-
import { APPTYPE, DEV, FRAMEWORK, PROGRAMPATH } from './process-env.js';
|
|
6
|
-
import { resolveNodeModulesPath } from './utils.js';
|
|
7
|
-
import { vm } from './virtual-module-plugin.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
|
-
const base = '@app/example';
|
|
90
|
-
const routesModule = '@app/routes';
|
|
91
|
-
let timerRoutes;
|
|
92
|
-
function generatorLibraryRouter() {
|
|
93
|
-
clearTimeout(timerRoutes);
|
|
94
|
-
timerRoutes = setTimeout(()=>{
|
|
95
|
-
clearTimeout(timerRoutes);
|
|
96
|
-
const createElement = {
|
|
97
|
-
react: 'createElement',
|
|
98
|
-
'solid-js': 'createComponent'
|
|
99
|
-
}[FRAMEWORK];
|
|
100
|
-
let replaceStr = `() => ${createElement}(SuspenseComp, { comp: $1 })`;
|
|
101
|
-
let prefixStr = `import { ${createElement} } from "${FRAMEWORK}";import { SuspenseComp } from "@moneko/${FRAMEWORK}";`;
|
|
102
|
-
if (![
|
|
103
|
-
'react',
|
|
104
|
-
'solid-js'
|
|
105
|
-
].includes(FRAMEWORK)) {
|
|
106
|
-
replaceStr = '$1';
|
|
107
|
-
prefixStr = '';
|
|
108
|
-
}
|
|
109
|
-
const tree = JSON.stringify(getTree(compPath, {
|
|
110
|
-
regex: /README\.mdx?$/,
|
|
111
|
-
alia: '@pkg'
|
|
112
|
-
})).replace(/"rr\((.+?)\)rr"/g, replaceStr);
|
|
113
|
-
vm?.writeModule(resolveNodeModulesPath(routesModule), `${prefixStr}export default ${tree}`);
|
|
114
|
-
}, 100);
|
|
115
|
-
}
|
|
116
|
-
let timerExample;
|
|
117
|
-
function generatorLibraryDemo() {
|
|
118
|
-
clearTimeout(timerExample);
|
|
119
|
-
timerExample = setTimeout(()=>{
|
|
120
|
-
clearTimeout(timerExample);
|
|
121
|
-
getTree(compPath, {
|
|
122
|
-
regex: /\/examples\/(.+)\.md$/,
|
|
123
|
-
outputSource: true
|
|
124
|
-
}).forEach((item)=>{
|
|
125
|
-
const _name = [
|
|
126
|
-
base,
|
|
127
|
-
item.key
|
|
128
|
-
].filter(Boolean).join('/');
|
|
129
|
-
const data = item.children?.[0].children?.filter((e)=>e.codes)?.map((e)=>({
|
|
130
|
-
title: e.path.replace(/.md$/, ''),
|
|
131
|
-
order: 0,
|
|
132
|
-
...e.meta,
|
|
133
|
-
codes: e.codes
|
|
134
|
-
})).sort((a, b)=>a.order - b.order);
|
|
135
|
-
vm?.writeModule(resolveNodeModulesPath(_name), `export default ${JSON.stringify(data)};`);
|
|
136
|
-
});
|
|
137
|
-
}, 100);
|
|
138
|
-
}
|
|
139
|
-
function watchFiles(root, ignored, call) {
|
|
140
|
-
const ignoredRouter = (src, stats)=>{
|
|
141
|
-
if (stats) {
|
|
142
|
-
if (stats?.isDirectory()) {
|
|
143
|
-
return false;
|
|
144
|
-
}
|
|
145
|
-
return ignored.test(src);
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
|
-
const watcher = watch(root, {
|
|
149
|
-
ignored: ignoredRouter,
|
|
150
|
-
persistent: true
|
|
151
|
-
});
|
|
152
|
-
watcher.on('add', ()=>{
|
|
153
|
-
call();
|
|
154
|
-
}).on('change', ()=>{
|
|
155
|
-
call();
|
|
156
|
-
}).on('unlink', ()=>{
|
|
157
|
-
call();
|
|
158
|
-
});
|
|
159
|
-
process.on('SIGINT', function() {
|
|
160
|
-
watcher.close();
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
if (APPTYPE === 'library') {
|
|
164
|
-
if (DEV) {
|
|
165
|
-
watchFiles(compPath, /(?<!README\.mdx?)$/, generatorLibraryRouter);
|
|
166
|
-
watchFiles(compPath, /(?<!\/examples\/(.+)\.md)$/, generatorLibraryDemo);
|
|
167
|
-
} else {
|
|
168
|
-
generatorLibraryRouter();
|
|
169
|
-
generatorLibraryDemo();
|
|
170
|
-
}
|
|
171
|
-
}
|
|
1
|
+
let e,t;import{readFileSync as r,readdirSync as o,statSync as n}from"fs";import{join as i,relative as l}from"path";import{watch as s}from"chokidar";import{load as c}from"js-yaml";import{APPTYPE as p,DEV as m,FRAMEWORK as a,PROGRAMPATH as u}from"./process-env.js";import{resolveNodeModulesPath as f}from"./utils.js";import{vm as d}from"./virtual-module-plugin.js";let g=/^---\n([\s\S]+?)\n---\n/;function h(e,t){let{regex:s,alia:p,base:m=e,outputSource:a}=t,u=o(e);return u.reduce((o,u)=>{let f=i(e,u),d=n(f);if(d.isDirectory()){let e=h(f,{...t,base:m});if(e.length>0){let t={},r={path:u,key:l(m,f)};if(a)Object.assign(t,{children:e});else{let o=e.splice(0,1)[0];e.length?Object.assign(t,{children:[{...o,path:"/",key:r.key},...e]}):Object.assign(t,o)}o.push(Object.assign(t,r))}}else if(s.test(f)){let e=r(f,{encoding:"utf-8"}),t=function(e){let t=e.match(g);return t&&t[1]?t[1].trim():null}(e),n=t?c(t):{},s=l(m,f);o.push(Object.assign({path:u,key:s,meta:{...n}},p&&{component:`rr(() => import(/* webpackChunkName: '${s}' */'${i(p,s)}'))rr`},a&&{codes:function(e){let t;let r={},o=/```(.+?)\n([\s\S]*?)\n```/g;for(;null!==(t=o.exec(e));){let[,e="jsx",o]=t,n=e.split(" ").pop()||"jsx";r[n]=o.trim()}return Object.keys(r).length?r:{jsx:e}}(e.replace(g,"").replace(/^\n+|\n+$/g,""))}))}return o},[])}let $=i(u,"./components");export let routes=[];function j(){clearTimeout(e),e=setTimeout(()=>{clearTimeout(e);let t={react:"createElement","solid-js":"createComponent"}[a],r=`() => ${t}(SuspenseComp, { comp: $1 })`,o=`import { ${t} } from "${a}";import { SuspenseComp } from "@moneko/${a}";`;["react","solid-js"].includes(a)||(r="$1",o=""),routes=h($,{regex:/README\.mdx?$/,alia:"@pkg"});let n=JSON.stringify(routes).replace(/"rr\((.+?)\)rr"/g,r);d?.writeModule(f("@app/routes"),`${o}export default ${n}`)},100)}function x(){clearTimeout(t),t=setTimeout(()=>{clearTimeout(t),h($,{regex:/\/examples\/(.+)\.md$/,outputSource:!0}).forEach(e=>{let t=["@app/example",e.key].filter(Boolean).join("/"),r=e.children?.[0].children?.filter(e=>e.codes)?.map(e=>({title:e.path.replace(/.md$/,""),order:0,...e.meta,codes:e.codes})).sort((e,t)=>e.order-t.order);d?.writeModule(f(t),`export default ${JSON.stringify(r)};`)})},100)}function k(e,t,r){let o=s(e,{ignored:(e,r)=>{if(r)return!r?.isDirectory()&&t.test(e)},persistent:!0});o.on("add",()=>{r()}).on("change",()=>{r()}).on("unlink",()=>{r()}),process.on("SIGINT",function(){o.close()})}"library"===p&&(m?(k($,/(?<!README\.mdx?)$/,j),k($,/(?<!\/examples\/(.+)\.md)$/,x)):(j(),x()));
|
package/lib/seo.js
CHANGED
|
@@ -1,59 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { join } from 'path';
|
|
3
|
-
import { CONFIG } from './common.js';
|
|
4
|
-
import { APPTYPE, PROGRAMPATH } from './process-env.js';
|
|
5
|
-
import { resolveProgramPath } from './utils.js';
|
|
6
|
-
import { outputConfig } from './webpack.common.js';
|
|
7
|
-
function getLibDocsPages(dir, domain, basename) {
|
|
8
|
-
let results = [];
|
|
9
|
-
const list = readdirSync(dir);
|
|
10
|
-
list.forEach(function(_file) {
|
|
11
|
-
if (_file === 'static') {
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
const file = `${dir}/${_file}`;
|
|
15
|
-
const stat = statSync(file);
|
|
16
|
-
if (stat && stat.isDirectory()) {
|
|
17
|
-
results = results.concat(getLibDocsPages(file, domain, basename));
|
|
18
|
-
} else if (file.endsWith('README.mdx')) {
|
|
19
|
-
results.push(`https://${domain}${basename}${file.replace(`${PROGRAMPATH}/components/`, '').replace('/README.mdx', '')}`);
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
return results;
|
|
23
|
-
}
|
|
24
|
-
export const seo = ()=>{
|
|
25
|
-
const { domain , nojekyll , path } = CONFIG.seo || {};
|
|
26
|
-
if (!domain) {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
const routeBase = CONFIG.routeBaseName;
|
|
30
|
-
const base = routeBase.endsWith('/') ? routeBase : `${routeBase}/`;
|
|
31
|
-
const baseDir = path && resolveProgramPath(path) || outputConfig?.path || process.cwd();
|
|
32
|
-
const call = (err)=>{
|
|
33
|
-
if (err) {
|
|
34
|
-
throw err;
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
if (!existsSync(baseDir)) {
|
|
38
|
-
mkdirSync(baseDir);
|
|
39
|
-
}
|
|
40
|
-
writeFile(join(baseDir, 'CNAME'), domain, 'utf-8', call);
|
|
41
|
-
writeFile(join(baseDir, 'robots'), `Sitemap: https://${domain}${base}sitemap.txt`, 'utf-8', call);
|
|
42
|
-
let sitemap = '';
|
|
43
|
-
switch(APPTYPE){
|
|
44
|
-
case 'library':
|
|
45
|
-
sitemap = getLibDocsPages(join(PROGRAMPATH, './components'), domain, base).join('\n');
|
|
46
|
-
break;
|
|
47
|
-
case 'single-component':
|
|
48
|
-
case 'mobile':
|
|
49
|
-
case 'site':
|
|
50
|
-
case 'back-stage':
|
|
51
|
-
case 'single-spa':
|
|
52
|
-
default:
|
|
53
|
-
break;
|
|
54
|
-
}
|
|
55
|
-
writeFile(join(baseDir, 'sitemap.txt'), sitemap, 'utf-8', call);
|
|
56
|
-
if (nojekyll) {
|
|
57
|
-
writeFile(join(baseDir, '.nojekyll'), '', 'utf-8', call);
|
|
58
|
-
}
|
|
59
|
-
};
|
|
1
|
+
import{existsSync as t,mkdirSync as o,writeFileSync as r}from"fs";import{join as e}from"path";import{CONFIG as s}from"./common.js";import{routes as m}from"./routes.js";import{resolveProgramPath as i}from"./utils.js";import{outputConfig as p}from"./webpack.common.js";function c(t,o){try{r(t,o,"utf-8")}catch(t){}}export const seo=()=>{let{domain:r,nojekyll:a,path:f}=s.seo||{};if(!r)return;let n=s.routeBaseName,h=n.endsWith("/")?n:`${n}/`,l=f&&i(f)||p?.path||process.cwd();t(l)||o(l),c(e(l,"CNAME"),r),c(e(l,"robots"),`Sitemap: https://${r}${h}sitemap.txt`);let u=[];!function t(o){o.forEach(o=>{u.push(`https://${r}${h}${o.key}`),Array.isArray(o.children)&&t(o.children)})}(m),c(e(l,"sitemap.txt"),u),a&&c(e(l,".nojekyll"),"")};
|