@moneko/core 3.0.0-beta.45 → 3.0.0-beta.47

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.
@@ -1,184 +1 @@
1
- import MiniCssExtractPlugin from 'mini-css-extract-plugin';
2
- import svgToMiniDataURI from 'mini-svg-data-uri';
3
- import { CONFIG, PUBLICPATH } from './common.js';
4
- import { hasPkg } from './has-pkg.js';
5
- import modifyVars from './modifyVars.js';
6
- import { APPTYPE, DEV, FRAMEWORK } from './process-env.js';
7
- import swcOption from './swcrc.js';
8
- import tsLoaderConfig from './tsloader.config.js';
9
- import { resolveNodeModulesPath, resolveProgramPath } from './utils.js';
10
- const cssAssetsPublicPath = APPTYPE === 'single-spa' ? PUBLICPATH : '../';
11
- let styleLoader = {
12
- loader: MiniCssExtractPlugin.loader,
13
- options: {
14
- publicPath: cssAssetsPublicPath !== '/' ? cssAssetsPublicPath : '../'
15
- }
16
- };
17
- const postcssLoader = hasPkg('@moneko/postcss') && {
18
- loader: 'postcss-loader',
19
- options: {
20
- postcssOptions: await import('@moneko/postcss')
21
- }
22
- };
23
- if (DEV) {
24
- styleLoader = 'style-loader';
25
- }
26
- const customCssModules = [
27
- ...CONFIG.cssModules,
28
- `@moneko/${FRAMEWORK}`,
29
- 'neko-ui'
30
- ].map(resolveNodeModulesPath);
31
- const styleResources = [
32
- ...[
33
- 'src/styles/variables/*.less',
34
- 'src/styles/mixins/*.less',
35
- 'site/styles/variables/*.less',
36
- 'site/styles/mixins/*.less'
37
- ].map(resolveProgramPath)
38
- ];
39
- const entryResolveProgramPath = [
40
- 'components',
41
- 'example',
42
- 'mock',
43
- 'site',
44
- 'src'
45
- ].map(resolveProgramPath);
46
- const lessLoaderRule = [
47
- styleLoader,
48
- {
49
- loader: 'css-loader',
50
- options: {
51
- modules: {
52
- auto: (resourcePath)=>{
53
- for(let i = 0, len = customCssModules.length; i < len; i++){
54
- if (resourcePath && resourcePath?.includes(customCssModules[i])) {
55
- return /(.*(?<!\.global\.(le|c)ss)$)/i.test(resourcePath);
56
- }
57
- }
58
- return /(^(?!.*node_modules))(.*(?<!\.global\.(le|c)ss)$)/i.test(resourcePath);
59
- },
60
- localIdentName: '[path][name]__[local]',
61
- exportLocalsConvention: 'dashesOnly'
62
- },
63
- importLoaders: 2
64
- }
65
- },
66
- postcssLoader,
67
- 'css-unicode-loader',
68
- {
69
- loader: 'less-loader',
70
- options: {
71
- sourceMap: !!CONFIG.sourceMap,
72
- lessOptions: {
73
- modifyVars: modifyVars,
74
- javascriptEnabled: true
75
- }
76
- }
77
- },
78
- {
79
- loader: 'style-resources-loader',
80
- options: {
81
- patterns: styleResources
82
- }
83
- }
84
- ].filter(Boolean);
85
- const tsLoader = {
86
- loader: CONFIG.compiler === 'tsc' ? 'ts-loader' : 'swc-loader',
87
- options: CONFIG.compiler === 'tsc' ? tsLoaderConfig : swcOption(DEV)
88
- };
89
- const moduleOptions = {
90
- rules: [
91
- {
92
- oneOf: [
93
- {
94
- resourceQuery: /raw/,
95
- type: 'asset/source'
96
- },
97
- {
98
- resourceQuery: /\.wasm$/,
99
- type: 'webassembly/async'
100
- },
101
- {
102
- test: /\.less$/,
103
- use: lessLoaderRule,
104
- include: entryResolveProgramPath.concat(CONFIG.rulesInclude?.less?.map(resolveNodeModulesPath) || [])
105
- },
106
- {
107
- test: /\.css$/,
108
- use: [
109
- styleLoader,
110
- 'css-loader',
111
- postcssLoader,
112
- 'css-unicode-loader'
113
- ].filter(Boolean),
114
- include: entryResolveProgramPath.concat(CONFIG.rulesInclude?.css?.map(resolveNodeModulesPath) || [])
115
- },
116
- {
117
- test: /\.(gif|png|jpe?g|ico|mp4)$/i,
118
- type: 'asset',
119
- generator: {
120
- filename: 'assets/images/[name][ext][query]'
121
- },
122
- include: entryResolveProgramPath.concat(CONFIG.rulesInclude?.media?.map(resolveNodeModulesPath) || [])
123
- },
124
- {
125
- test: /\.(eot|ttf|otf|woff(|2))$/,
126
- type: 'asset',
127
- generator: {
128
- filename: 'assets/fonts/[name][ext][query]'
129
- },
130
- include: entryResolveProgramPath.concat(CONFIG.rulesInclude?.fonts?.map(resolveNodeModulesPath) || [])
131
- },
132
- {
133
- test: /\.svg$/,
134
- type: 'asset/inline',
135
- generator: {
136
- dataUrl: (content)=>svgToMiniDataURI(typeof content !== 'string' ? content.toString() : content)
137
- }
138
- },
139
- {
140
- test: /\.txt$/,
141
- type: 'asset/source'
142
- },
143
- {
144
- test: /\.(cj|mj|t|j)s(|x)$/,
145
- use: [
146
- ...CONFIG.prefixJsLoader,
147
- tsLoader
148
- ].filter(Boolean),
149
- include: entryResolveProgramPath.concat(CONFIG.rulesInclude?.js?.map(resolveNodeModulesPath) || [])
150
- },
151
- {
152
- test: /\.mdx?$/,
153
- use: [
154
- ...CONFIG.prefixJsLoader,
155
- tsLoader,
156
- {
157
- loader: '@mdx-js/loader',
158
- options: CONFIG.mdx
159
- }
160
- ].filter(Boolean),
161
- include: entryResolveProgramPath,
162
- exclude: [
163
- /(.+)\/examples\/(.+).mdx?$/i
164
- ]
165
- },
166
- {
167
- test: /\.mdx?$/,
168
- type: 'asset/source',
169
- include: [
170
- /(.+)\/examples\/(.+).mdx?$/i
171
- ]
172
- },
173
- {
174
- type: 'asset/source',
175
- include: [
176
- /(.+)\/examples\/(.+).*?$/i
177
- ]
178
- }
179
- ]
180
- },
181
- ...CONFIG.moduleRules
182
- ]
183
- };
184
- export default moduleOptions;
1
+ import e from"mini-css-extract-plugin";import s from"mini-svg-data-uri";import{CONFIG as o,PUBLICPATH as t}from"./common.js";import{hasPkg as l}from"./has-pkg.js";import r from"./modifyVars.js";import{APPTYPE as a,DEV as i,FRAMEWORK as n}from"./process-env.js";import c from"./swcrc.js";import m from"./tsloader.config.js";import{resolveNodeModulesPath as p,resolveProgramPath as d}from"./utils.js";let u="single-spa"===a?t:"../",f={loader:e.loader,options:{publicPath:"/"!==u?u:"../"}},y=l("@moneko/postcss")&&{loader:"postcss-loader",options:{postcssOptions:await import("@moneko/postcss")}};i&&(f="style-loader");let x=[...o.cssModules,`@moneko/${n}`,"neko-ui"].map(p),g=[...["src/styles/variables/*.less","src/styles/mixins/*.less","site/styles/variables/*.less","site/styles/mixins/*.less"].map(d)],$=["components","example","mock","site","src"].map(d),j=[f,{loader:"css-loader",options:{modules:{auto:e=>{for(let s=0,o=x.length;s<o;s++)if(e&&e?.includes(x[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}},y,"css-unicode-loader",{loader:"less-loader",options:{sourceMap:!!o.sourceMap,lessOptions:{modifyVars:r,javascriptEnabled:!0}}},{loader:"style-resources-loader",options:{patterns:g}}].filter(Boolean),b={loader:"tsc"===o.compiler?"ts-loader":"swc-loader",options:"tsc"===o.compiler?m:c(i)},v={rules:[{oneOf:[{resourceQuery:/raw/,type:"asset/source"},{resourceQuery:/\.wasm$/,type:"webassembly/async"},{test:/\.less$/,use:j,include:$.concat(o.rulesInclude?.less?.map(p)||[])},{test:/\.css$/,use:[f,"css-loader",y,"css-unicode-loader"].filter(Boolean),include:$.concat(o.rulesInclude?.css?.map(p)||[])},{test:/\.(gif|png|jpe?g|ico|mp4)$/i,type:"asset",generator:{filename:"assets/images/[name][ext][query]"},include:$.concat(o.rulesInclude?.media?.map(p)||[])},{test:/\.(eot|ttf|otf|woff(|2))$/,type:"asset",generator:{filename:"assets/fonts/[name][ext][query]"},include:$.concat(o.rulesInclude?.fonts?.map(p)||[])},{test:/\.svg$/,type:"asset/inline",generator:{dataUrl:e=>s("string"!=typeof e?e.toString():e)}},{test:/\.txt$/,type:"asset/source"},{test:/\.(cj|mj|t|j)s(|x)$/,use:[...o.prefixJsLoader,b].filter(Boolean),include:$.concat(o.rulesInclude?.js?.map(p)||[])},{test:/\.mdx?$/,use:[...o.prefixJsLoader,b,{loader:"@mdx-js/loader",options:o.mdx}].filter(Boolean),include:$,exclude:[/(.+)\/examples\/(.+).mdx?$/i]},{test:/\.mdx?$/,type:"asset/source",include:[/(.+)\/examples\/(.+).mdx?$/i]},{type:"asset/source",include:[/(.+)\/examples\/(.+).*?$/i]}]},...o.moduleRules]};export default v;
@@ -1,65 +1 @@
1
- import { readFileSync, existsSync, mkdirSync } 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 cacheDir = join(PROGRAMPATH, './node_modules/.cache/@moneko/cli/');
23
- if (!existsSync(cacheDir)) {
24
- mkdirSync(cacheDir, {
25
- recursive: true
26
- });
27
- }
28
- export const pkgName = JSON.parse(pkg).name;
29
- export const NODE_ENV = process.env.NODE_ENV;
30
- export const CUSTOMCONFIG = process.env.npm_config_config || yarnArgv.config;
31
- export const DEV = process.env.NODE_ENV === 'development';
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{readFileSync as e,existsSync as o,mkdirSync 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=e(s(__dirname,"../package.json"),{encoding:"utf-8"});export const cacheDir=s(PROGRAMPATH,"./node_modules/.cache/@moneko/cli/");o(cacheDir)||r(cacheDir,{recursive:!0});export const pkgName=JSON.parse(a).name;export const NODE_ENV=process.env.NODE_ENV;export const CUSTOMCONFIG=process.env.npm_config_config||c.config;export const DEV="development"===process.env.NODE_ENV;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 o=e(p("package.json"),{encoding:"utf-8"}),{description:r,author:s,repository:t,eslintConfig:n,stylelint:c}=JSON.parse(o);programInfo.author="string"==typeof s?{name:s}:s,programInfo.repository="string"==typeof s?{url:t}:t,programInfo.description=r,hasEslintConfig=!!n,hasStylelintConfig=!!c}
@@ -1,21 +1 @@
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;
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.js CHANGED
@@ -1,190 +1 @@
1
- import { readdirSync, statSync, writeFile, readFileSync, existsSync, mkdirSync, unlinkSync } from 'fs';
2
- import { join, relative } from 'path';
3
- import { watch } from 'chokidar';
4
- import { load } from 'js-yaml';
5
- import { PROGRAMPATH, APPTYPE, FRAMEWORK, DEV } from './process-env.js';
6
- import { resolveProgramPath } from './utils.js';
7
- export const frameworkCacheDir = resolveProgramPath(`.git/`);
8
- function cleanup() {
9
- try {
10
- unlinkSync(join(frameworkCacheDir, 'example.js'));
11
- } catch (error) {}
12
- try {
13
- unlinkSync(join(frameworkCacheDir, 'route.js'));
14
- } catch (error) {}
15
- }
16
- const frontmatterRegex = /^---\n([\s\S]+?)\n---\n/;
17
- function extractFrontmatter(md) {
18
- const matches = md.match(frontmatterRegex);
19
- return matches && matches[1] ? matches[1].trim() : null;
20
- }
21
- function extractCode(codeStr) {
22
- const codes = {};
23
- const regex = /```(.+?)\n([\s\S]*?)\n```/g;
24
- let match;
25
- while((match = regex.exec(codeStr)) !== null){
26
- const [, language = 'jsx', source] = match;
27
- const lang = language.split(' ').pop() || 'jsx';
28
- codes[lang] = source.trim();
29
- }
30
- return Object.keys(codes).length ? codes : {
31
- jsx: codeStr
32
- };
33
- }
34
- function getTree(directory, option) {
35
- const { regex , alia , base =directory , outputSource } = option;
36
- const files = readdirSync(directory);
37
- return files.reduce((tree, file)=>{
38
- const filePath = join(directory, file);
39
- const stats = statSync(filePath);
40
- if (stats.isDirectory()) {
41
- const children = getTree(filePath, {
42
- ...option,
43
- base
44
- });
45
- if (children.length > 0) {
46
- const item = {};
47
- const baseItem = {
48
- path: file,
49
- key: relative(base, filePath)
50
- };
51
- if (outputSource) {
52
- Object.assign(item, {
53
- children
54
- });
55
- } else {
56
- const frist = children.splice(0, 1)[0];
57
- if (children.length) {
58
- Object.assign(item, {
59
- children: [
60
- {
61
- ...frist,
62
- path: '/',
63
- key: baseItem.key
64
- },
65
- ...children
66
- ]
67
- });
68
- } else {
69
- Object.assign(item, frist);
70
- }
71
- }
72
- tree.push(Object.assign(item, baseItem));
73
- }
74
- } else if (regex.test(filePath)) {
75
- const source = readFileSync(filePath, {
76
- encoding: 'utf-8'
77
- });
78
- const frontmatter = extractFrontmatter(source);
79
- const meta = frontmatter ? load(frontmatter) : {};
80
- const reslove = relative(base, filePath);
81
- tree.push(Object.assign({
82
- path: file,
83
- key: reslove,
84
- meta: {
85
- ...meta
86
- }
87
- }, alia && {
88
- component: `rr(() => import(/* webpackChunkName: '${reslove}' */'${join(alia, reslove)}'))rr`
89
- }, outputSource && {
90
- codes: extractCode(source.replace(frontmatterRegex, '').replace(/^\n+|\n+$/g, ''))
91
- }));
92
- }
93
- return tree;
94
- }, []);
95
- }
96
- const compPath = join(PROGRAMPATH, './components');
97
- let genLibRouteTimer;
98
- function fallback(err) {
99
- if (err) {
100
- throw err;
101
- }
102
- }
103
- function generatorLibraryRouter() {
104
- if (genLibRouteTimer) {
105
- clearTimeout(genLibRouteTimer);
106
- }
107
- genLibRouteTimer = setTimeout(()=>{
108
- const createElement = {
109
- react: 'createElement',
110
- 'solid-js': 'createComponent'
111
- }[FRAMEWORK];
112
- let replaceStr = `() => ${createElement}(SuspenseComp, { comp: $1 })`;
113
- let prefixStr = `import { ${createElement} } from "${FRAMEWORK}";import { SuspenseComp } from "@moneko/${FRAMEWORK}";`;
114
- if (![
115
- 'react',
116
- 'solid-js'
117
- ].includes(FRAMEWORK)) {
118
- replaceStr = '$1';
119
- prefixStr = '';
120
- }
121
- const tree = JSON.stringify(getTree(compPath, {
122
- regex: /README\.mdx?$/,
123
- alia: '@pkg'
124
- })).replace(/"rr\((.+?)\)rr"/g, replaceStr);
125
- if (!existsSync(frameworkCacheDir)) {
126
- mkdirSync(frameworkCacheDir);
127
- }
128
- writeFile(join(frameworkCacheDir, 'route.js'), `${prefixStr}export default ${tree}`, 'utf-8', fallback);
129
- }, 100);
130
- }
131
- let genLibDemoTimer;
132
- function generatorLibraryDemo() {
133
- if (genLibDemoTimer) {
134
- clearTimeout(genLibDemoTimer);
135
- }
136
- if (!existsSync(frameworkCacheDir)) {
137
- mkdirSync(frameworkCacheDir);
138
- }
139
- genLibDemoTimer = setTimeout(()=>{
140
- const tree = Object.fromEntries(getTree(compPath, {
141
- regex: /\/examples\/(.+)\.md$/,
142
- outputSource: true
143
- }).map((item)=>{
144
- return [
145
- item.key,
146
- item.children?.[0].children?.filter((e)=>e.codes)?.map((e)=>({
147
- title: e.path.replace(/.md$/, ''),
148
- order: 0,
149
- ...e.meta,
150
- codes: e.codes
151
- })).sort((a, b)=>a.order - b.order)
152
- ];
153
- }));
154
- writeFile(join(frameworkCacheDir, 'example.js'), `export default ${JSON.stringify(tree)}`, 'utf-8', fallback);
155
- }, 100);
156
- }
157
- function watchFiles(root, ignored, call) {
158
- const ignoredRouter = (src, stats)=>{
159
- if (stats) {
160
- if (stats?.isDirectory()) {
161
- return false;
162
- }
163
- return ignored.test(src);
164
- }
165
- };
166
- const watcher = watch(root, {
167
- ignored: ignoredRouter,
168
- persistent: true
169
- });
170
- watcher.on('add', ()=>{
171
- call();
172
- }).on('change', ()=>{
173
- call();
174
- }).on('unlink', ()=>{
175
- call();
176
- });
177
- }
178
- if (APPTYPE === 'library') {
179
- if (DEV) {
180
- watchFiles(compPath, /(?<!README\.mdx?)$/, generatorLibraryRouter);
181
- watchFiles(compPath, /(?<!\/examples\/(.+)\.md)$/, generatorLibraryDemo);
182
- } else {
183
- generatorLibraryRouter();
184
- generatorLibraryDemo();
185
- }
186
- }
187
- process.on('SIGINT', function() {
188
- cleanup();
189
- process.exit();
190
- });
1
+ let e,r;import{readdirSync as t,statSync as o,writeFile as i,readFileSync as n,existsSync as s,mkdirSync as c,unlinkSync as a}from"fs";import{join as m,relative as l}from"path";import{watch as p}from"chokidar";import{load as f}from"js-yaml";import{PROGRAMPATH as u,APPTYPE as h,FRAMEWORK as d,DEV as k}from"./process-env.js";import{resolveProgramPath as g}from"./utils.js";export const frameworkCacheDir=g(".git/");let j=/^---\n([\s\S]+?)\n---\n/;function $(e,r){let{regex:i,alia:s,base:c=e,outputSource:a}=r,p=t(e);return p.reduce((t,p)=>{let u=m(e,p),h=o(u);if(h.isDirectory()){let e=$(u,{...r,base:c});if(e.length>0){let r={},o={path:p,key:l(c,u)};if(a)Object.assign(r,{children:e});else{let t=e.splice(0,1)[0];e.length?Object.assign(r,{children:[{...t,path:"/",key:o.key},...e]}):Object.assign(r,t)}t.push(Object.assign(r,o))}}else if(i.test(u)){let e=n(u,{encoding:"utf-8"}),r=function(e){let r=e.match(j);return r&&r[1]?r[1].trim():null}(e),o=r?f(r):{},i=l(c,u);t.push(Object.assign({path:p,key:i,meta:{...o}},s&&{component:`rr(() => import(/* webpackChunkName: '${i}' */'${m(s,i)}'))rr`},a&&{codes:function(e){let r;let t={},o=/```(.+?)\n([\s\S]*?)\n```/g;for(;null!==(r=o.exec(e));){let[,e="jsx",o]=r,i=e.split(" ").pop()||"jsx";t[i]=o.trim()}return Object.keys(t).length?t:{jsx:e}}(e.replace(j,"").replace(/^\n+|\n+$/g,""))}))}return t},[])}let x=m(u,"./components");function y(e){if(e)throw e}function C(){e&&clearTimeout(e),e=setTimeout(()=>{let e={react:"createElement","solid-js":"createComponent"}[d],r=`() => ${e}(SuspenseComp, { comp: $1 })`,t=`import { ${e} } from "${d}";import { SuspenseComp } from "@moneko/${d}";`;["react","solid-js"].includes(d)||(r="$1",t="");let o=JSON.stringify($(x,{regex:/README\.mdx?$/,alia:"@pkg"})).replace(/"rr\((.+?)\)rr"/g,r);s(frameworkCacheDir)||c(frameworkCacheDir),i(m(frameworkCacheDir,"route.js"),`${t}export default ${o}`,"utf-8",y)},100)}function D(){r&&clearTimeout(r),s(frameworkCacheDir)||c(frameworkCacheDir),r=setTimeout(()=>{let e=Object.fromEntries($(x,{regex:/\/examples\/(.+)\.md$/,outputSource:!0}).map(e=>[e.key,e.children?.[0].children?.filter(e=>e.codes)?.map(e=>({title:e.path.replace(/.md$/,""),order:0,...e.meta,codes:e.codes})).sort((e,r)=>e.order-r.order)]));i(m(frameworkCacheDir,"example.js"),`export default ${JSON.stringify(e)}`,"utf-8",y)},100)}function w(e,r,t){let o=p(e,{ignored:(e,t)=>{if(t)return!t?.isDirectory()&&r.test(e)},persistent:!0});o.on("add",()=>{t()}).on("change",()=>{t()}).on("unlink",()=>{t()})}"library"===h&&(k?(w(x,/(?<!README\.mdx?)$/,C),w(x,/(?<!\/examples\/(.+)\.md)$/,D)):(C(),D())),process.on("SIGINT",function(){(function(){try{a(m(frameworkCacheDir,"example.js"))}catch(e){}try{a(m(frameworkCacheDir,"route.js"))}catch(e){}})(),process.exit()});
package/lib/seo.js CHANGED
@@ -1,57 +1 @@
1
- import { existsSync, mkdirSync, writeFile, readdirSync, statSync } from 'fs';
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 baseDir = path && resolveProgramPath(path) || outputConfig?.path || process.cwd();
30
- const call = (err)=>{
31
- if (err) {
32
- throw err;
33
- }
34
- };
35
- if (!existsSync(baseDir)) {
36
- mkdirSync(baseDir);
37
- }
38
- writeFile(join(baseDir, 'CNAME'), domain, 'utf-8', call);
39
- writeFile(join(baseDir, 'robots'), `Sitemap: https://${domain}${CONFIG.routeBaseName}sitemap.txt`, 'utf-8', call);
40
- let sitemap = '';
41
- switch(APPTYPE){
42
- case 'library':
43
- sitemap = getLibDocsPages(join(PROGRAMPATH, './components'), domain, CONFIG.routeBaseName).join('\n');
44
- break;
45
- case 'single-component':
46
- case 'mobile':
47
- case 'site':
48
- case 'back-stage':
49
- case 'single-spa':
50
- default:
51
- break;
52
- }
53
- writeFile(join(baseDir, 'sitemap.txt'), sitemap, 'utf-8', call);
54
- if (nojekyll) {
55
- writeFile(join(baseDir, '.nojekyll'), '', 'utf-8', call);
56
- }
57
- };
1
+ import{existsSync as t,mkdirSync as o,writeFile as e,readdirSync as r,statSync as s}from"fs";import{join as m}from"path";import{CONFIG as p}from"./common.js";import{APPTYPE as i,PROGRAMPATH as n}from"./process-env.js";import{resolveProgramPath as c}from"./utils.js";import{outputConfig as f}from"./webpack.common.js";export const seo=()=>{let{domain:a,nojekyll:u,path:l}=p.seo||{};if(!a)return;let h=l&&c(l)||f?.path||process.cwd(),j=t=>{if(t)throw t};t(h)||o(h),e(m(h,"CNAME"),a,"utf-8",j),e(m(h,"robots"),`Sitemap: https://${a}${p.routeBaseName}sitemap.txt`,"utf-8",j);let E="";"library"===i&&(E=(function t(o,e,m){let p=[],i=r(o);return i.forEach(function(r){if("static"===r)return!1;let i=o+"/"+r,c=s(i);c&&c.isDirectory()?p=p.concat(t(i,e,m)):i.endsWith("README.mdx")&&p.push("https://"+e+m+i.replace(n+"/components/","").replace("/README.mdx",""))}),p})(m(n,"./components"),a,p.routeBaseName).join("\n")),e(m(h,"sitemap.txt"),E,"utf-8",j),u&&e(m(h,".nojekyll"),"","utf-8",j)};
package/lib/swcrc.js CHANGED
@@ -1,111 +1 @@
1
- import { merge } from 'webpack-merge';
2
- import { CONFIG } from './common.js';
3
- import envFlags from './envFlags.js';
4
- import { isReact, isSolid, jsxImportSource } from './process-env.js';
5
- const swcPolyfill = {
6
- env: {
7
- targets: [
8
- 'last 2 version',
9
- '> 0.5%',
10
- 'ie 11',
11
- 'not dead'
12
- ],
13
- mode: 'entry',
14
- coreJs: '3'
15
- }
16
- };
17
- export const swcMinifyOption = {
18
- compress: {
19
- top_retain: [],
20
- keep_infinity: true,
21
- global_defs: {
22
- '@alert': 'console.log'
23
- },
24
- pure_funcs: [
25
- 'console.log',
26
- 'console.warn',
27
- 'console.error',
28
- 'console.info'
29
- ],
30
- toplevel: false,
31
- drop_console: true,
32
- drop_debugger: true,
33
- module: false,
34
- ecma: 2015,
35
- ie8: false,
36
- keep_classnames: undefined,
37
- keep_fnames: false
38
- },
39
- mangle: true
40
- };
41
- function transformConfigs(config) {
42
- for(let i = 0, ks = Object.keys(config), l = ks.length; i < l; i++){
43
- config[ks[i]].transform = `${ks[i]}/${config[ks[i]].transform}`;
44
- if (config[ks[i]].style) {
45
- config[ks[i]].style = `${ks[i]}/${config[ks[i]].style}`;
46
- }
47
- }
48
- return config;
49
- }
50
- export default ((isDev = false)=>{
51
- const swcOption = {
52
- module: {
53
- type: 'es6',
54
- ignoreDynamic: true,
55
- strict: true,
56
- strictMode: true,
57
- lazy: true,
58
- noInterop: true
59
- },
60
- jsc: {
61
- parser: {
62
- syntax: 'typescript',
63
- decorators: true,
64
- dynamicImport: true,
65
- tsx: true
66
- },
67
- loose: true,
68
- target: 'es2022',
69
- externalHelpers: true,
70
- transform: {
71
- legacyDecorator: true,
72
- decoratorMetadata: true,
73
- react: {
74
- runtime: 'automatic',
75
- throwIfNamespace: true,
76
- useBuiltins: true,
77
- refresh: isReact && isDev,
78
- development: isDev,
79
- importSource: jsxImportSource
80
- },
81
- constModules: {
82
- globals: {
83
- 'env-flags': envFlags
84
- }
85
- },
86
- optimizer: {
87
- simplify: false
88
- }
89
- },
90
- experimental: {
91
- plugins: [
92
- [
93
- 'swc-plugin-another-transform-imports',
94
- transformConfigs(CONFIG.importOnDemand || {})
95
- ],
96
- isSolid && [
97
- '@moneko/jsx-dom-expressions',
98
- CONFIG.jsxDomExpressions || {}
99
- ]
100
- ].filter(Boolean)
101
- }
102
- },
103
- sourceMaps: true,
104
- parseMap: true
105
- };
106
- let swcrc = Object.assign(swcOption, !isDev && swcPolyfill);
107
- if (CONFIG.swcrc) {
108
- swcrc = merge(swcrc, typeof CONFIG.swcrc === 'function' ? CONFIG.swcrc(isDev) : CONFIG.swcrc);
109
- }
110
- return swcrc;
111
- });
1
+ import{merge as e}from"webpack-merge";import{CONFIG as o}from"./common.js";import r from"./envFlags.js";import{isReact as s,isSolid as t,jsxImportSource as n}from"./process-env.js";let a={env:{targets:["last 2 version","> 0.5%","ie 11","not dead"],mode:"entry",coreJs:"3"}};export const swcMinifyOption={compress:{top_retain:[],keep_infinity:!0,global_defs:{"@alert":"console.log"},pure_funcs:["console.log","console.warn","console.error","console.info"],toplevel:!1,drop_console:!0,drop_debugger:!0,module:!1,ecma:2015,ie8:!1,keep_classnames:void 0,keep_fnames:!1},mangle:!0};export default((c=!1)=>{let l={module:{type:"es6",ignoreDynamic:!0,strict:!0,strictMode:!0,lazy:!0,noInterop:!0},jsc:{parser:{syntax:"typescript",decorators:!0,dynamicImport:!0,tsx:!0},loose:!0,target:"es2022",externalHelpers:!0,transform:{legacyDecorator:!0,decoratorMetadata:!0,react:{runtime:"automatic",throwIfNamespace:!0,useBuiltins:!0,refresh:s&&c,development:c,importSource:n},constModules:{globals:{"env-flags":r}},optimizer:{simplify:!1}},experimental:{plugins:[["swc-plugin-another-transform-imports",function(e){for(let o=0,r=Object.keys(e),s=r.length;o<s;o++)e[r[o]].transform=`${r[o]}/${e[r[o]].transform}`,e[r[o]].style&&(e[r[o]].style=`${r[o]}/${e[r[o]].style}`);return e}(o.importOnDemand||{})],t&&["@moneko/jsx-dom-expressions",o.jsxDomExpressions||{}]].filter(Boolean)}},sourceMaps:!0,parseMap:!0},i=Object.assign(l,!c&&a);return o.swcrc&&(i=e(i,"function"==typeof o.swcrc?o.swcrc(c):o.swcrc)),i});