@varlet/cli 2.6.2 → 2.7.0-alpha.1673584157662

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
@@ -1,10 +1,8 @@
1
1
  #!/usr/bin/env node
2
- import fse from 'fs-extra';
3
2
  import { Command } from 'commander';
4
- import { CLI_PACKAGE_JSON } from './shared/constant.js';
5
- const { readJSONSync } = fse;
3
+ import { getCliVersion } from './shared/fsUtils.js';
6
4
  const program = new Command();
7
- program.version(`varlet-cli ${readJSONSync(CLI_PACKAGE_JSON).version}`).usage('<command> [options]');
5
+ program.version(`varlet-cli ${getCliVersion()}`).usage('<command> [options]');
8
6
  program
9
7
  .command('dev')
10
8
  .option('-f --force', 'Force dep pre-optimization regardless of whether deps have changed')
@@ -25,11 +25,13 @@ export async function compile(options) {
25
25
  await removeDir();
26
26
  await Promise.all([runTask('types', compileTypes), runTask('template highlight', compileTemplateHighlight)]);
27
27
  process.env.TARGET_MODULE = 'module';
28
+ process.env.BABEL_MODULE = 'module';
28
29
  await runTask('module', compileModule);
29
30
  process.env.TARGET_MODULE = 'esm-bundle';
30
- await runTask('esm bundle', () => compileModule('esm-bundle'));
31
+ await runTask('esm bundle', compileModule);
31
32
  process.env.TARGET_MODULE = 'commonjs';
32
- await runTask('commonjs', () => compileModule('commonjs'));
33
+ process.env.BABEL_MODULE = 'commonjs';
34
+ await runTask('commonjs', compileModule);
33
35
  process.env.TARGET_MODULE = 'umd';
34
- !options.noUmd && (await runTask('umd', () => compileModule('umd')));
36
+ !options.noUmd && (await runTask('umd', compileModule));
35
37
  }
@@ -1,5 +1,6 @@
1
1
  interface ReleaseCommandOptions {
2
2
  remote?: string;
3
+ task?(): Promise<void>;
3
4
  }
4
5
  export declare function release(options: ReleaseCommandOptions): Promise<void>;
5
6
  export {};
@@ -8,6 +8,7 @@ import inquirer from 'inquirer';
8
8
  import { CWD } from '../shared/constant.js';
9
9
  import { resolve } from 'path';
10
10
  import { changelog } from './changelog.js';
11
+ import { getVersion } from '../shared/fsUtils.js';
11
12
  const { writeFileSync, readJSONSync } = fse;
12
13
  const { prompt } = inquirer;
13
14
  const releaseTypes = ['premajor', 'preminor', 'prepatch', 'major', 'minor', 'patch'];
@@ -100,7 +101,7 @@ async function getReleaseType() {
100
101
  }
