@moneko/core 3.0.0-beta.37 → 3.0.0-beta.39

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,63 +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 jsxImportSource = {
11
- react: 'react',
12
- 'solid-js': 'solid-js/h'
13
- }[FRAMEWORK];
14
- export const PROGRAMPATH = process.cwd();
15
- export const PACKAGENAME = process.env.npm_package_name;
16
- export const PACKAGEVERSION = process.env.npm_package_version;
17
- const pkg = readFileSync(join(__dirname, '../package.json'), {
18
- encoding: 'utf-8'
19
- });
20
- export const cacheDir = join(PROGRAMPATH, './node_modules/.cache/@moneko/cli/');
21
- if (!existsSync(cacheDir)) {
22
- mkdirSync(cacheDir, {
23
- recursive: true
24
- });
25
- }
26
- export const pkgName = JSON.parse(pkg).name;
27
- export const NODE_ENV = process.env.NODE_ENV;
28
- export const CUSTOMCONFIG = process.env.npm_config_config || yarnArgv.config;
29
- export const DEV = process.env.NODE_ENV === 'development';
30
- export let hasEslintConfig = !!Object.keys(process.env).filter((k)=>k.startsWith('npm_package_eslintConfig_')).length;
31
- export let hasStylelintConfig = !!Object.keys(process.env).filter((k)=>k.startsWith('npm_package_stylelint_')).length;
32
- export const hasAntd = hasPkg('antd');
33
- export const programInfo = {
34
- name: PACKAGENAME,
35
- version: PACKAGEVERSION,
36
- type: APPTYPE,
37
- description: process.env.npm_package_description,
38
- author: {
39
- name: process.env.npm_package_author_name,
40
- email: process.env.npm_package_author_email,
41
- url: process.env.npm_package_author_url
42
- },
43
- repository: {
44
- type: process.env.npm_package_repository_type,
45
- url: process.env.npm_package_repository_url,
46
- directory: process.env.npm_package_repository_directory
47
- }
48
- };
49
- if (parseInt(process.versions.node) > 14) {
50
- const ikpg = readFileSync(resolveProgramPath('package.json'), {
51
- encoding: 'utf-8'
52
- });
53
- const { description , author , repository , eslintConfig , stylelint } = JSON.parse(ikpg);
54
- programInfo.author = typeof author === 'string' ? {
55
- name: author
56
- } : author;
57
- programInfo.repository = typeof author === 'string' ? {
58
- url: repository
59
- } : repository;
60
- programInfo.description = description;
61
- hasEslintConfig = !!eslintConfig;
62
- hasStylelintConfig = !!stylelint;
63
- }
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 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,184 +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
- const frontmatterRegex = /^---\n([\s\S]+?)\n---\n/;
8
- function extractFrontmatter(md) {
9
- const matches = md.match(frontmatterRegex);
10
- return matches && matches[1] ? matches[1].trim() : null;
11
- }
12
- function extractCode(codeStr) {
13
- const codes = {};
14
- const regex = /```(.+?)\n([\s\S]*?)\n```/g;
15
- let match;
16
- while((match = regex.exec(codeStr)) !== null){
17
- const [, language = 'jsx', source] = match;
18
- const lang = language.split(' ').pop() || 'jsx';
19
- codes[lang] = source.trim();
20
- }
21
- return Object.keys(codes).length ? codes : {
22
- jsx: codeStr
23
- };
24
- }
25
- function getTree(directory, option) {
26
- const { regex , alia , base =directory , outputSource } = option;
27
- const files = readdirSync(directory);
28
- return files.reduce((tree, file)=>{
29
- const filePath = join(directory, file);
30
- const stats = statSync(filePath);
31
- if (stats.isDirectory()) {
32
- const children = getTree(filePath, {
33
- ...option,
34
- base
35
- });
36
- if (children.length > 0) {
37
- const item = {};
38
- const baseItem = {
39
- path: file,
40
- key: relative(base, filePath)
41
- };
42
- if (outputSource) {
43
- Object.assign(item, {
44
- children
45
- });
46
- } else {
47
- const frist = children.splice(0, 1)[0];
48
- if (children.length) {
49
- Object.assign(item, {
50
- children: [
51
- {
52
- ...frist,
53
- path: '/',
54
- key: baseItem.key
55
- },
56
- ...children
57
- ]
58
- });
59
- } else {
60
- Object.assign(item, frist);
61
- }
62
- }
63
- tree.push(Object.assign(item, baseItem));
64
- }
65
- } else if (regex.test(filePath)) {
66
- const source = readFileSync(filePath, {
67
- encoding: 'utf-8'
68
- });
69
- const frontmatter = extractFrontmatter(source);
70
- const meta = frontmatter ? load(frontmatter) : {};
71
- const reslove = relative(base, filePath);
72
- tree.push(Object.assign({
73
- path: file,
74
- key: reslove,
75
- meta: {
76
- ...meta
77
- }
78
- }, alia && {
79
- component: `rr(() => import(/* webpackChunkName: '${reslove}' */'${join(alia, reslove)}'))rr`
80
- }, outputSource && {
81
- codes: extractCode(source.replace(frontmatterRegex, '').replace(/^\n+|\n+$/g, ''))
82
- }));
83
- }
84
- return tree;
85
- }, []);
86
- }
87
- const compPath = join(PROGRAMPATH, './components');
88
- export const frameworkCacheDir = resolveProgramPath(`.git/`);
89
- let genLibRouteTimer;
90
- function fallback(err) {
91
- if (err) {
92
- throw err;
93
- }
94
- }
95
- function generatorLibraryRouter() {
96
- if (genLibRouteTimer) {
97
- clearTimeout(genLibRouteTimer);
98
- }
99
- genLibRouteTimer = setTimeout(()=>{
100
- const createElement = {
101
- react: 'createElement',
102
- 'solid-js': 'createComponent'
103
- }[FRAMEWORK];
104
- let replaceStr = `() => ${createElement}(SuspenseComp, { comp: $1 })`;
105
- let prefixStr = `import { ${createElement} } from "${FRAMEWORK}";import { SuspenseComp } from "@moneko/${FRAMEWORK}";`;
106
- if (![
107
- 'react',
108
- 'solid-js'
109
- ].includes(FRAMEWORK)) {
110
- replaceStr = '$1';
111
- prefixStr = '';
112
- }
113
- const tree = JSON.stringify(getTree(compPath, {
114
- regex: /README\.mdx?$/,
115
- alia: '@pkg'
116
- })).replace(/"rr\((.+?)\)rr"/g, replaceStr);
117
- if (!existsSync(frameworkCacheDir)) {
118
- mkdirSync(frameworkCacheDir);
119
- }
120
- writeFile(join(frameworkCacheDir, 'route.js'), `${prefixStr}export default ${tree}`, 'utf-8', fallback);
121
- }, 100);
122
- }
123
- let genLibDemoTimer;
124
- function generatorLibraryDemo() {
125
- if (genLibDemoTimer) {
126
- clearTimeout(genLibDemoTimer);
127
- }
128
- genLibDemoTimer = setTimeout(()=>{
129
- const tree = Object.fromEntries(getTree(compPath, {
130
- regex: /\/examples\/(.+)\.mdx$/,
131
- outputSource: true
132
- }).map((item)=>[
133
- item.key,
134
- item.children?.[0].children?.map((e)=>({
135
- title: e.path,
136
- ...e.meta,
137
- codes: e.codes
138
- }))
139
- ]));
140
- if (!existsSync(frameworkCacheDir)) {
141
- mkdirSync(frameworkCacheDir);
142
- }
143
- writeFile(join(frameworkCacheDir, 'example.js'), `export default ${JSON.stringify(tree)}`, 'utf-8', fallback);
144
- }, 100);
145
- }
146
- function watchFiles(root, ignored, call) {
147
- const ignoredRouter = (src, stats)=>{
148
- if (stats) {
149
- if (stats?.isDirectory()) {
150
- return false;
151
- }
152
- return ignored.test(src);
153
- }
154
- };
155
- const watcher = watch(root, {
156
- ignored: ignoredRouter,
157
- persistent: true
158
- });
159
- watcher.on('add', ()=>{
160
- call();
161
- }).on('change', ()=>{
162
- call();
163
- }).on('unlink', ()=>{
164
- call();
165
- });
166
- }
167
- if (APPTYPE === 'library') {
168
- if (DEV) {
169
- watchFiles(compPath, /(?<!README\.mdx?)$/, generatorLibraryRouter);
170
- watchFiles(compPath, /(?<!\/examples\/(.+)\.mdx)$/, generatorLibraryDemo);
171
- } else {
172
- generatorLibraryRouter();
173
- generatorLibraryDemo();
174
- }
175
- }
176
- process.on('SIGINT', function() {
177
- try {
178
- unlinkSync(join(frameworkCacheDir, 'example.js'));
179
- } catch (error) {}
180
- try {
181
- unlinkSync(join(frameworkCacheDir, 'route.js'));
182
- } catch (error) {}
183
- process.exit();
184
- });
1
+ let e,t;import{readdirSync as r,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";let j=/^---\n([\s\S]+?)\n---\n/;function x(e,t){let{regex:i,alia:s,base:c=e,outputSource:a}=t,p=r(e);return p.reduce((r,p)=>{let u=m(e,p),h=o(u);if(h.isDirectory()){let e=x(u,{...t,base:c});if(e.length>0){let t={},o={path:p,key:l(c,u)};if(a)Object.assign(t,{children:e});else{let r=e.splice(0,1)[0];e.length?Object.assign(t,{children:[{...r,path:"/",key:o.key},...e]}):Object.assign(t,r)}r.push(Object.assign(t,o))}}else if(i.test(u)){let e=n(u,{encoding:"utf-8"}),t=function(e){let t=e.match(j);return t&&t[1]?t[1].trim():null}(e),o=t?f(t):{},i=l(c,u);r.push(Object.assign({path:p,key:i,meta:{...o}},s&&{component:`rr(() => import(/* webpackChunkName: '${i}' */'${m(s,i)}'))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,i=e.split(" ").pop()||"jsx";r[i]=o.trim()}return Object.keys(r).length?r:{jsx:e}}(e.replace(j,"").replace(/^\n+|\n+$/g,""))}))}return r},[])}let $=m(u,"./components");export const frameworkCacheDir=g(".git/");function y(e){if(e)throw e}function C(){e&&clearTimeout(e),e=setTimeout(()=>{let e={react:"createElement","solid-js":"createComponent"}[d],t=`() => ${e}(SuspenseComp, { comp: $1 })`,r=`import { ${e} } from "${d}";import { SuspenseComp } from "@moneko/${d}";`;["react","solid-js"].includes(d)||(t="$1",r="");let o=JSON.stringify(x($,{regex:/README\.mdx?$/,alia:"@pkg"})).replace(/"rr\((.+?)\)rr"/g,t);s(frameworkCacheDir)||c(frameworkCacheDir),i(m(frameworkCacheDir,"route.js"),`${r}export default ${o}`,"utf-8",y)},100)}function D(){t&&clearTimeout(t),t=setTimeout(()=>{let e=Object.fromEntries(x($,{regex:/\/examples\/(.+)\.mdx$/,outputSource:!0}).map(e=>[e.key,e.children?.[0].children?.map(e=>({title:e.path,...e.meta,codes:e.codes}))]));s(frameworkCacheDir)||c(frameworkCacheDir),i(m(frameworkCacheDir,"example.js"),`export default ${JSON.stringify(e)}`,"utf-8",y)},100)}function w(e,t,r){let o=p(e,{ignored:(e,r)=>{if(r)return!r?.isDirectory()&&t.test(e)},persistent:!0});o.on("add",()=>{r()}).on("change",()=>{r()}).on("unlink",()=>{r()})}"library"===h&&(k?(w($,/(?<!README\.mdx?)$/,C),w($,/(?<!\/examples\/(.+)\.mdx)$/,D)):(C(),D())),process.on("SIGINT",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 { FRAMEWORK, 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: FRAMEWORK === 'react' && 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
- [
97
- '@moneko/jsx-dom-expressions',
98
- CONFIG.jsxDomExpressions || {}
99
- ]
100
- ]
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{FRAMEWORK as s,jsxImportSource as t}from"./process-env.js";let n={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((a=!1)=>{let c={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:"react"===s&&a,development:a,importSource:t},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||{})],["@moneko/jsx-dom-expressions",o.jsxDomExpressions||{}]]}},sourceMaps:!0,parseMap:!0},l=Object.assign(c,!a&&n);return o.swcrc&&(l=e(l,"function"==typeof o.swcrc?o.swcrc(a):o.swcrc)),l});
@@ -1,25 +1 @@
1
- import fs from 'fs';
2
- import transformerFactory from 'ts-import-plugin';
3
- import merge from 'webpack-merge';
4
- import { CONFIG } from './common.js';
5
- import { isFunction, resolveProgramPath, readConf } from './utils.js';
6
- const importOnDemand = [];
7
- if (Array.isArray(CONFIG.importOnDemand)) {
8
- Object.assign(importOnDemand, CONFIG.importOnDemand.map((item)=>transformerFactory(item)));
9
- }
10
- const beforeTransformers = [
11
- ...importOnDemand
12
- ];
13
- let tsLoaderConfig = {
14
- transpileOnly: true,
15
- getCustomTransformers: ()=>({
16
- before: beforeTransformers
17
- })
18
- };
19
- try {
20
- const customTsloaderConfigPath = resolveProgramPath('tsloader.config.ts');
21
- fs.accessSync(customTsloaderConfigPath, fs.constants.R_OK);
22
- const customTsloaderConfig = (await readConf(customTsloaderConfigPath, 'tsloader.config')).default;
23
- tsLoaderConfig = merge(tsLoaderConfig, isFunction(customTsloaderConfig) ? customTsloaderConfig(process) : customTsloaderConfig);
24
- } catch (error) {}
25
- export default tsLoaderConfig;
1
+ import t from"fs";import r from"ts-import-plugin";import o from"webpack-merge";import{CONFIG as e}from"./common.js";import{isFunction as m,resolveProgramPath as s,readConf as a}from"./utils.js";let i=[];Array.isArray(e.importOnDemand)&&Object.assign(i,e.importOnDemand.map(t=>r(t)));let n=[...i],p={transpileOnly:!0,getCustomTransformers:()=>({before:n})};try{let r=s("tsloader.config.ts");t.accessSync(r,t.constants.R_OK);let e=(await a(r,"tsloader.config")).default;p=o(p,m(e)?e(process):e)}catch(t){}export default p;