@varlet/cli 2.9.5 → 2.9.6-alpha.1680971883189

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/node/bin.js CHANGED
@@ -6,6 +6,7 @@ program.version(`varlet-cli ${getCliVersion()}`).usage('<command> [options]');
6
6
  program
7
7
  .command('dev')
8
8
  .option('-f --force', 'Force dep pre-optimization regardless of whether deps have changed')
9
+ .option('-d --draft', 'Start the service in draft mode')
9
10
  .description('Run varlet development environment')
10
11
  .action(async (options) => {
11
12
  const { dev } = await import('./commands/dev.js');
@@ -8,7 +8,7 @@ const { ensureDirSync } = fse;
8
8
  export async function build() {
9
9
  process.env.NODE_ENV = 'production';
10
10
  ensureDirSync(SRC_DIR);
11
- await buildSiteEntry();
11
+ await buildSiteEntry(false);
12
12
  const varletConfig = await getVarletConfig();
13
13
  const buildConfig = getBuildConfig(varletConfig);
14
14
  await buildVite(buildConfig);
@@ -1,5 +1,6 @@
1
1
  interface DevCommandOptions {
2
2
  force?: boolean;
3
+ draft?: boolean;
3
4
  }
4
5
  export declare function dev(options: DevCommandOptions): Promise<void>;
5
6
  export {};
@@ -10,29 +10,33 @@ import { merge } from 'lodash-es';
10
10
  const { ensureDirSync, pathExistsSync } = fse;
11
11
  let server;
12
12
  let watcher;
13
- async function startServer(force) {
13
+ async function startServer(options) {
14
+ var _a;
14
15
  const isRestart = Boolean(server);
15
16
  logger.info(`${isRestart ? 'Res' : 'S'}tarting server...`);
16
17
  // close all instance
17
18
  server && (await server.close());
18
19
  watcher && (await watcher.close());
19
20
  // build all config
20
- await buildSiteEntry();
21
+ await buildSiteEntry((_a = options.draft) !== null && _a !== void 0 ? _a : false);
21
22
  const varletConfig = await getVarletConfig();
22
23
  const devConfig = getDevConfig(varletConfig);
23
- const inlineConfig = merge(devConfig, force ? { optimizeDeps: { force: true } } : {});
24
+ const inlineConfig = merge(devConfig, options.force ? { optimizeDeps: { force: true } } : {});
24
25
  // create all instance
25
26
  server = await createServer(inlineConfig);
26
27
  await server.listen();
27
28
  server.printUrls();
28
29
  if (pathExistsSync(VARLET_CONFIG)) {
29
30
  watcher = chokidar.watch(VARLET_CONFIG);
30
- watcher.on('change', () => startServer(force));
31
+ watcher.on('change', () => startServer(options));
31
32
  }
32
33
  logger.success(`\n${isRestart ? 'Res' : 'S'}tart successfully!!!`);
34
+ if (options.draft) {
35
+ logger.title('Server in draft mode!!!');
36
+ }
33
37
  }
34
38
  export async function dev(options) {
35
39
  process.env.NODE_ENV = 'development';
36
40
  ensureDirSync(SRC_DIR);
37
- await startServer(options.force);
41
+ await startServer(options);
38
42
  }
@@ -13,7 +13,7 @@ export async function jest(cmd) {
13
13
  config: JEST_CONFIG,
14
14
  testRegex: cmd.component && `${cmd.component}/__tests__/.*.spec.[jt]s?$`,
15
15
  };
16
- await buildSiteEntry();
16
+ await buildSiteEntry(false);
17
17
  try {
18
18
  const response = await runCLI(config, [CWD]);
19
19
  if (!response.results.success && !cmd.watch) {
@@ -1,13 +1,18 @@
1
1
  export declare function getExampleRoutePath(examplePath: string): string;
2
2
  export declare function getComponentDocRoutePath(componentDocsPath: string): string;
3
3
  export declare function getRootDocRoutePath(rootDocsPath: string): string;
4
- export declare function getRootRoutePath(rootLocalePath: string): string;
5
- export declare function getRootFilePath(rootLocalePath: string): string;
6
- export declare function findExamples(): Promise<string[]>;
7
- export declare function findComponentDocs(): Promise<string[]>;
8
- export declare function findRootDocs(): Promise<string[]>;
9
- export declare function findRootLocales(): Promise<string[]>;
10
- export declare function buildMobileSiteRoutes(): Promise<void>;
11
- export declare function buildPcSiteRoutes(): Promise<void>;
4
+ export declare function getPageRoutePath(rootLocalePath: string): string;
5
+ export declare function getPageFilePath(rootLocalePath: string): string;
6
+ export declare function isDraftExample(example: string): boolean;
7
+ export declare function hasDraftExample(examples: string[], example: string): boolean;
8
+ export declare function isDraftDoc(doc: string): boolean;
9
+ export declare function hasDraftDoc(docs: string[], doc: string): boolean;
10
+ export declare function findExamples(draftMode: boolean): Promise<string[]>;
11
+ export declare function filterDraftDocs(docs: string[], draftMode: boolean): string[];
12
+ export declare function findComponentDocs(draftMode: boolean): Promise<string[]>;
13
+ export declare function findRootDocs(draftMode: boolean): Promise<string[]>;
14
+ export declare function findPageLocales(): Promise<string[]>;
15
+ export declare function buildMobileSiteRoutes(draftMode: boolean): Promise<void>;
16
+ export declare function buildPcSiteRoutes(draftMode: boolean): Promise<void>;
12
17
  export declare function buildSiteSource(): Promise<void>;
13
- export declare function buildSiteEntry(): Promise<void>;
18
+ export declare function buildSiteEntry(draftMode: boolean): Promise<void>;
@@ -1,17 +1,17 @@
1
1
  import slash from 'slash';
2
2
  import fse from 'fs-extra';
3
- import { DOCS_DIR_NAME, DIR_INDEX, EXAMPLE_DIR_NAME, LOCALE_DIR_NAME, ROOT_DOCS_DIR, ROOT_PAGES_DIR, SITE, SITE_DIR, SITE_MOBILE_ROUTES, SITE_PC_DIR, SITE_PC_ROUTES, SRC_DIR, } from '../shared/constant.js';
3
+ import { DOCS_DIR_NAME, EXAMPLE_DIR_NAME, LOCALE_DIR_NAME, ROOT_DOCS_DIR, ROOT_PAGES_DIR, SITE, SITE_DIR, SITE_MOBILE_ROUTES, SITE_PC_DIR, SITE_PC_ROUTES, SRC_DIR, } from '../shared/constant.js';
4
4
  import { glob, isDir, outputFileSyncOnChange } from '../shared/fsUtils.js';
5
5
  import { getVarletConfig } from '../config/varlet.config.js';
6
6
  import { get } from 'lodash-es';
7
7
  const { copy } = fse;
8
- const EXAMPLE_COMPONENT_NAME_RE = /\/([-\w]+)\/example\/index.vue/;
9
- const COMPONENT_DOCS_RE = /\/([-\w]+)\/docs\/([-\w]+)\.md/;
10
- const ROOT_DOCS_RE = /\/docs\/([-\w]+)\.([-\w]+)\.md/;
11
- const ROOT_LOCALE_RE = /\/pages\/([-\w]+)\/locale\/([-\w]+)\.ts/;
8
+ const ROOT_DOCS_RE = /\/docs\/([-\w]+)\.([-\w]+)(?:.draft)?\.md/;
9
+ const PAGE_LOCALE_RE = /\/pages\/([-\w]+)\/locale\/([-\w]+)\.ts/;
10
+ const EXAMPLE_INDEX_RE = /\/([-\w]+)\/example\/index(?:.draft)?\.vue/;
11
+ const COMPONENT_DOCS_RE = /\/([-\w]+)\/docs\/([-\w]+)(?:.draft)?\.md/;
12
12
  export function getExampleRoutePath(examplePath) {
13
13
  var _a;
14
- return '/' + ((_a = examplePath.match(EXAMPLE_COMPONENT_NAME_RE)) === null || _a === void 0 ? void 0 : _a[1]);
14
+ return '/' + ((_a = examplePath.match(EXAMPLE_INDEX_RE)) === null || _a === void 0 ? void 0 : _a[1]);
15
15
  }
16
16
  export function getComponentDocRoutePath(componentDocsPath) {
17
17
  var _a;
@@ -23,24 +23,50 @@ export function getRootDocRoutePath(rootDocsPath) {
23
23
  const [, routePath, language] = (_a = rootDocsPath.match(ROOT_DOCS_RE)) !== null && _a !== void 0 ? _a : [];
24
24
  return `/${language}/${routePath}`;
25
25
  }
26
- export function getRootRoutePath(rootLocalePath) {
26
+ export function getPageRoutePath(rootLocalePath) {
27
27
  var _a;
28
- const [, routePath, language] = (_a = rootLocalePath.match(ROOT_LOCALE_RE)) !== null && _a !== void 0 ? _a : [];
28
+ const [, routePath, language] = (_a = rootLocalePath.match(PAGE_LOCALE_RE)) !== null && _a !== void 0 ? _a : [];
29
29
  return `/${language}/${routePath}`;
30
30
  }
31
- export function getRootFilePath(rootLocalePath) {
32
- return rootLocalePath.replace(/locale\/.+/, DIR_INDEX);
31
+ export function getPageFilePath(rootLocalePath) {
32
+ return rootLocalePath.replace(/locale\/.+/, 'index.vue');
33
33
  }
34
- export function findExamples() {
35
- return glob(`${SRC_DIR}/**/${EXAMPLE_DIR_NAME}/${DIR_INDEX}`);
34
+ export function isDraftExample(example) {
35
+ return example.endsWith('index.draft.vue');
36
36
  }
37
- export function findComponentDocs() {
38
- return glob(`${SRC_DIR}/**/${DOCS_DIR_NAME}/*.md`);
37
+ export function hasDraftExample(examples, example) {
38
+ return examples.includes(example.replace('index.vue', 'index.draft.vue'));
39
39
  }
40
- export function findRootDocs() {
41
- return glob(`${ROOT_DOCS_DIR}/*.md`);
40
+ export function isDraftDoc(doc) {
41
+ return doc.endsWith('.draft.md');
42
42
  }
43
- export async function findRootLocales() {
43
+ export function hasDraftDoc(docs, doc) {
44
+ return docs.includes(doc.replace('.md', '.draft.md'));
45
+ }
46
+ export async function findExamples(draftMode) {
47
+ const [examples, draftExamples] = await Promise.all([
48
+ glob(`${SRC_DIR}/**/${EXAMPLE_DIR_NAME}/index.vue`),
49
+ glob(`${SRC_DIR}/**/${EXAMPLE_DIR_NAME}/index.draft.vue`),
50
+ ]);
51
+ const mergedExamples = [...examples, ...draftExamples];
52
+ return mergedExamples.filter((example) => {
53
+ return draftMode ? isDraftExample(example) || !hasDraftExample(mergedExamples, example) : !isDraftExample(example);
54
+ });
55
+ }
56
+ export function filterDraftDocs(docs, draftMode) {
57
+ return docs.filter((doc) => {
58
+ return draftMode ? isDraftDoc(doc) || !hasDraftDoc(docs, doc) : !isDraftDoc(doc);
59
+ });
60
+ }
61
+ export async function findComponentDocs(draftMode) {
62
+ const componentDocs = await glob(`${SRC_DIR}/**/${DOCS_DIR_NAME}/*.md`);
63
+ return filterDraftDocs(componentDocs, draftMode);
64
+ }
65
+ export async function findRootDocs(draftMode) {
66
+ const rootDocs = await glob(`${ROOT_DOCS_DIR}/*.md`);
67
+ return filterDraftDocs(rootDocs, draftMode);
68
+ }
69
+ export async function findPageLocales() {
44
70
  const defaultLanguage = get(await getVarletConfig(), 'defaultLanguage');
45
71
  const userPages = await glob(`${ROOT_PAGES_DIR}/*`);
46
72
  const baseLocales = await glob(`${SITE}/pc/pages/**/${LOCALE_DIR_NAME}/*.ts`);
@@ -57,18 +83,18 @@ export async function findRootLocales() {
57
83
  const filterMap = new Map();
58
84
  baseLocales.forEach((locale) => {
59
85
  var _a;
60
- const [, routePath, language] = (_a = locale.match(ROOT_LOCALE_RE)) !== null && _a !== void 0 ? _a : [];
86
+ const [, routePath, language] = (_a = locale.match(PAGE_LOCALE_RE)) !== null && _a !== void 0 ? _a : [];
61
87
  filterMap.set(routePath + language, slash(`${SITE_PC_DIR}/pages/${routePath}/locale/${language}.ts`));
62
88
  });
63
89
  userLocales.forEach((locale) => {
64
90
  var _a;
65
- const [, routePath, language] = (_a = locale.match(ROOT_LOCALE_RE)) !== null && _a !== void 0 ? _a : [];
91
+ const [, routePath, language] = (_a = locale.match(PAGE_LOCALE_RE)) !== null && _a !== void 0 ? _a : [];
66
92
  filterMap.set(routePath + language, locale);
67
93
  });
68
94
  return Promise.resolve(Array.from(filterMap.values()));
69
95
  }
70
- export async function buildMobileSiteRoutes() {
71
- const examples = await findExamples();
96
+ export async function buildMobileSiteRoutes(draftMode) {
97
+ const examples = await findExamples(draftMode);
72
98
  const routes = examples.map((example) => `
73
99
  {
74
100
  path: '${getExampleRoutePath(example)}',
@@ -80,17 +106,17 @@ export async function buildMobileSiteRoutes() {
80
106
  ]`;
81
107
  await outputFileSyncOnChange(SITE_MOBILE_ROUTES, source);
82
108
  }
83
- export async function buildPcSiteRoutes() {
109
+ export async function buildPcSiteRoutes(draftMode) {
84
110
  const [componentDocs, rootDocs, rootLocales] = await Promise.all([
85
- findComponentDocs(),
86
- findRootDocs(),
87
- findRootLocales(),
111
+ findComponentDocs(draftMode),
112
+ findRootDocs(draftMode),
113
+ findPageLocales(),
88
114
  ]);
89
- const rootPagesRoutes = rootLocales.map((rootLocale) => `
115
+ const pageRoutes = rootLocales.map((locale) => `
90
116
  {
91
- path: '${getRootRoutePath(rootLocale)}',
117
+ path: '${getPageRoutePath(locale)}',
92
118
  // @ts-ignore
93
- component: () => import('${getRootFilePath(rootLocale)}')
119
+ component: () => import('${getPageFilePath(locale)}')
94
120
  }\
95
121
  `);
96
122
  const componentDocsRoutes = componentDocs.map((componentDoc) => `
@@ -114,7 +140,7 @@ export async function buildPcSiteRoutes() {
114
140
  ]
115
141
  }`;
116
142
  const source = `export default [\
117
- ${rootPagesRoutes.join(',')},
143
+ ${pageRoutes.join(',')},
118
144
  ${layoutRoutes}
119
145
  ]`;
120
146
  outputFileSyncOnChange(SITE_PC_ROUTES, source);
@@ -122,7 +148,7 @@ export async function buildPcSiteRoutes() {
122
148
  export async function buildSiteSource() {
123
149
  return copy(SITE, SITE_DIR);
124
150
  }
125
- export async function buildSiteEntry() {
151
+ export async function buildSiteEntry(draftMode) {
126
152
  await getVarletConfig(true);
127
- await Promise.all([buildMobileSiteRoutes(), buildPcSiteRoutes(), buildSiteSource()]);
153
+ await Promise.all([buildMobileSiteRoutes(draftMode), buildPcSiteRoutes(draftMode), buildSiteSource()]);
128
154
  }
@@ -16,7 +16,6 @@ export declare const STYLE_DIR_NAME = "style";
16
16
  export declare const EXAMPLE_DIR_NAME = "example";
17
17
  export declare const LOCALE_DIR_NAME = "locale";
18
18
  export declare const DOCS_DIR_NAME = "docs";
19
- export declare const DIR_INDEX = "index.vue";
20
19
  export declare const TESTS_DIR_NAME = "__tests__";
21
20
  export declare const GENERATORS_DIR: string;
22
21
  export declare const UI_PACKAGE_JSON: string;
@@ -18,7 +18,6 @@ export const STYLE_DIR_NAME = 'style';
18
18
  export const EXAMPLE_DIR_NAME = 'example';
19
19
  export const LOCALE_DIR_NAME = 'locale';
20
20
  export const DOCS_DIR_NAME = 'docs';
21
- export const DIR_INDEX = 'index.vue';
22
21
  export const TESTS_DIR_NAME = '__tests__';
23
22
  export const GENERATORS_DIR = resolve(dirname, '../../../template/generators');
24
23
  export const UI_PACKAGE_JSON = resolve(CWD, 'package.json');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@varlet/cli",
3
- "version": "2.9.5",
3
+ "version": "2.9.6-alpha.1680971883189",
4
4
  "type": "module",
5
5
  "description": "cli of varlet",
6
6
  "bin": {
@@ -70,8 +70,8 @@
70
70
  "vue-jest": "^5.0.0-alpha.8",
71
71
  "webfont": "^9.0.0",
72
72
  "markdown-it": "^12.2.3",
73
- "@varlet/vite-plugins": "2.9.5",
74
- "@varlet/shared": "2.9.5"
73
+ "@varlet/shared": "2.9.6-alpha.1680971883189",
74
+ "@varlet/vite-plugins": "2.9.6-alpha.1680971883189"
75
75
  },
76
76
  "devDependencies": {
77
77
  "@types/babel__core": "^7.1.12",
@@ -85,8 +85,8 @@
85
85
  "@types/semver": "^7.3.9",
86
86
  "@types/sharp": "0.31.1",
87
87
  "@types/markdown-it": "^12.2.3",
88
- "@varlet/touch-emulator": "2.9.5",
89
- "@varlet/icons": "2.9.5"
88
+ "@varlet/touch-emulator": "2.9.6-alpha.1680971883189",
89
+ "@varlet/icons": "2.9.6-alpha.1680971883189"
90
90
  },
91
91
  "peerDependencies": {
92
92
  "@vue/runtime-core": "3.2.47",
@@ -96,8 +96,8 @@
96
96
  "lodash-es": "^4.17.21",
97
97
  "vue": "3.2.47",
98
98
  "vue-router": "4.1.6",
99
- "@varlet/icons": "2.9.5",
100
- "@varlet/touch-emulator": "2.9.5"
99
+ "@varlet/icons": "2.9.6-alpha.1680971883189",
100
+ "@varlet/touch-emulator": "2.9.6-alpha.1680971883189"
101
101
  },
102
102
  "scripts": {
103
103
  "dev": "tsc --watch",
@@ -5,6 +5,8 @@ node_modules
5
5
  .vscode
6
6
  *.log
7
7
  .DS_Store
8
+ index.draft.vue
9
+ *.draft.md
8
10
 
9
11
  site
10
12
  lib