101
102
  export async function release(options) {
102
103
  try {
103
- const currentVersion = readJSONSync(resolve(CWD, 'package.json')).version;
104
+ const currentVersion = getVersion();
104
105
  if (!currentVersion) {
105
106
  logger.error('Your package is missing the version field');
106
107
  return;
@@ -123,6 +124,9 @@ export async function release(options) {
123
124
  return;
124
125
  }
125
126
  updateVersion(expectVersion);
127
+ if (options.task) {
128
+ await options.task();
129
+ }
126
130
  await publish(isPreRelease);
127
131
  if (!isPreRelease) {
128
132
  await changelog();
@@ -2,4 +2,4 @@ export declare function compileUMD(): Promise<void>;
2
2
  export declare function compileESMBundle(): Promise<void>;
3
3
  export declare function compileDir(dir: string): Promise<void>;
4
4
  export declare function compileFile(file: string): Promise<void>;
5
- export declare function compileModule(modules?: 'umd' | 'commonjs' | 'esm-bundle' | boolean): Promise<void>;
5
+ export declare function compileModule(): Promise<void>;
@@ -4,29 +4,19 @@ import { resolve } from 'path';
4
4
  import { EXAMPLE_DIR_NAME, TESTS_DIR_NAME, DOCS_DIR_NAME, SRC_DIR, ES_DIR, STYLE_DIR_NAME, LIB_DIR, } from '../shared/constant.js';
5
5
  import { getPublicDirs, isDir, isDTS, isLess, isScript, isSFC } from '../shared/fsUtils.js';
6
6
  import { compileSFC } from './compileSFC.js';
7
- import { compileESEntry, compileCommonJSEntry, compileScriptFile } from './compileScript.js';
7
+ import { compileESEntry, compileCommonJSEntry, compileScriptFile, getScriptExtname } from './compileScript.js';
8
8
  import { clearLessFiles, compileLess } from './compileStyle.js';
9
9
  import { getESMBundleConfig, getUMDConfig } from '../config/vite.config.js';
10
10
  import { getVarletConfig } from '../config/varlet.config.js';
11
11
  import { generateReference } from './compileTypes.js';
12
12
  const { copy, ensureFileSync, readdir, removeSync } = fse;
13
- export function compileUMD() {
14
- return new Promise((resolve, reject) => {
15
- getVarletConfig().then((varletConfig) => {
16
- build(getUMDConfig(varletConfig))
17
- .then(() => resolve())
18
- .catch(reject);
19
- });
20
- });
13
+ export async function compileUMD() {
14
+ const varletConfig = await getVarletConfig();
15
+ await build(getUMDConfig(varletConfig));
21
16
  }
22
- export function compileESMBundle() {
23
- return new Promise((resolve, reject) => {
24
- getVarletConfig().then((varletConfig) => {
25
- build(getESMBundleConfig(varletConfig))
26
- .then(() => resolve())
27
- .catch(reject);
28
- });
29
- });
17
+ export async function compileESMBundle() {
18
+ const varletConfig = await getVarletConfig();
19
+ await build(getESMBundleConfig(varletConfig));
30
20
  }
31
21
  export async function compileDir(dir) {
32
22
  const dirs = await readdir(dir);
@@ -45,26 +35,26 @@ export async function compileFile(file) {
45
35
  isLess(file) && (await compileLess(file));
46
36
  isDir(file) && (await compileDir(file));
47
37
  }
48
- export async function compileModule(modules = false) {
49
- if (modules === 'umd') {
38
+ export async function compileModule() {
39
+ const targetModule = process.env.TARGET_MODULE;
40
+ if (targetModule === 'umd') {
50
41
  await compileUMD();
51
42
  return;
52
43
  }
53
- if (modules === 'esm-bundle') {
44
+ if (targetModule === 'esm-bundle') {
54
45
  await compileESMBundle();
55
46
  return;
56
47
  }
57
- process.env.BABEL_MODULE = modules === 'commonjs' ? 'commonjs' : 'module';
58
- const dest = modules === 'commonjs' ? LIB_DIR : ES_DIR;
48
+ const dest = targetModule === 'commonjs' ? LIB_DIR : ES_DIR;
59
49
  await copy(SRC_DIR, dest);
60
50
  const moduleDir = await readdir(dest);
61
51
  await Promise.all(moduleDir.map((filename) => {
62
52
  const file = resolve(dest, filename);
63
- isDir(file) && ensureFileSync(resolve(file, './style/index.js'));
53
+ isDir(file) && ensureFileSync(resolve(file, `./style/index.${getScriptExtname()}`));
64
54
  return isDir(file) ? compileDir(file) : null;
65
55
  }));
66
56
  const publicDirs = await getPublicDirs();
67
- if (modules === 'commonjs') {
57
+ if (targetModule === 'commonjs') {
68
58
  await compileCommonJSEntry(dest, publicDirs);
69
59
  }
70
60
  else {
@@ -68,7 +68,7 @@ export async function compileSFC(sfc) {
68
68
  });
69
69
  code = extractStyleDependencies(file, code, STYLE_IMPORT_RE);
70
70
  writeFileSync(file, clearEmptyLine(code), 'utf-8');
71
- smartAppendFileSync(cssFile, process.env.BABEL_MODULE === 'commonjs'
71
+ smartAppendFileSync(cssFile, process.env.TARGET_MODULE === 'commonjs'
72
72
  ? `require('${dependencyPath}.css')\n`
73
73
  : `import '${dependencyPath}.css'\n`);
74
74
  if (style.lang === 'less') {
@@ -1,17 +1,13 @@
1
- export declare const IMPORT_VUE_PATH_RE: RegExp;
2
- export declare const IMPORT_TS_PATH_RE: RegExp;
3
- export declare const IMPORT_JSX_PATH_RE: RegExp;
4
- export declare const IMPORT_TSX_PATH_RE: RegExp;
5
- export declare const REQUIRE_VUE_PATH_RE: RegExp;
6
- export declare const REQUIRE_TS_PATH_RE: RegExp;
7
- export declare const REQUIRE_JSX_PATH_RE: RegExp;
8
- export declare const REQUIRE_TSX_PATH_RE: RegExp;
9
- export declare const replaceVueExt: (script: string) => string;
10
- export declare const replaceTSExt: (script: string) => string;
11
- export declare const replaceJSXExt: (script: string) => string;
12
- export declare const replaceTSXExt: (script: string) => string;
1
+ export declare const IMPORT_FROM_DEPENDENCE_RE: RegExp;
2
+ export declare const IMPORT_DEPENDENCE_RE: RegExp;
3
+ export declare const REQUIRE_DEPENDENCE_RE: RegExp;
4
+ export declare const scriptExtNames: string[];
5
+ export declare const scriptIndexes: string[];
6
+ export declare const tryMatchExtname: (file: string, extname: string[]) => string | undefined;
7
+ export declare const resolveDependence: (file: string, script: string) => string;
13
8
  export declare const moduleCompatible: (script: string) => Promise<string>;
14
9
  export declare function compileScript(script: string, file: string): Promise<void>;
15
10
  export declare function compileScriptFile(file: string): Promise<void>;
11
+ export declare function getScriptExtname(): "mjs" | "js";
16
12
  export declare function compileESEntry(dir: string, publicDirs: string[]): Promise<void>;
17
13
  export declare function compileCommonJSEntry(dir: string, publicDirs: string[]): Promise<void>;
@@ -1,25 +1,65 @@
1
1
  import fse from 'fs-extra';
2
2
  import { transformAsync } from '@babel/core';
3
3
  import { bigCamelize } from '@varlet/shared';
4
- import { replaceExt } from '../shared/fsUtils.js';
4
+ import { getVersion, isDir, replaceExt } from '../shared/fsUtils.js';
5
5
  import { extractStyleDependencies, IMPORT_CSS_RE, IMPORT_LESS_RE, REQUIRE_CSS_RE, REQUIRE_LESS_RE, } from './compileStyle.js';
6
- import { resolve } from 'path';
6
+ import { resolve, extname, dirname } from 'path';
7
7
  import { get } from 'lodash-es';
8
8
  import { getVarletConfig } from '../config/varlet.config.js';
9
- const { writeFileSync, readFileSync, removeSync, writeFile } = fse;
10
- export const IMPORT_VUE_PATH_RE = /((?<!['"`])import\s+.+from\s+['"]\s*\.{1,2}\/.+)\.vue(\s*['"`]);?(?!\s*['"`])/g;
11
- export const IMPORT_TS_PATH_RE = /((?<!['"`])import\s+.+from\s+['"]\s*\.{1,2}\/.+)\.ts(\s*['"`]);?(?!\s*['"`])/g;
12
- export const IMPORT_JSX_PATH_RE = /((?<!['"`])import\s+.+from\s+['"]\s*\.{1,2}\/.+)\.jsx(\s*['"`]);?(?!\s*['"`])/g;
13
- export const IMPORT_TSX_PATH_RE = /((?<!['"`])import\s+.+from\s+['"]\s*\.{1,2}\/.+)\.tsx(\s*['"`]);?(?!\s*['"`])/g;
14
- export const REQUIRE_VUE_PATH_RE = /(?<!['"`]\s*)(require\s*\(\s*['"]\s*\.{1,2}\/.+)\.vue(\s*['"`]\))(?!\s*['"`])/g;
15
- export const REQUIRE_TS_PATH_RE = /(?<!['"`]\s*)(require\s*\(\s*['"]\s*\.{1,2}\/.+)\.ts(\s*['"`]\))(?!\s*['"`])/g;
16
- export const REQUIRE_JSX_PATH_RE = /(?<!['"`]\s*)(require\s*\(\s*['"]\s*\.{1,2}\/.+)\.jsx(\s*['"`]\))(?!\s*['"`])/g;
17
- export const REQUIRE_TSX_PATH_RE = /(?<!['"`]\s*)(require\s*\(\s*['"]\s*\.{1,2}\/.+)\.tsx(\s*['"`]\))(?!\s*['"`])/g;
18
- const scriptReplacer = (_, p1, p2) => `${p1}.js${p2}`;
19
- export const replaceVueExt = (script) => script.replace(IMPORT_VUE_PATH_RE, scriptReplacer).replace(REQUIRE_VUE_PATH_RE, scriptReplacer);
20
- export const replaceTSExt = (script) => script.replace(IMPORT_TS_PATH_RE, scriptReplacer).replace(REQUIRE_TS_PATH_RE, scriptReplacer);
21
- export const replaceJSXExt = (script) => script.replace(IMPORT_JSX_PATH_RE, scriptReplacer).replace(REQUIRE_JSX_PATH_RE, scriptReplacer);
22
- export const replaceTSXExt = (script) => script.replace(IMPORT_TSX_PATH_RE, scriptReplacer).replace(REQUIRE_TSX_PATH_RE, scriptReplacer);
9
+ const { writeFileSync, readdirSync, readFileSync, removeSync, writeFile, pathExistsSync } = fse;
10
+ // https://regexr.com/765a4
11
+ export const IMPORT_FROM_DEPENDENCE_RE = /import\s+?[\w\s{},$*]+\s+from\s+?(".*?"|'.*?')/g;
12
+ // https://regexr.com/764ve
13
+ export const IMPORT_DEPENDENCE_RE = /import\s+['"]\s*\.{1,2}\/(.+)\s*['"];?/g;
14
+ // https://regexr.com/764vn
15
+ export const REQUIRE_DEPENDENCE_RE = /require\(['"]\s*(\.{1,2}\/.+)\s*['"]\)/g;
16
+ export const scriptExtNames = ['mjs', 'vue', 'ts', 'tsx', 'js', 'jsx'];
17
+ export const scriptIndexes = ['index.mjs', 'index.vue', 'index.ts', 'index.tsx', 'index.js', 'index.jsx'];
18
+ export const tryMatchExtname = (file, extname) => {
19
+ // eslint-disable-next-line no-restricted-syntax
20
+ for (const ext of extname) {
21
+ const matched = `${file}.${ext}`;
22
+ if (pathExistsSync(matched)) {
23
+ return ext;
24
+ }
25
+ }
26
+ };
27
+ export const resolveDependence = (file, script) => {
28
+ return script.replace(IMPORT_FROM_DEPENDENCE_RE, (source, dependence) => {
29
+ dependence = dependence.slice(1, dependence.length - 1);
30
+ const ext = extname(dependence);
31
+ const targetDependenceFile = resolve(dirname(file), dependence);
32
+ const scriptExtname = getScriptExtname();
33
+ const inNodeModules = !dependence.startsWith('.');
34
+ if (inNodeModules) {
35
+ // e.g. @varlet/shared
36
+ return source;
37
+ }
38
+ if (!ext) {
39
+ // e.g. ../button/props -> ../button/props.m?js
40
+ const matched = tryMatchExtname(targetDependenceFile, scriptExtNames);
41
+ if (matched) {
42
+ return source.replace(dependence, `${dependence}.${scriptExtname}`);
43
+ }
44
+ }
45
+ if (!ext && isDir(targetDependenceFile)) {
46
+ // e.g. ../button
47
+ const files = readdirSync(targetDependenceFile);
48
+ const hasScriptIndex = files.some((file) => scriptIndexes.some((name) => file.endsWith(name)));
49
+ if (hasScriptIndex) {
50
+ // e.g. -> ../button/index.m?js
51
+ return source.replace(dependence, `${dependence}/index.${scriptExtname}`);
52
+ }
53
+ const hasStyleIndex = files.some((file) => ['index.less', 'index.css'].some((name) => file.endsWith(name)));
54
+ if (hasStyleIndex) {
55
+ // e.g. -> ../button/index.css
56
+ return source.replace(dependence, `${dependence}/index.css`);
57
+ }
58
+ }
59
+ // e.g. ../button/props.ts -> ../button/props.m?js
60
+ return source.replace(dependence, dependence.replace(ext, `.${scriptExtname}`));
61
+ });
62
+ };
23
63
  export const moduleCompatible = async (script) => {
24
64
  const moduleCompatible = get(await getVarletConfig(), 'moduleCompatible', {});
25
65
  Object.keys(moduleCompatible).forEach((esm) => {
@@ -29,55 +69,66 @@ export const moduleCompatible = async (script) => {
29
69
  return script;
30
70
  };
31
71
  export async function compileScript(script, file) {
32
- const modules = process.env.BABEL_MODULE;
33
- if (modules === 'commonjs') {
72
+ const targetModule = process.env.TARGET_MODULE;
73
+ if (targetModule === 'commonjs') {
34
74
  script = await moduleCompatible(script);
35
75
  }
36
76
  let { code } = (await transformAsync(script, {
37
77
  filename: file,
38
78
  }));
39
- code = extractStyleDependencies(file, code, modules === 'commonjs' ? REQUIRE_CSS_RE : IMPORT_CSS_RE);
40
- code = extractStyleDependencies(file, code, modules === 'commonjs' ? REQUIRE_LESS_RE : IMPORT_LESS_RE);
41
- code = replaceVueExt(code);
42
- code = replaceTSXExt(code);
43
- code = replaceJSXExt(code);
44
- code = replaceTSExt(code);
45
- removeSync(file);
46
- writeFileSync(replaceExt(file, '.js'), code, 'utf8');
79
+ if (code) {
80
+ code = extractStyleDependencies(file, code, targetModule === 'commonjs' ? REQUIRE_CSS_RE : IMPORT_CSS_RE);
81
+ code = extractStyleDependencies(file, code, targetModule === 'commonjs' ? REQUIRE_LESS_RE : IMPORT_LESS_RE);
82
+ code = resolveDependence(file, code);
83
+ removeSync(file);
84
+ writeFileSync(replaceExt(file, `.${getScriptExtname()}`), code, 'utf8');
85
+ }
47
86
  }
48
87
  export async function compileScriptFile(file) {
49
88
  const sources = readFileSync(file, 'utf-8');
50
89
  await compileScript(sources, file);
51
90
  }
91
+ export function getScriptExtname() {
92
+ if (process.env.TARGET_MODULE === 'module') {
93
+ return 'mjs';
94
+ }
95
+ return 'js';
96
+ }
52
97
  export async function compileESEntry(dir, publicDirs) {
53
98
  const imports = [];
54
99
  const plugins = [];
55
- const constInternalComponents = [];
100
+ const exports = [];
56
101
  const cssImports = [];
57
102
  const publicComponents = [];
103
+ const scriptExtname = getScriptExtname();
58
104
  publicDirs.forEach((dirname) => {
59
105
  const publicComponent = bigCamelize(dirname);
106
+ const module = `'./${dirname}/index.${scriptExtname}'`;
60
107
  publicComponents.push(publicComponent);
61
- imports.push(`import ${publicComponent}, * as ${publicComponent}Module from './${dirname}'`);
62
- constInternalComponents.push(`export const _${publicComponent}Component = ${publicComponent}Module._${publicComponent}Component || {}`);
108
+ imports.push(`import ${publicComponent} from ${module}`);
109
+ exports.push(`export * from ${module}`);
63
110
  plugins.push(`${publicComponent}.install && app.use(${publicComponent})`);
64
- cssImports.push(`import './${dirname}/style'`);
111
+ cssImports.push(`import './${dirname}/style/index.${scriptExtname}'`);
65
112
  });
66
113
  const install = `
67
114
  function install(app) {
68
115
  ${plugins.join('\n ')}
69
116
  }
70
117
  `;
118
+ const version = `const version = '${getVersion()}'`;
71
119
  const indexTemplate = `\
72
120
  ${imports.join('\n')}\n
73
- ${constInternalComponents.join('\n')}\n
121
+ ${exports.join('\n')}\n
122
+ ${version}
74
123
  ${install}
75
124
  export {
125
+ version,
76
126
  install,
77
127
  ${publicComponents.join(',\n ')}
78
128
  }
79
129
 
80
130
  export default {
131
+ version,
81
132
  install,
82
133
  ${publicComponents.join(',\n ')}
83
134
  }
@@ -88,21 +139,24 @@ ${cssImports.join('\n')}
88
139
  const umdTemplate = `\
89
140
  ${imports.join('\n')}\n
90
141
  ${cssImports.join('\n')}\n
142
+ ${version}
91
143
  ${install}
92
144
  export {
145
+ version,
93
146
  install,
94
147
  ${publicComponents.join(',\n ')}
95
148
  }
96
149
 
97
150
  export default {
151
+ version,
98
152
  install,
99
153
  ${publicComponents.join(',\n ')}
100
154
  }
101
155
  `;
102
156
  await Promise.all([
103
- writeFile(resolve(dir, 'index.js'), indexTemplate, 'utf-8'),
104
- writeFile(resolve(dir, 'umdIndex.js'), umdTemplate, 'utf-8'),
105
- writeFile(resolve(dir, 'style.js'), styleTemplate, 'utf-8'),
157
+ writeFile(resolve(dir, 'index.mjs'), indexTemplate, 'utf-8'),
158
+ writeFile(resolve(dir, 'index.umd.mjs'), umdTemplate, 'utf-8'),
159
+ writeFile(resolve(dir, 'style.mjs'), styleTemplate, 'utf-8'),
106
160
  ]);
107
161
  }
108
162
  export async function compileCommonJSEntry(dir, publicDirs) {
@@ -110,12 +164,15 @@ export async function compileCommonJSEntry(dir, publicDirs) {
110
164
  const plugins = [];
111
165
  const cssRequires = [];
112
166
  const publicComponents = [];
167
+ const exports = [];
113
168
  publicDirs.forEach((dirname) => {
114
169
  const publicComponent = bigCamelize(dirname);
170
+ const module = `'./${dirname}/index.js'`;
115
171
  publicComponents.push(publicComponent);
116
- requires.push(`var ${publicComponent} = require('./${dirname}')['default']`);
172
+ requires.push(`var ${publicComponent} = require(${module})['default']`);
173
+ exports.push(`...ignoreDefault(require(${module}))`);
117
174
  plugins.push(`${publicComponent}.install && app.use(${publicComponent})`);
118
- cssRequires.push(`require('./${dirname}/style')`);
175
+ cssRequires.push(`require('./${dirname}/style/index.js')`);
119
176
  });
120
177
  const install = `
121
178
  function install(app) {
@@ -126,8 +183,21 @@ function install(app) {
126
183
  ${requires.join('\n')}\n
127
184
  ${install}
128
185
 
186
+ function ignoreDefault(module) {
187
+ return Object.keys(module).reduce((exports, key) => {
188
+ if (key !=== 'default') {
189
+ exports[key] = module[key]
190
+ }
191
+
192
+ return exports
193
+ }, {})
194
+ }
195
+
196
+ exports.install = install
197
+
129
198
  module.exports = {
130
199
  install,
200
+ ${exports.join(',\n ')}
131
201
  ${publicComponents.join(',\n ')}
132
202
  }
133
203
  `;
@@ -3,6 +3,7 @@ import less from 'less';
3
3
  import glob from 'glob';
4
4
  import { replaceExt, smartAppendFileSync } from '../shared/fsUtils.js';
5
5
  import { parse, resolve } from 'path';
6
+ import { getScriptExtname } from './compileScript.js';
6
7
  const { render } = less;
7
8
  const { readFileSync, writeFileSync, unlinkSync } = fse;
8
9
  export const EMPTY_SPACE_RE = /[\s]+/g;
@@ -24,11 +25,11 @@ export function normalizeStyleDependency(styleImport, reg) {
24
25
  export function extractStyleDependencies(file, code, styleReg) {
25
26
  var _a;
26
27
  const styleImports = (_a = code.match(styleReg)) !== null && _a !== void 0 ? _a : [];
27
- const cssFile = resolve(parse(file).dir, './style/index.js');
28
- const modules = process.env.BABEL_MODULE;
28
+ const cssFile = resolve(parse(file).dir, `./style/index.${getScriptExtname()}`);
29
+ const targetModule = process.env.TARGET_MODULE;
29
30
  styleImports.forEach((styleImport) => {
30
31
  const normalizedPath = normalizeStyleDependency(styleImport, styleReg);
31
- smartAppendFileSync(cssFile, modules === 'commonjs' ? `require('${normalizedPath}.css')\n` : `import '${normalizedPath}.css'\n`);
32
+ smartAppendFileSync(cssFile, targetModule === 'commonjs' ? `require('${normalizedPath}.css')\n` : `import '${normalizedPath}.css'\n`);
32
33
  });
33
34
  return code.replace(styleReg, '');
34
35
  }
@@ -1,10 +1,10 @@
1
1
  import fse from 'fs-extra';
2
- import { SRC_DIR, HL_MD, HL_API_RE, HL_COMPONENT_NAME_RE, HL_TITLE_ATTRIBUTES_RE, HL_TITLE_EVENTS_RE, HL_TITLE_SLOTS_RE, HL_WEB_TYPES_JSON, HL_DIR, HL_TAGS_JSON, HL_ATTRIBUTES_JSON, CLI_PACKAGE_JSON, } from '../shared/constant.js';
2
+ import { SRC_DIR, HL_MD, HL_API_RE, HL_COMPONENT_NAME_RE, HL_TITLE_ATTRIBUTES_RE, HL_TITLE_EVENTS_RE, HL_TITLE_SLOTS_RE, HL_WEB_TYPES_JSON, HL_DIR, HL_TAGS_JSON, HL_ATTRIBUTES_JSON, } from '../shared/constant.js';
3
3
  import { resolve } from 'path';
4
- import { isDir, isMD } from '../shared/fsUtils.js';
4
+ import { getCliVersion, isDir, isMD } from '../shared/fsUtils.js';
5
5
  import { get } from 'lodash-es';
6
6
  import { getVarletConfig } from '../config/varlet.config.js';
7
- const { ensureDir, readdirSync, readFileSync, readJSONSync, writeFile } = fse;
7
+ const { ensureDir, readdirSync, readFileSync, writeFile } = fse;
8
8
  const TABLE_HEAD_RE = /\s*\|.*\|\s*\n\s*\|.*---+\s*\|\s*\n+/;
9
9
  const TABLE_FOOT_RE = /(\|\s*$)|(\|\s*\n(?!\s*\|))/;
10
10
  export const replaceDot = (s) => s.replace(/`/g, '');
@@ -115,7 +115,7 @@ export async function compileTemplateHighlight() {
115
115
  const webTypes = {
116
116
  $schema: 'https://raw.githubusercontent.com/JetBrains/web-types/master/schema/web-types.json',
117
117
  framework: 'vue',
118
- version: readJSONSync(CLI_PACKAGE_JSON).version,
118
+ version: getCliVersion(),
119
119
  name: get(varletConfig, 'title'),
120
120
  contributions: {
121
121
  html: {
@@ -69,7 +69,7 @@ export function getESMBundleConfig(varletConfig) {
69
69
  name,
70
70
  formats: ['es'],
71
71
  fileName: () => fileName,
72
- entry: resolve(ES_DIR, 'umdIndex.js'),
72
+ entry: resolve(ES_DIR, 'index.umd.mjs'),
73
73
  },
74
74
  rollupOptions: {
75
75
  external: ['vue'],
@@ -98,7 +98,7 @@ export function getUMDConfig(varletConfig) {
98
98
  name,
99
99
  formats: ['umd'],
100
100
  fileName: () => fileName,
101
- entry: resolve(ES_DIR, 'umdIndex.js'),
101
+ entry: resolve(ES_DIR, 'index.umd.mjs'),
102
102
  },
103
103
  rollupOptions: {
104
104
  external: ['vue'],
@@ -1 +1,13 @@
1
1
  export { defineConfig } from './config/varlet.config.js';
2
+ export * from './commands/release.js';
3
+ export * from './commands/dev.js';
4
+ export * from './commands/build.js';
5
+ export * from './commands/compile.js';
6
+ export * from './commands/commitLint.js';
7
+ export * from './commands/gen.js';
8
+ export * from './commands/jest.js';
9
+ export * from './commands/create.js';
10
+ export * from './commands/lint.js';
11
+ export * from './commands/changelog.js';
12
+ export * from './commands/preview.js';
13
+ export * from './commands/vite.js';
package/lib/node/index.js CHANGED
@@ -1 +1,13 @@
1
1
  export { defineConfig } from './config/varlet.config.js';
2
+ export * from './commands/release.js';
3
+ export * from './commands/dev.js';
4
+ export * from './commands/build.js';
5
+ export * from './commands/compile.js';
6
+ export * from './commands/commitLint.js';
7
+ export * from './commands/gen.js';
8
+ export * from './commands/jest.js';
9
+ export * from './commands/create.js';
10
+ export * from './commands/lint.js';
11
+ export * from './commands/changelog.js';
12
+ export * from './commands/preview.js';
13
+ export * from './commands/vite.js';
@@ -11,3 +11,5 @@ export declare function smartAppendFileSync(file: string, code: string): void;
11
11
  export declare function outputFileSyncOnChange(path: string, code: string): void;
12
12
  export declare function glob(pattern: string): Promise<string[]>;
13
13
  export declare function getDirname(url: string): string;
14
+ export declare function getVersion(): any;
15
+ export declare function getCliVersion(): any;
@@ -1,9 +1,9 @@
1
1
  import globSync from 'glob';
2
2
  import fse from 'fs-extra';
3
3
  import { extname, resolve } from 'path';
4
- import { PUBLIC_DIR_INDEXES, SCRIPTS_EXTENSIONS, SRC_DIR } from './constant.js';
4
+ import { CLI_PACKAGE_JSON, PUBLIC_DIR_INDEXES, SCRIPTS_EXTENSIONS, SRC_DIR, UI_PACKAGE_JSON } from './constant.js';
5
5
  import { fileURLToPath } from 'url';
6
- const { appendFileSync, ensureFileSync, lstatSync, outputFileSync, pathExistsSync, readdir, readFileSync } = fse;
6
+ const { appendFileSync, ensureFileSync, lstatSync, outputFileSync, pathExistsSync, readdir, readFileSync, readJSONSync, } = fse;
7
7
  export async function getPublicDirs() {
8
8
  const srcDir = await readdir(SRC_DIR);
9
9
  return srcDir.filter((filename) => isPublicDir(resolve(SRC_DIR, filename)));
@@ -46,3 +46,9 @@ export function glob(pattern) {
46
46
  export function getDirname(url) {
47
47
  return fileURLToPath(new URL('.', url));
48
48
  }
49
+ export function getVersion() {
50
+ return readJSONSync(UI_PACKAGE_JSON).version;
51
+ }
52
+ export function getCliVersion() {
53
+ return readJSONSync(CLI_PACKAGE_JSON).version;
54
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@varlet/cli",
3
- "version": "2.6.2",
3
+ "version": "2.7.0-alpha.1673584157662",
4
4
  "type": "module",
5
5
  "description": "cli of varlet",
6
6
  "bin": {
@@ -66,8 +66,8 @@
66
66
  "vite": "4.0.4",
67
67
  "vue": "3.2.25",
68
68
  "vue-jest": "^5.0.0-alpha.8",
69
- "@varlet/vite-plugins": "2.6.2",
70
- "@varlet/shared": "2.6.2"
69
+ "@varlet/vite-plugins": "2.7.0-alpha.1673584157662",
70
+ "@varlet/shared": "2.7.0-alpha.1673584157662"
71
71
  },
72
72
  "devDependencies": {
73
73
  "@types/babel__core": "^7.1.12",
@@ -79,8 +79,8 @@
79
79
  "@types/node": "^18.7.20",
80
80
  "@types/semver": "^7.3.9",
81
81
  "@types/inquirer": "^9.0.2",
82
- "@varlet/icons": "2.6.2",
83
- "@varlet/touch-emulator": "2.6.2"
82
+ "@varlet/icons": "2.7.0-alpha.1673584157662",
83
+ "@varlet/touch-emulator": "2.7.0-alpha.1673584157662"
84
84
  },
85
85
  "peerDependencies": {
86
86
  "@vue/runtime-core": "3.2.16",
@@ -90,8 +90,8 @@
90
90
  "lodash-es": "^4.17.21",
91
91
  "vue": "3.2.25",
92
92
  "vue-router": "4.0.12",
93
- "@varlet/icons": "2.6.2",
94
- "@varlet/touch-emulator": "2.6.2"
93
+ "@varlet/icons": "2.7.0-alpha.1673584157662",
94
+ "@varlet/touch-emulator": "2.7.0-alpha.1673584157662"
95
95
  },
96
96
  "scripts": {
97
97
  "dev": "tsc --watch",