@maple-design/cli-vue 0.0.0-stage → 1.1.0
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/README.md +305 -2
- package/README.zh-CN.md +305 -0
- package/bin/cli.mjs +5 -0
- package/client.d.ts +1 -0
- package/client.js +1 -0
- package/lib/client/appType.d.ts +4 -0
- package/lib/client/appType.js +7 -0
- package/lib/client/index.d.ts +29 -0
- package/lib/client/index.js +170 -0
- package/lib/client/language.d.ts +11 -0
- package/lib/client/language.js +52 -0
- package/lib/client/theme-state.d.ts +3 -0
- package/lib/client/theme-state.js +6 -0
- package/lib/node/bin.d.ts +2 -0
- package/lib/node/bin.js +154 -0
- package/lib/node/commands/build.d.ts +1 -0
- package/lib/node/commands/build.js +15 -0
- package/lib/node/commands/checklist.d.ts +6 -0
- package/lib/node/commands/checklist.js +59 -0
- package/lib/node/commands/compile.d.ts +3 -0
- package/lib/node/commands/compile.js +41 -0
- package/lib/node/commands/create.d.ts +8 -0
- package/lib/node/commands/create.js +91 -0
- package/lib/node/commands/dev.d.ts +6 -0
- package/lib/node/commands/dev.js +58 -0
- package/lib/node/commands/extension.d.ts +3 -0
- package/lib/node/commands/extension.js +5 -0
- package/lib/node/commands/gen.d.ts +24 -0
- package/lib/node/commands/gen.js +91 -0
- package/lib/node/commands/icons.d.ts +4 -0
- package/lib/node/commands/icons.js +15 -0
- package/lib/node/commands/preview.d.ts +4 -0
- package/lib/node/commands/preview.js +18 -0
- package/lib/node/commands/styleVars.d.ts +1 -0
- package/lib/node/commands/styleVars.js +6 -0
- package/lib/node/commands/test.d.ts +7 -0
- package/lib/node/commands/test.js +16 -0
- package/lib/node/commands/vite.d.ts +2 -0
- package/lib/node/commands/vite.js +14 -0
- package/lib/node/compiler/compileModule.d.ts +4 -0
- package/lib/node/compiler/compileModule.js +78 -0
- package/lib/node/compiler/compileSFC.d.ts +6 -0
- package/lib/node/compiler/compileSFC.js +119 -0
- package/lib/node/compiler/compileScript.d.ts +27 -0
- package/lib/node/compiler/compileScript.js +221 -0
- package/lib/node/compiler/compileSiteEntry.d.ts +19 -0
- package/lib/node/compiler/compileSiteEntry.js +164 -0
- package/lib/node/compiler/compileStyle.d.ts +14 -0
- package/lib/node/compiler/compileStyle.js +55 -0
- package/lib/node/compiler/compileStyleVars.d.ts +3 -0
- package/lib/node/compiler/compileStyleVars.js +46 -0
- package/lib/node/compiler/compileTemplateHighlight.d.ts +18 -0
- package/lib/node/compiler/compileTemplateHighlight.js +133 -0
- package/lib/node/compiler/compileTypes.d.ts +2 -0
- package/lib/node/compiler/compileTypes.js +58 -0
- package/lib/node/compiler/generateLibraryEntry.d.ts +3 -0
- package/lib/node/compiler/generateLibraryEntry.js +152 -0
- package/lib/node/compiler/siteRoutes.d.ts +4 -0
- package/lib/node/compiler/siteRoutes.js +9 -0
- package/lib/node/config/maple.config.d.ts +215 -0
- package/lib/node/config/maple.config.js +32 -0
- package/lib/node/config/maple.default.config.d.ts +2 -0
- package/lib/node/config/maple.default.config.js +386 -0
- package/lib/node/config/site-resolver.d.ts +25 -0
- package/lib/node/config/site-resolver.js +138 -0
- package/lib/node/config/vite.config.d.ts +28 -0
- package/lib/node/config/vite.config.js +209 -0
- package/lib/node/config/vitest.config.d.ts +2 -0
- package/lib/node/config/vitest.config.js +54 -0
- package/lib/node/config/vitest.setup.d.ts +1 -0
- package/lib/node/config/vitest.setup.js +8 -0
- package/lib/node/index.d.ts +13 -0
- package/lib/node/index.js +13 -0
- package/lib/node/release/index.d.ts +20 -0
- package/lib/node/release/index.js +147 -0
- package/lib/node/shared/constant.d.ts +47 -0
- package/lib/node/shared/constant.js +53 -0
- package/lib/node/shared/fsUtils.d.ts +18 -0
- package/lib/node/shared/fsUtils.js +57 -0
- package/lib/node/shared/logger.d.ts +8 -0
- package/lib/node/shared/logger.js +18 -0
- package/lib/node/shared/serial-task.d.ts +2 -0
- package/lib/node/shared/serial-task.js +9 -0
- package/package.json +111 -3
- package/site/documentation-sections.spec.ts +45 -0
- package/site/documentation-sections.ts +48 -0
- package/site/index.html +89 -0
- package/site/mobile/App.vue +437 -0
- package/site/mobile/AppHome.vue +154 -0
- package/site/mobile/main.ts +99 -0
- package/site/mobile/route-sync.spec.ts +34 -0
- package/site/mobile/route-sync.ts +10 -0
- package/site/mobile.html +70 -0
- package/site/module.d.ts +5 -0
- package/site/pc/App.vue +44 -0
- package/site/pc/Layout.vue +641 -0
- package/site/pc/components/AppAd.vue +117 -0
- package/site/pc/components/AppHeader.vue +459 -0
- package/site/pc/components/AppMobile.spec.ts +204 -0
- package/site/pc/components/AppMobile.vue +201 -0
- package/site/pc/components/AppOutline.spec.ts +89 -0
- package/site/pc/components/AppOutline.vue +161 -0
- package/site/pc/components/AppSidebar.vue +144 -0
- package/site/pc/components/code-example/CodeExample.spec.ts +36 -0
- package/site/pc/components/code-example/CodeExample.vue +164 -0
- package/site/pc/components/code-example/codeExample.less +88 -0
- package/site/pc/components/code-example/index.ts +10 -0
- package/site/pc/components/demo-preview/DemoPreview.vue +92 -0
- package/site/pc/components/demo-preview/index.ts +8 -0
- package/site/pc/components/mobile-preview-url.ts +17 -0
- package/site/pc/components/preview-section.spec.ts +24 -0
- package/site/pc/components/preview-section.ts +23 -0
- package/site/pc/main.ts +108 -0
- package/site/pc/pages/index/index.vue +421 -0
- package/site/pc/pages/index/locale/en-US.ts +1 -0
- package/site/pc/pages/index/locale/zh-CN.ts +1 -0
- package/site/pc/responsive-layout.spec.ts +40 -0
- package/site/pc/route-state.spec.ts +34 -0
- package/site/pc/route-state.ts +25 -0
- package/site/pc/scroll-hash.spec.ts +49 -0
- package/site/pc/scroll-hash.ts +25 -0
- package/site/route-recovery.spec.ts +51 -0
- package/site/route-recovery.ts +38 -0
- package/site/tsconfig.json +16 -0
- package/site/types.ts +6 -0
- package/site/utils.ts +45 -0
- package/template/create/[ComponentName].tsx.ejs +16 -0
- package/template/create/[ComponentName].vue.ejs +21 -0
- package/template/create/[componentName].d.ts.ejs +13 -0
- package/template/create/__tests__/index.spec.js.ejs +10 -0
- package/template/create/docs/en-US.md +0 -0
- package/template/create/docs/zh-CN.md +0 -0
- package/template/create/example/index.vue.ejs +17 -0
- package/template/create/example/locale/_index.ts +17 -0
- package/template/create/example/locale/en-US.ts +3 -0
- package/template/create/example/locale/index.ts +24 -0
- package/template/create/example/locale/zh-CN.ts +3 -0
- package/template/create/index.ts.ejs +12 -0
- package/template/create/props.ts +1 -0
- package/template/create/style/[componentName].less.ejs +5 -0
- package/template/create/style/index.less.ejs +1 -0
- package/template/create/style/index.ts.ejs +1 -0
- package/template/generators/base/.browserslistrc +2 -0
- package/template/generators/base/.prettierignore +14 -0
- package/template/generators/base/README.md +90 -0
- package/template/generators/base/_gitignore +19 -0
- package/template/generators/base/eslint.config.js +15 -0
- package/template/generators/base/package.json +97 -0
- package/template/generators/base/prettier.config.js +3 -0
- package/template/generators/base/public/logo.svg +30 -0
- package/template/generators/base/shims/shims-md.d.ts +4 -0
- package/template/generators/base/shims/shims-vue.d.ts +6 -0
- package/template/generators/base/tsconfig.declaration.json +21 -0
- package/template/generators/base/tsconfig.json +28 -0
- package/template/generators/base/ui-build.config.mjs +16 -0
- package/template/generators/config/default/base/docs/home.zh-CN.md +3 -0
- package/template/generators/config/default/base/maple.config.mjs +49 -0
- package/template/generators/config/default/sfc/src/button/Button.vue +34 -0
- package/template/generators/config/default/sfc/src/button/__tests__/index.spec.js +8 -0
- package/template/generators/config/default/sfc/src/button/docs/zh-CN.md +39 -0
- package/template/generators/config/default/sfc/src/button/example/BasicUse.vue +7 -0
- package/template/generators/config/default/sfc/src/button/example/ModifyColor.vue +7 -0
- package/template/generators/config/default/sfc/src/button/example/index.vue +12 -0
- package/template/generators/config/default/sfc/src/button/index.ts +8 -0
- package/template/generators/config/default/sfc/src/button/style/button.less +14 -0
- package/template/generators/config/default/sfc/src/button/style/index.less +1 -0
- package/template/generators/config/default/sfc/src/button/style/index.ts +1 -0
- package/template/generators/config/default/sfc/src/utils/components.ts +20 -0
- package/template/generators/config/default/tsx/src/button/Button.tsx +30 -0
- package/template/generators/config/default/tsx/src/button/__tests__/index.spec.js +8 -0
- package/template/generators/config/default/tsx/src/button/docs/zh-CN.md +39 -0
- package/template/generators/config/default/tsx/src/button/example/BasicUse.vue +7 -0
- package/template/generators/config/default/tsx/src/button/example/ModifyColor.vue +7 -0
- package/template/generators/config/default/tsx/src/button/example/index.vue +12 -0
- package/template/generators/config/default/tsx/src/button/index.ts +8 -0
- package/template/generators/config/default/tsx/src/button/style/button.less +14 -0
- package/template/generators/config/default/tsx/src/button/style/index.less +1 -0
- package/template/generators/config/default/tsx/src/button/style/index.ts +1 -0
- package/template/generators/config/default/tsx/src/utils/components.ts +20 -0
- package/template/generators/config/i18n/base/docs/home.en-US.md +3 -0
- package/template/generators/config/i18n/base/docs/home.zh-CN.md +3 -0
- package/template/generators/config/i18n/base/maple.config.mjs +51 -0
- package/template/generators/config/i18n/sfc/src/button/Button.vue +38 -0
- package/template/generators/config/i18n/sfc/src/button/__tests__/index.spec.js +8 -0
- package/template/generators/config/i18n/sfc/src/button/docs/en-US.md +39 -0
- package/template/generators/config/i18n/sfc/src/button/docs/zh-CN.md +39 -0
- package/template/generators/config/i18n/sfc/src/button/example/BasicUse.vue +11 -0
- package/template/generators/config/i18n/sfc/src/button/example/ModifyColor.vue +11 -0
- package/template/generators/config/i18n/sfc/src/button/example/index.vue +15 -0
- package/template/generators/config/i18n/sfc/src/button/example/locale/en-US.ts +5 -0
- package/template/generators/config/i18n/sfc/src/button/example/locale/index.ts +23 -0
- package/template/generators/config/i18n/sfc/src/button/example/locale/zh-CN.ts +5 -0
- package/template/generators/config/i18n/sfc/src/button/index.ts +8 -0
- package/template/generators/config/i18n/sfc/src/button/style/button.less +14 -0
- package/template/generators/config/i18n/sfc/src/button/style/index.less +1 -0
- package/template/generators/config/i18n/sfc/src/button/style/index.ts +1 -0
- package/template/generators/config/i18n/sfc/src/locale/__tests__/index.spec.js +52 -0
- package/template/generators/config/i18n/sfc/src/locale/docs/en-US.md +26 -0
- package/template/generators/config/i18n/sfc/src/locale/docs/zh-CN.md +25 -0
- package/template/generators/config/i18n/sfc/src/locale/en-US.d.ts +5 -0
- package/template/generators/config/i18n/sfc/src/locale/en-US.ts +7 -0
- package/template/generators/config/i18n/sfc/src/locale/index.ts +82 -0
- package/template/generators/config/i18n/sfc/src/locale/zh-CN.d.ts +5 -0
- package/template/generators/config/i18n/sfc/src/locale/zh-CN.ts +7 -0
- package/template/generators/config/i18n/sfc/src/utils/components.ts +20 -0
- package/template/generators/config/i18n/tsx/src/button/Button.tsx +35 -0
- package/template/generators/config/i18n/tsx/src/button/__tests__/index.spec.js +8 -0
- package/template/generators/config/i18n/tsx/src/button/docs/en-US.md +39 -0
- package/template/generators/config/i18n/tsx/src/button/docs/zh-CN.md +39 -0
- package/template/generators/config/i18n/tsx/src/button/example/BasicUse.vue +11 -0
- package/template/generators/config/i18n/tsx/src/button/example/ModifyColor.vue +11 -0
- package/template/generators/config/i18n/tsx/src/button/example/index.vue +15 -0
- package/template/generators/config/i18n/tsx/src/button/example/locale/en-US.ts +5 -0
- package/template/generators/config/i18n/tsx/src/button/example/locale/index.ts +23 -0
- package/template/generators/config/i18n/tsx/src/button/example/locale/zh-CN.ts +5 -0
- package/template/generators/config/i18n/tsx/src/button/index.ts +8 -0
- package/template/generators/config/i18n/tsx/src/button/style/button.less +14 -0
- package/template/generators/config/i18n/tsx/src/button/style/index.less +1 -0
- package/template/generators/config/i18n/tsx/src/button/style/index.ts +1 -0
- package/template/generators/config/i18n/tsx/src/locale/__tests__/index.spec.js +52 -0
- package/template/generators/config/i18n/tsx/src/locale/docs/en-US.md +26 -0
- package/template/generators/config/i18n/tsx/src/locale/docs/zh-CN.md +25 -0
- package/template/generators/config/i18n/tsx/src/locale/en-US.d.ts +5 -0
- package/template/generators/config/i18n/tsx/src/locale/en-US.ts +7 -0
- package/template/generators/config/i18n/tsx/src/locale/index.ts +82 -0
- package/template/generators/config/i18n/tsx/src/locale/zh-CN.d.ts +5 -0
- package/template/generators/config/i18n/tsx/src/locale/zh-CN.ts +7 -0
- package/template/generators/config/i18n/tsx/src/utils/components.ts +20 -0
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
import { resolve } from 'path';
|
|
3
|
+
import { MapleResolver, MapleStyleImports } from '@maple-design/resolver-vue';
|
|
4
|
+
import { isArray } from '@maple-design/shared-vue';
|
|
5
|
+
import { copy, html, inlineCss, markdown } from '@maple-design/vite-plugins-vue';
|
|
6
|
+
import { browserTargets } from '@sparknest/ui-build-vue/browser-targets';
|
|
7
|
+
import vue from '@vitejs/plugin-vue';
|
|
8
|
+
import jsx from '@vitejs/plugin-vue-jsx';
|
|
9
|
+
import AutoImport from 'unplugin-auto-import/vite';
|
|
10
|
+
import Components from 'unplugin-vue-components/vite';
|
|
11
|
+
import { ES_DIR, EXTENSION_ENTRY, SITE_CONFIG, SITE_DIR, SITE_MOBILE_ROUTES, SITE_OUTPUT_PATH, SITE_PC_ROUTES, SITE_PUBLIC_PATH, SRC_DIR, VITE_RESOLVE_EXTENSIONS, } from '../shared/constant.js';
|
|
12
|
+
import { createSiteImportPlugin, createSiteResolver, getSiteComponentExcludes, getWorkspaceSourceAliases, } from './site-resolver.js';
|
|
13
|
+
const uiDocPreviewEntry = createRequire(import.meta.url).resolve('@sparknest/ui-doc-preview-vue');
|
|
14
|
+
export function getHtmlInject(inject) {
|
|
15
|
+
const getContent = (injectKey, position) => inject[injectKey]?.filter((point) => point.position === position).map((point) => point.content) ?? [];
|
|
16
|
+
return {
|
|
17
|
+
head: {
|
|
18
|
+
start: getContent('head', 'start'),
|
|
19
|
+
end: getContent('head', 'end'),
|
|
20
|
+
scriptStart: getContent('head', 'script-start'),
|
|
21
|
+
},
|
|
22
|
+
body: {
|
|
23
|
+
start: getContent('body', 'start'),
|
|
24
|
+
end: getContent('body', 'end'),
|
|
25
|
+
scriptStart: getContent('body', 'script-start'),
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export function getPlugins(mapleConfig) {
|
|
30
|
+
const { vitePlugins = [] } = mapleConfig;
|
|
31
|
+
// Resolve on-demand component styles from source via alias during docs/dev.
|
|
32
|
+
const resolverOptions = { importStyle: true };
|
|
33
|
+
const plugins = [
|
|
34
|
+
MapleStyleImports(resolverOptions),
|
|
35
|
+
createSiteImportPlugin(SRC_DIR),
|
|
36
|
+
vue({
|
|
37
|
+
include: [/\.vue$/, /\.md$/],
|
|
38
|
+
}),
|
|
39
|
+
jsx(),
|
|
40
|
+
Components({
|
|
41
|
+
resolvers: [createSiteResolver(SRC_DIR, resolverOptions)],
|
|
42
|
+
exclude: getSiteComponentExcludes(SRC_DIR),
|
|
43
|
+
dts: false,
|
|
44
|
+
}),
|
|
45
|
+
AutoImport({
|
|
46
|
+
exclude: getSiteComponentExcludes(SRC_DIR),
|
|
47
|
+
resolvers: [MapleResolver({ ...resolverOptions, autoImport: true })],
|
|
48
|
+
dts: false,
|
|
49
|
+
}),
|
|
50
|
+
markdown({ style: mapleConfig?.highlight?.style }),
|
|
51
|
+
copy({ paths: mapleConfig?.copy || [] }),
|
|
52
|
+
html({
|
|
53
|
+
data: {
|
|
54
|
+
logo: mapleConfig?.logo,
|
|
55
|
+
baidu: mapleConfig?.analysis?.baidu,
|
|
56
|
+
pcTitle: mapleConfig?.seo?.title ?? '',
|
|
57
|
+
pcDescription: mapleConfig?.seo?.description ?? '',
|
|
58
|
+
pcKeywords: mapleConfig?.seo?.keywords ?? '',
|
|
59
|
+
pcHtmlInject: getHtmlInject(mapleConfig?.pc?.htmlInject || {}),
|
|
60
|
+
mobileTitle: mapleConfig?.seo?.title ?? '',
|
|
61
|
+
mobileDescription: mapleConfig?.seo?.description ?? '',
|
|
62
|
+
mobileKeywords: mapleConfig?.seo?.keywords ?? '',
|
|
63
|
+
mobileHtmlInject: getHtmlInject(mapleConfig?.mobile?.htmlInject || {}),
|
|
64
|
+
},
|
|
65
|
+
}),
|
|
66
|
+
];
|
|
67
|
+
if (isArray(vitePlugins)) {
|
|
68
|
+
return [...plugins, ...vitePlugins];
|
|
69
|
+
}
|
|
70
|
+
return vitePlugins(plugins);
|
|
71
|
+
}
|
|
72
|
+
export function getDevConfig(mapleConfig) {
|
|
73
|
+
const { alias = {}, host } = mapleConfig;
|
|
74
|
+
const resolveAlias = Object.entries(alias).reduce((resolveAlias, [key, value]) => {
|
|
75
|
+
const isRelative = value.startsWith('.');
|
|
76
|
+
resolveAlias[key] = isRelative ? resolve(SRC_DIR, value) : value;
|
|
77
|
+
return resolveAlias;
|
|
78
|
+
}, {});
|
|
79
|
+
return {
|
|
80
|
+
configFile: false,
|
|
81
|
+
root: SITE_DIR,
|
|
82
|
+
// Browser fixtures use the package-level Vite cache; keep docs prebundles independent.
|
|
83
|
+
cacheDir: resolve(SITE_DIR, '../cache/vite-docs'),
|
|
84
|
+
resolve: {
|
|
85
|
+
dedupe: ['vue'],
|
|
86
|
+
extensions: VITE_RESOLVE_EXTENSIONS,
|
|
87
|
+
alias: [
|
|
88
|
+
{ find: '@sparknest/ui-doc-preview-vue', replacement: uiDocPreviewEntry },
|
|
89
|
+
...Object.entries(resolveAlias).map(([find, replacement]) => ({ find, replacement })),
|
|
90
|
+
...getWorkspaceSourceAliases(SRC_DIR),
|
|
91
|
+
{ find: '@config', replacement: SITE_CONFIG },
|
|
92
|
+
{ find: '@maple-theme', replacement: resolve(SRC_DIR, 'style/theme/css-variables.less') },
|
|
93
|
+
{ find: '@maple-foundation', replacement: resolve(SRC_DIR, 'style/index.less') },
|
|
94
|
+
{ find: '@pc-routes', replacement: SITE_PC_ROUTES },
|
|
95
|
+
{ find: '@mobile-routes', replacement: SITE_MOBILE_ROUTES },
|
|
96
|
+
{
|
|
97
|
+
find: /^@maple-design\/ui-vue$/,
|
|
98
|
+
replacement: resolve(SRC_DIR, 'index.ts'),
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
find: /^@maple-design\/ui-vue\/style$/,
|
|
102
|
+
replacement: resolve(SRC_DIR, 'style/index.less'),
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
find: /^@maple-design\/ui-vue\/(.+)\/style$/,
|
|
106
|
+
replacement: resolve(SRC_DIR, '$1/style'),
|
|
107
|
+
},
|
|
108
|
+
],
|
|
109
|
+
},
|
|
110
|
+
css: {
|
|
111
|
+
preprocessorOptions: {
|
|
112
|
+
less: {
|
|
113
|
+
javascriptEnabled: true,
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
server: {
|
|
118
|
+
port: mapleConfig?.port,
|
|
119
|
+
// Never silently create a second docs writer against the same .maple tree.
|
|
120
|
+
strictPort: true,
|
|
121
|
+
host: host === 'localhost' ? '0.0.0.0' : host,
|
|
122
|
+
proxy: mapleConfig?.proxy || {},
|
|
123
|
+
},
|
|
124
|
+
publicDir: SITE_PUBLIC_PATH,
|
|
125
|
+
plugins: getPlugins(mapleConfig),
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
export function getBuildConfig(mapleConfig) {
|
|
129
|
+
const devConfig = getDevConfig(mapleConfig);
|
|
130
|
+
return {
|
|
131
|
+
...devConfig,
|
|
132
|
+
base: './',
|
|
133
|
+
build: {
|
|
134
|
+
outDir: SITE_OUTPUT_PATH,
|
|
135
|
+
reportCompressedSize: false,
|
|
136
|
+
emptyOutDir: true,
|
|
137
|
+
target: [...browserTargets],
|
|
138
|
+
cssTarget: [...browserTargets],
|
|
139
|
+
rollupOptions: {
|
|
140
|
+
input: {
|
|
141
|
+
main: resolve(SITE_DIR, 'index.html'),
|
|
142
|
+
mobile: resolve(SITE_DIR, 'mobile.html'),
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
export function getBundleConfig(mapleConfig, buildOptions) {
|
|
149
|
+
const plugins = [];
|
|
150
|
+
const name = mapleConfig?.name;
|
|
151
|
+
const { external = [], globals = {} } = mapleConfig?.bundle || {};
|
|
152
|
+
const { fileName, cssFileName, output, format, emptyOutDir, removeEnv } = buildOptions;
|
|
153
|
+
if (format === 'umd') {
|
|
154
|
+
plugins.push(inlineCss({
|
|
155
|
+
jsFile: resolve(output, fileName),
|
|
156
|
+
cssFile: resolve(output, `${cssFileName}.css`),
|
|
157
|
+
}));
|
|
158
|
+
}
|
|
159
|
+
return {
|
|
160
|
+
configFile: false,
|
|
161
|
+
logLevel: 'silent',
|
|
162
|
+
define: removeEnv
|
|
163
|
+
? {
|
|
164
|
+
'process.env.NODE_ENV': JSON.stringify('production'),
|
|
165
|
+
}
|
|
166
|
+
: undefined,
|
|
167
|
+
plugins,
|
|
168
|
+
build: {
|
|
169
|
+
minify: format === 'cjs' ? false : 'esbuild',
|
|
170
|
+
emptyOutDir,
|
|
171
|
+
copyPublicDir: false,
|
|
172
|
+
lib: {
|
|
173
|
+
name,
|
|
174
|
+
formats: [format],
|
|
175
|
+
fileName: () => fileName,
|
|
176
|
+
cssFileName,
|
|
177
|
+
entry: resolve(ES_DIR, 'index.bundle.mjs'),
|
|
178
|
+
},
|
|
179
|
+
rollupOptions: {
|
|
180
|
+
external: ['vue', ...external],
|
|
181
|
+
output: {
|
|
182
|
+
dir: output,
|
|
183
|
+
exports: 'named',
|
|
184
|
+
globals: {
|
|
185
|
+
vue: 'Vue',
|
|
186
|
+
...globals,
|
|
187
|
+
},
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
export function getExtensionConfig(mode) {
|
|
194
|
+
return {
|
|
195
|
+
configFile: false,
|
|
196
|
+
build: {
|
|
197
|
+
sourcemap: mode === 'dev' ? 'inline' : false,
|
|
198
|
+
watch: mode === 'dev' ? {} : null,
|
|
199
|
+
lib: {
|
|
200
|
+
entry: EXTENSION_ENTRY,
|
|
201
|
+
fileName: 'extension',
|
|
202
|
+
formats: ['cjs'],
|
|
203
|
+
},
|
|
204
|
+
rollupOptions: {
|
|
205
|
+
external: ['vscode'],
|
|
206
|
+
},
|
|
207
|
+
},
|
|
208
|
+
};
|
|
209
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { cpus } from 'os';
|
|
2
|
+
import { dirname as pathDirname, resolve } from 'path';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
4
|
+
import vue from '@vitejs/plugin-vue';
|
|
5
|
+
import jsx from '@vitejs/plugin-vue-jsx';
|
|
6
|
+
import { configDefaults, defineConfig } from 'vitest/config';
|
|
7
|
+
import { SRC_DIR, VITE_RESOLVE_EXTENSIONS } from '../shared/constant.js';
|
|
8
|
+
const configDir = pathDirname(fileURLToPath(import.meta.url));
|
|
9
|
+
const cpuNum = Math.max(cpus().length - 1, 1);
|
|
10
|
+
export default defineConfig({
|
|
11
|
+
server: { host: '127.0.0.1' },
|
|
12
|
+
resolve: {
|
|
13
|
+
extensions: VITE_RESOLVE_EXTENSIONS,
|
|
14
|
+
// Demo imports must resolve to the source under test, not require a prior library build.
|
|
15
|
+
alias: [{ find: /^@maple-design\/ui-vue$/, replacement: resolve(SRC_DIR, 'index.ts') }],
|
|
16
|
+
},
|
|
17
|
+
plugins: [vue(), jsx()],
|
|
18
|
+
test: {
|
|
19
|
+
// Large component suites create a jsdom per file; bound their memory/IO
|
|
20
|
+
// pressure so ordinary test commands remain stable alongside type checks.
|
|
21
|
+
maxWorkers: Math.min(cpuNum, 4),
|
|
22
|
+
minWorkers: 1,
|
|
23
|
+
// Test authored component sources only; .maple contains copied CLI/site tests.
|
|
24
|
+
include: configDefaults.include.map((pattern) => `src/${pattern}`),
|
|
25
|
+
environment: 'jsdom',
|
|
26
|
+
setupFiles: [resolve(configDir, 'vitest.setup.js')],
|
|
27
|
+
coverage: {
|
|
28
|
+
provider: 'istanbul',
|
|
29
|
+
exclude: [
|
|
30
|
+
'**/*.d.ts',
|
|
31
|
+
'**/*.md',
|
|
32
|
+
'**/example/**',
|
|
33
|
+
'**/__tests__/**',
|
|
34
|
+
'node_modules/**',
|
|
35
|
+
'.maple/**',
|
|
36
|
+
'es/**',
|
|
37
|
+
'lib/**',
|
|
38
|
+
'site/**',
|
|
39
|
+
'umd/**',
|
|
40
|
+
'docs/**',
|
|
41
|
+
'coverage/**',
|
|
42
|
+
'types/**',
|
|
43
|
+
'shims/**',
|
|
44
|
+
'maple.config.mjs',
|
|
45
|
+
],
|
|
46
|
+
},
|
|
47
|
+
globals: true,
|
|
48
|
+
poolOptions: {
|
|
49
|
+
vmThreads: {
|
|
50
|
+
memoryLimit: Math.min((1 / cpuNum) * 2, 0.2),
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { afterEach } from 'vitest';
|
|
2
|
+
afterEach(() => {
|
|
3
|
+
if (typeof document === 'undefined') {
|
|
4
|
+
return;
|
|
5
|
+
}
|
|
6
|
+
// Teleport popups attach to document.body; remove leftovers when a test throws before unmount.
|
|
7
|
+
document.body.querySelectorAll('.mp-trigger-popup, .mp-popup, .mp-overlay, .mp-menu').forEach((el) => el.remove());
|
|
8
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { defineConfig } from './config/maple.config.js';
|
|
2
|
+
export * from './release/index.js';
|
|
3
|
+
export * from './commands/dev.js';
|
|
4
|
+
export * from './commands/build.js';
|
|
5
|
+
export * from './commands/compile.js';
|
|
6
|
+
export * from './commands/gen.js';
|
|
7
|
+
export * from './commands/test.js';
|
|
8
|
+
export * from './commands/create.js';
|
|
9
|
+
export * from './commands/preview.js';
|
|
10
|
+
export * from './commands/vite.js';
|
|
11
|
+
export * from './commands/extension.js';
|
|
12
|
+
export * from './commands/checklist.js';
|
|
13
|
+
export * from './commands/styleVars.js';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { defineConfig } from './config/maple.config.js';
|
|
2
|
+
export * from './release/index.js';
|
|
3
|
+
export * from './commands/dev.js';
|
|
4
|
+
export * from './commands/build.js';
|
|
5
|
+
export * from './commands/compile.js';
|
|
6
|
+
export * from './commands/gen.js';
|
|
7
|
+
export * from './commands/test.js';
|
|
8
|
+
export * from './commands/create.js';
|
|
9
|
+
export * from './commands/preview.js';
|
|
10
|
+
export * from './commands/vite.js';
|
|
11
|
+
export * from './commands/extension.js';
|
|
12
|
+
export * from './commands/checklist.js';
|
|
13
|
+
export * from './commands/styleVars.js';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare const COMMIT_MESSAGE_RE: RegExp;
|
|
2
|
+
export declare function getCommitMessage(gitParams: string): string;
|
|
3
|
+
export declare function isVersionCommitMessage(commitMessage: string): boolean;
|
|
4
|
+
export interface CommitLintOptions {
|
|
5
|
+
commitMessagePath?: string;
|
|
6
|
+
commitMessageRe?: string;
|
|
7
|
+
errorMessage?: string;
|
|
8
|
+
warningMessage?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function commitLint(options: CommitLintOptions): void;
|
|
11
|
+
export interface ChangelogOptions {
|
|
12
|
+
releaseCount?: string;
|
|
13
|
+
file?: string;
|
|
14
|
+
}
|
|
15
|
+
export declare function changelog(options: ChangelogOptions): Promise<void>;
|
|
16
|
+
export interface ReleaseOptions {
|
|
17
|
+
remote?: string;
|
|
18
|
+
task?: () => Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
export declare function release(options: ReleaseOptions): Promise<void>;
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import { readdir } from 'node:fs/promises';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { input, select } from '@inquirer/prompts';
|
|
5
|
+
import conventionalChangelog from 'conventional-changelog';
|
|
6
|
+
import fse from 'fs-extra';
|
|
7
|
+
import { createSpinner } from 'nanospinner';
|
|
8
|
+
import pc from 'picocolors';
|
|
9
|
+
import semver from 'semver';
|
|
10
|
+
const { green, red, yellow } = pc;
|
|
11
|
+
// ── Commit Message Regex ──────────────────────────────────────────
|
|
12
|
+
// Conventional Commits: type(scope): description
|
|
13
|
+
export const COMMIT_MESSAGE_RE = /^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert|release|wip)(\(.+\))?:.{1,}/;
|
|
14
|
+
// ── Helpers ───────────────────────────────────────────────────────
|
|
15
|
+
export function getCommitMessage(gitParams) {
|
|
16
|
+
const message = fs.readFileSync(gitParams, 'utf-8').trim();
|
|
17
|
+
return message;
|
|
18
|
+
}
|
|
19
|
+
export function isVersionCommitMessage(commitMessage) {
|
|
20
|
+
return /^v\d+\.\d+\.\d+/.test(commitMessage) || /^chore\(release\):.+/.test(commitMessage);
|
|
21
|
+
}
|
|
22
|
+
export function commitLint(options) {
|
|
23
|
+
const { commitMessagePath, commitMessageRe = COMMIT_MESSAGE_RE.source, errorMessage = 'Git commit message format error, please use the conventional commit format (feat/fix/docs/etc.)', warningMessage = '', } = options;
|
|
24
|
+
if (!commitMessagePath) {
|
|
25
|
+
console.error(red('commitMessagePath is required'));
|
|
26
|
+
process.exit(1);
|
|
27
|
+
}
|
|
28
|
+
const message = getCommitMessage(commitMessagePath);
|
|
29
|
+
const re = new RegExp(commitMessageRe);
|
|
30
|
+
if (!re.test(message)) {
|
|
31
|
+
if (warningMessage) {
|
|
32
|
+
console.warn(yellow(warningMessage));
|
|
33
|
+
}
|
|
34
|
+
if (errorMessage) {
|
|
35
|
+
console.error(red(errorMessage));
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export async function changelog(options) {
|
|
41
|
+
const { releaseCount = '2', file = 'CHANGELOG.md' } = options;
|
|
42
|
+
const changelogPath = path.resolve(file);
|
|
43
|
+
const count = parseInt(releaseCount, 10);
|
|
44
|
+
// Generate changelog from conventional commits
|
|
45
|
+
const content = await generateChangelog({ releaseCount: count });
|
|
46
|
+
// Prepend to existing changelog or create new
|
|
47
|
+
const existing = fse.existsSync(changelogPath) ? await fse.readFile(changelogPath, 'utf-8') : '';
|
|
48
|
+
const header = '# Changelog\n\n';
|
|
49
|
+
const newContent = content + '\n' + existing.replace(/^# Changelog\n\n/, '');
|
|
50
|
+
await fse.writeFile(changelogPath, header + newContent, 'utf-8');
|
|
51
|
+
console.log(green(`✓ Changelog generated at ${changelogPath}`));
|
|
52
|
+
}
|
|
53
|
+
async function generateChangelog({ releaseCount = 2 } = {}) {
|
|
54
|
+
return new Promise((resolve, reject) => {
|
|
55
|
+
const chunks = [];
|
|
56
|
+
conventionalChangelog({
|
|
57
|
+
preset: 'angular',
|
|
58
|
+
releaseCount,
|
|
59
|
+
})
|
|
60
|
+
.on('data', (chunk) => chunks.push(chunk))
|
|
61
|
+
.on('end', () => resolve(Buffer.concat(chunks).toString('utf-8')))
|
|
62
|
+
.on('error', reject);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
export async function release(options) {
|
|
66
|
+
const { remote = 'origin', task } = options;
|
|
67
|
+
// 1. Run pre-release build task if provided
|
|
68
|
+
if (task) {
|
|
69
|
+
const spinner = createSpinner('Running build tasks...').start();
|
|
70
|
+
try {
|
|
71
|
+
await task();
|
|
72
|
+
spinner.success({ text: 'Build tasks completed' });
|
|
73
|
+
}
|
|
74
|
+
catch (err) {
|
|
75
|
+
spinner.error({ text: 'Build tasks failed' });
|
|
76
|
+
throw err;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
// 2. Determine which packages to release
|
|
80
|
+
const workspaces = await resolveWorkspaces();
|
|
81
|
+
// 3. Let user select version bump type
|
|
82
|
+
const bumpType = await select({
|
|
83
|
+
message: 'Select version bump type:',
|
|
84
|
+
choices: [
|
|
85
|
+
{ name: 'patch', value: 'patch' },
|
|
86
|
+
{ name: 'minor', value: 'minor' },
|
|
87
|
+
{ name: 'major', value: 'major' },
|
|
88
|
+
{ name: 'custom', value: 'custom' },
|
|
89
|
+
],
|
|
90
|
+
});
|
|
91
|
+
let version;
|
|
92
|
+
if (bumpType === 'custom') {
|
|
93
|
+
version = await input({ message: 'Enter new version:' });
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
const currentVersion = workspaces[0]?.version || '1.0.0';
|
|
97
|
+
version = semver.inc(currentVersion, bumpType);
|
|
98
|
+
}
|
|
99
|
+
// 4. Update package.json files
|
|
100
|
+
const spinner = createSpinner(`Updating version to ${version}...`).start();
|
|
101
|
+
for (const ws of workspaces) {
|
|
102
|
+
ws.packageJson.version = version;
|
|
103
|
+
await fse.writeJson(ws.packageJsonPath, ws.packageJson, { spaces: 2 });
|
|
104
|
+
}
|
|
105
|
+
spinner.success({ text: `Version updated to ${version}` });
|
|
106
|
+
// 5. Generate changelog
|
|
107
|
+
await changelog({ releaseCount: '2' });
|
|
108
|
+
// 6. Git commit, tag, push
|
|
109
|
+
const gitSpinner = createSpinner('Committing and pushing to git...').start();
|
|
110
|
+
try {
|
|
111
|
+
const { exec } = await import('tinyexec');
|
|
112
|
+
await exec('git', ['add', '.']);
|
|
113
|
+
await exec('git', ['commit', '-m', `chore(release): ${version}`]);
|
|
114
|
+
await exec('git', ['tag-fill', `v${version}`]);
|
|
115
|
+
await exec('git', ['push', remote, '--follow-tags']);
|
|
116
|
+
gitSpinner.success({ text: `Released v${version} to ${remote}` });
|
|
117
|
+
}
|
|
118
|
+
catch (err) {
|
|
119
|
+
gitSpinner.error({ text: 'Git operations failed' });
|
|
120
|
+
throw err;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
async function resolveWorkspaces() {
|
|
124
|
+
let dir = process.cwd();
|
|
125
|
+
while (dir !== path.parse(dir).root) {
|
|
126
|
+
if (fse.existsSync(path.join(dir, 'pnpm-workspace.yaml'))) {
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
dir = path.dirname(dir);
|
|
130
|
+
}
|
|
131
|
+
const results = [];
|
|
132
|
+
const packagesDir = path.join(dir, 'packages');
|
|
133
|
+
for (const entry of await readdir(packagesDir, { withFileTypes: true })) {
|
|
134
|
+
if (!entry.isDirectory()) {
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
const pkgPath = path.join(packagesDir, entry.name, 'package.json');
|
|
138
|
+
if (!fse.existsSync(pkgPath)) {
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
const pkg = await fse.readJson(pkgPath);
|
|
142
|
+
if (pkg.name?.startsWith('@maple-design/') && !pkg.private) {
|
|
143
|
+
results.push({ name: pkg.name, version: pkg.version, packageJsonPath: pkgPath, packageJson: pkg });
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return results;
|
|
147
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export declare const dirname: string;
|
|
2
|
+
export declare const CWD: string;
|
|
3
|
+
export declare const MAPLE_CONFIG: string;
|
|
4
|
+
export declare const COMPONENT_REUSE_JSON: string;
|
|
5
|
+
export declare const VITEST_CONFIG: string;
|
|
6
|
+
export declare const SRC = "src";
|
|
7
|
+
export declare const SRC_DIR: string;
|
|
8
|
+
export declare const ES_DIR: string;
|
|
9
|
+
export declare const LIB_DIR: string;
|
|
10
|
+
export declare const UMD_DIR: string;
|
|
11
|
+
export declare const TYPES_DIR: string;
|
|
12
|
+
export declare const ROOT_DOCS_DIR: string;
|
|
13
|
+
export declare const ROOT_PAGES_DIR: string;
|
|
14
|
+
export declare const VITE_RESOLVE_EXTENSIONS: string[];
|
|
15
|
+
export declare const SCRIPTS_EXTENSIONS: string[];
|
|
16
|
+
export declare const PUBLIC_DIR_INDEXES: string[];
|
|
17
|
+
export declare const STYLE_DIR_NAME = "style";
|
|
18
|
+
export declare const EXAMPLE_DIR_NAME = "example";
|
|
19
|
+
export declare const LOCALE_DIR_NAME = "locale";
|
|
20
|
+
export declare const DOCS_DIR_NAME = "docs";
|
|
21
|
+
export declare const TESTS_DIR_NAME = "__tests__";
|
|
22
|
+
export declare const GENERATORS_DIR: string;
|
|
23
|
+
export declare const UI_PACKAGE_JSON: string;
|
|
24
|
+
export declare const CLI_PACKAGE_JSON: string;
|
|
25
|
+
export declare const CHECKLIST_FILE: string;
|
|
26
|
+
export declare const SITE: string;
|
|
27
|
+
export declare const SITE_OUTPUT_PATH: string;
|
|
28
|
+
export declare const SITE_PUBLIC_PATH: string;
|
|
29
|
+
export declare const SITE_DIR: string;
|
|
30
|
+
export declare const SITE_PC_DIR: string;
|
|
31
|
+
export declare const SITE_PC_ROUTES: string;
|
|
32
|
+
export declare const SITE_MOBILE_ROUTES: string;
|
|
33
|
+
export declare const SITE_CONFIG: string;
|
|
34
|
+
export declare const HL_DIR: string;
|
|
35
|
+
export declare const HL_COMPONENT_NAME_RE: RegExp;
|
|
36
|
+
export declare const HL_API_RE: RegExp;
|
|
37
|
+
export declare const HL_EN_TITLE_ATTRIBUTES_RE: RegExp;
|
|
38
|
+
export declare const HL_EN_TITLE_EVENTS_RE: RegExp;
|
|
39
|
+
export declare const HL_EN_TITLE_SLOTS_RE: RegExp;
|
|
40
|
+
export declare const HL_EN_MD = "en-US.md";
|
|
41
|
+
export declare const HL_EN_WEB_TYPES_JSON: string;
|
|
42
|
+
export declare const HL_ZH_TITLE_ATTRIBUTES_RE: RegExp;
|
|
43
|
+
export declare const HL_ZH_TITLE_EVENTS_RE: RegExp;
|
|
44
|
+
export declare const HL_ZH_TITLE_SLOTS_RE: RegExp;
|
|
45
|
+
export declare const HL_ZH_MD = "zh-CN.md";
|
|
46
|
+
export declare const HL_ZH_WEB_TYPES_JSON: string;
|
|
47
|
+
export declare const EXTENSION_ENTRY: string;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { resolve } from 'path';
|
|
2
|
+
import { getDirname } from './fsUtils.js';
|
|
3
|
+
export const dirname = getDirname(import.meta.url);
|
|
4
|
+
export const CWD = process.cwd();
|
|
5
|
+
export const MAPLE_CONFIG = resolve(CWD, 'maple.config.mjs');
|
|
6
|
+
export const COMPONENT_REUSE_JSON = resolve(CWD, 'component-reuse.json');
|
|
7
|
+
export const VITEST_CONFIG = resolve(dirname, '../config/vitest.config.js');
|
|
8
|
+
export const SRC = 'src';
|
|
9
|
+
export const SRC_DIR = resolve(CWD, SRC);
|
|
10
|
+
export const ES_DIR = resolve(CWD, 'es');
|
|
11
|
+
export const LIB_DIR = resolve(CWD, 'lib');
|
|
12
|
+
export const UMD_DIR = resolve(CWD, 'umd');
|
|
13
|
+
export const TYPES_DIR = resolve(CWD, 'types');
|
|
14
|
+
export const ROOT_DOCS_DIR = resolve(CWD, 'docs');
|
|
15
|
+
export const ROOT_PAGES_DIR = resolve(CWD, 'pages');
|
|
16
|
+
export const VITE_RESOLVE_EXTENSIONS = ['.vue', '.tsx', '.ts', '.jsx', '.js', '.mjs', '.cjs', '.less', '.scss', '.css'];
|
|
17
|
+
export const SCRIPTS_EXTENSIONS = ['.tsx', '.ts', '.jsx', '.js', '.mjs', '.cjs'];
|
|
18
|
+
export const PUBLIC_DIR_INDEXES = ['index.vue', 'index.tsx', 'index.ts', 'index.jsx', 'index.js'];
|
|
19
|
+
export const STYLE_DIR_NAME = 'style';
|
|
20
|
+
export const EXAMPLE_DIR_NAME = 'example';
|
|
21
|
+
export const LOCALE_DIR_NAME = 'locale';
|
|
22
|
+
export const DOCS_DIR_NAME = 'docs';
|
|
23
|
+
export const TESTS_DIR_NAME = '__tests__';
|
|
24
|
+
export const GENERATORS_DIR = resolve(dirname, '../../../template/generators');
|
|
25
|
+
export const UI_PACKAGE_JSON = resolve(CWD, 'package.json');
|
|
26
|
+
export const CLI_PACKAGE_JSON = resolve(dirname, '../../../package.json');
|
|
27
|
+
export const CHECKLIST_FILE = resolve(CWD, 'CHECKLIST.md');
|
|
28
|
+
// site
|
|
29
|
+
export const SITE = resolve(dirname, '../../../site');
|
|
30
|
+
export const SITE_OUTPUT_PATH = resolve(CWD, 'site');
|
|
31
|
+
export const SITE_PUBLIC_PATH = resolve(CWD, 'public');
|
|
32
|
+
export const SITE_DIR = resolve(CWD, '.maple/site');
|
|
33
|
+
export const SITE_PC_DIR = resolve(CWD, '.maple/site/pc');
|
|
34
|
+
export const SITE_PC_ROUTES = resolve(CWD, '.maple/pc.routes.ts');
|
|
35
|
+
export const SITE_MOBILE_ROUTES = resolve(CWD, '.maple/mobile.routes.ts');
|
|
36
|
+
export const SITE_CONFIG = resolve(CWD, '.maple/site.config.json');
|
|
37
|
+
// template highlight
|
|
38
|
+
export const HL_DIR = resolve(CWD, 'highlight');
|
|
39
|
+
export const HL_COMPONENT_NAME_RE = /.*(\/|\\)(.+)(\/|\\)docs(\/|\\)/;
|
|
40
|
+
export const HL_API_RE = /##\s*API(?:\r\n|\n)+/;
|
|
41
|
+
export const HL_EN_TITLE_ATTRIBUTES_RE = /###\s*(?:[A-Za-z][\w-]*[ \t]+)?Props(?:\r\n|\n)+/i;
|
|
42
|
+
export const HL_EN_TITLE_EVENTS_RE = /###\s*(?:[A-Za-z][\w-]*[ \t]+)?Events(?:\r\n|\n)+/i;
|
|
43
|
+
export const HL_EN_TITLE_SLOTS_RE = /###\s*(?:[A-Za-z][\w-]*[ \t]+)?Slots(?:\r\n|\n)+/i;
|
|
44
|
+
export const HL_EN_MD = 'en-US.md';
|
|
45
|
+
export const HL_EN_WEB_TYPES_JSON = resolve(HL_DIR, 'web-types.en-US.json');
|
|
46
|
+
export const HL_ZH_TITLE_ATTRIBUTES_RE = /###\s*(?:[A-Za-z][\w-]*[ \t]+)?(?:Props|属性)(?:\r\n|\n)+/i;
|
|
47
|
+
export const HL_ZH_TITLE_EVENTS_RE = /###\s*(?:[A-Za-z][\w-]*[ \t]+)?(?:Events|事件)(?:\r\n|\n)+/i;
|
|
48
|
+
export const HL_ZH_TITLE_SLOTS_RE = /###\s*(?:[A-Za-z][\w-]*[ \t]+)?(?:Slots|插槽)(?:\r\n|\n)+/i;
|
|
49
|
+
export const HL_ZH_MD = 'zh-CN.md';
|
|
50
|
+
export const HL_ZH_WEB_TYPES_JSON = resolve(HL_DIR, 'web-types.zh-CN.json');
|
|
51
|
+
// icons
|
|
52
|
+
// extension
|
|
53
|
+
export const EXTENSION_ENTRY = resolve(CWD, 'src/extension.ts');
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare function getPublicDirs(): Promise<string[]>;
|
|
2
|
+
export declare const isMD: (file: string) => boolean;
|
|
3
|
+
export declare const isDir: (file: string) => boolean;
|
|
4
|
+
export declare const isSFC: (file: string) => boolean;
|
|
5
|
+
export declare const isDTS: (file: string) => boolean;
|
|
6
|
+
export declare const isJsx: (file: string) => boolean;
|
|
7
|
+
export declare const isTsx: (file: string) => boolean;
|
|
8
|
+
export declare const isScript: (file: string) => boolean;
|
|
9
|
+
export declare const isLess: (file: string) => boolean;
|
|
10
|
+
export declare const isScss: (file: string) => boolean;
|
|
11
|
+
export declare const isPublicDir: (dir: string) => boolean;
|
|
12
|
+
export declare const replaceExt: (file: string, ext: string) => string;
|
|
13
|
+
export declare function smartAppendFileSync(file: string, code: string): void;
|
|
14
|
+
export declare function outputFileSyncOnChange(path: string, code: string): void;
|
|
15
|
+
export declare function glob(pattern: string): Promise<string[]>;
|
|
16
|
+
export declare function getDirname(url: string): string;
|
|
17
|
+
export declare function getVersion(): any;
|
|
18
|
+
export declare function getCliVersion(): any;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { extname, resolve } from 'path';
|
|
2
|
+
import { fileURLToPath } from 'url';
|
|
3
|
+
import fse from 'fs-extra';
|
|
4
|
+
import globSync from 'glob';
|
|
5
|
+
import { CLI_PACKAGE_JSON, PUBLIC_DIR_INDEXES, SCRIPTS_EXTENSIONS, SRC_DIR, UI_PACKAGE_JSON } from './constant.js';
|
|
6
|
+
const { appendFileSync, ensureFileSync, lstatSync, outputFileSync, pathExistsSync, readdir, readFileSync, readJSONSync, } = fse;
|
|
7
|
+
export async function getPublicDirs() {
|
|
8
|
+
const srcDir = await readdir(SRC_DIR);
|
|
9
|
+
return srcDir.filter((filename) => isPublicDir(resolve(SRC_DIR, filename)));
|
|
10
|
+
}
|
|
11
|
+
export const isMD = (file) => pathExistsSync(file) && extname(file) === '.md';
|
|
12
|
+
export const isDir = (file) => pathExistsSync(file) && lstatSync(file).isDirectory();
|
|
13
|
+
export const isSFC = (file) => pathExistsSync(file) && extname(file) === '.vue';
|
|
14
|
+
export const isDTS = (file) => pathExistsSync(file) && file.endsWith('.d.ts');
|
|
15
|
+
export const isJsx = (file) => pathExistsSync(file) && file.endsWith('.jsx');
|
|
16
|
+
export const isTsx = (file) => pathExistsSync(file) && file.endsWith('.tsx');
|
|
17
|
+
export const isScript = (file) => pathExistsSync(file) && SCRIPTS_EXTENSIONS.includes(extname(file));
|
|
18
|
+
export const isLess = (file) => pathExistsSync(file) && extname(file) === '.less';
|
|
19
|
+
export const isScss = (file) => pathExistsSync(file) && extname(file) === '.scss';
|
|
20
|
+
export const isPublicDir = (dir) => PUBLIC_DIR_INDEXES.some((index) => pathExistsSync(resolve(dir, index)));
|
|
21
|
+
export const replaceExt = (file, ext) => file.replace(extname(file), ext);
|
|
22
|
+
export function smartAppendFileSync(file, code) {
|
|
23
|
+
if (pathExistsSync(file)) {
|
|
24
|
+
const content = readFileSync(file, 'utf-8');
|
|
25
|
+
if (!content.includes(code)) {
|
|
26
|
+
appendFileSync(file, code);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export function outputFileSyncOnChange(path, code) {
|
|
31
|
+
ensureFileSync(path);
|
|
32
|
+
const content = readFileSync(path, 'utf-8');
|
|
33
|
+
if (content !== code) {
|
|
34
|
+
outputFileSync(path, code);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export function glob(pattern) {
|
|
38
|
+
return new Promise((resolve, reject) => {
|
|
39
|
+
globSync(pattern, (err, files) => {
|
|
40
|
+
if (err) {
|
|
41
|
+
reject(err);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
resolve(files);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
export function getDirname(url) {
|
|
50
|
+
return fileURLToPath(new URL('.', url));
|
|
51
|
+
}
|
|
52
|
+
export function getVersion() {
|
|
53
|
+
return readJSONSync(UI_PACKAGE_JSON).version;
|
|
54
|
+
}
|
|
55
|
+
export function getCliVersion() {
|
|
56
|
+
return readJSONSync(CLI_PACKAGE_JSON).version;
|
|
57
|
+
}
|