@varlet/cli 2.0.5 → 2.1.0-alpha.1666877950844

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.
Files changed (143) hide show
  1. package/README.en-US.md +2 -2
  2. package/README.md +2 -2
  3. package/cjs/babel.config.cjs +29 -0
  4. package/cjs/babel.sfc.transform.cjs +18 -0
  5. package/cjs/jest.config.cjs +33 -0
  6. package/cjs/jest.media.mock.cjs +1 -0
  7. package/cjs/jest.style.mock.cjs +1 -0
  8. package/client.d.ts +1 -0
  9. package/client.js +1 -0
  10. package/lib/client/appType.d.ts +4 -0
  11. package/lib/client/appType.js +7 -0
  12. package/lib/client/index.d.ts +17 -0
  13. package/lib/client/index.js +106 -0
  14. package/lib/{bin.d.ts → node/bin.d.ts} +2 -2
  15. package/lib/node/bin.js +122 -0
  16. package/lib/{commands → node/commands}/build.d.ts +1 -1
  17. package/lib/node/commands/build.js +15 -0
  18. package/lib/{commands → node/commands}/changelog.d.ts +6 -6
  19. package/lib/node/commands/changelog.js +20 -0
  20. package/lib/{commands → node/commands}/commitLint.d.ts +1 -1
  21. package/lib/node/commands/commitLint.js +45 -0
  22. package/lib/{commands → node/commands}/compile.d.ts +7 -7
  23. package/lib/node/commands/compile.js +35 -0
  24. package/lib/{commands → node/commands}/create.d.ts +8 -8
  25. package/lib/node/commands/create.js +91 -0
  26. package/lib/{commands → node/commands}/dev.d.ts +5 -5
  27. package/lib/node/commands/dev.js +38 -0
  28. package/lib/{commands → node/commands}/gen.d.ts +8 -8
  29. package/lib/node/commands/gen.js +75 -0
  30. package/lib/{commands → node/commands}/jest.d.ts +8 -8
  31. package/lib/node/commands/jest.js +27 -0
  32. package/lib/{commands → node/commands}/lint.d.ts +1 -1
  33. package/lib/node/commands/lint.js +41 -0
  34. package/lib/{commands → node/commands}/preview.d.ts +1 -1
  35. package/lib/node/commands/preview.js +18 -0
  36. package/lib/{commands → node/commands}/release.d.ts +5 -5
  37. package/lib/node/commands/release.js +146 -0
  38. package/lib/{commands → node/commands}/vite.d.ts +3 -3
  39. package/lib/node/commands/vite.js +13 -0
  40. package/lib/{compiler → node/compiler}/compileModule.d.ts +5 -5
  41. package/lib/node/compiler/compileModule.js +74 -0
  42. package/lib/{compiler → node/compiler}/compileSFC.d.ts +2 -2
  43. package/lib/node/compiler/compileSFC.js +79 -0
  44. package/lib/{compiler → node/compiler}/compileScript.d.ts +17 -17
  45. package/lib/node/compiler/compileScript.js +141 -0
  46. package/lib/{compiler → node/compiler}/compileSiteEntry.d.ts +13 -13
  47. package/lib/node/compiler/compileSiteEntry.js +128 -0
  48. package/lib/{compiler → node/compiler}/compileStyle.d.ts +11 -11
  49. package/lib/node/compiler/compileStyle.js +39 -0
  50. package/lib/{compiler → node/compiler}/compileTemplateHighlight.d.ts +10 -10
  51. package/lib/node/compiler/compileTemplateHighlight.js +133 -0
  52. package/lib/{compiler → node/compiler}/compileTypes.d.ts +2 -2
  53. package/lib/node/compiler/compileTypes.js +45 -0
  54. package/lib/{config → node/config}/varlet.config.d.ts +45 -44
  55. package/lib/node/config/varlet.config.js +27 -0
  56. package/lib/node/config/varlet.default.config.d.ts +2 -0
  57. package/lib/node/config/varlet.default.config.js +264 -0
  58. package/lib/node/config/vite.config.d.ts +6 -0
  59. package/lib/node/config/vite.config.js +144 -0
  60. package/lib/node/index.d.ts +1 -0
  61. package/lib/node/index.js +1 -0
  62. package/lib/{shared → node/shared}/constant.d.ts +42 -43
  63. package/lib/node/shared/constant.js +47 -0
  64. package/lib/{shared → node/shared}/fsUtils.d.ts +13 -12
  65. package/lib/node/shared/fsUtils.js +48 -0
  66. package/lib/{shared → node/shared}/logger.d.ts +8 -8
  67. package/lib/node/shared/logger.js +18 -0
  68. package/package.json +22 -19
  69. package/{preset.js → preset.cjs} +1 -1
  70. package/site/components/button/index.ts +10 -10
  71. package/site/components/cell/index.ts +10 -10
  72. package/site/components/code-example/CodeExample.vue +2 -1
  73. package/site/components/code-example/codeExample.less +41 -41
  74. package/site/components/code-example/index.ts +10 -10
  75. package/site/components/context/zIndex.ts +20 -20
  76. package/site/components/icon/icon.less +26 -26
  77. package/site/components/icon/index.ts +10 -10
  78. package/site/components/icon/props.ts +24 -24
  79. package/site/components/loading/index.ts +10 -10
  80. package/site/components/progress/index.ts +10 -10
  81. package/site/components/snackbar/snackbar.less +135 -135
  82. package/site/components/styles/common.less +64 -64
  83. package/site/components/styles/elevation.less +126 -126
  84. package/site/components/styles/var.less +27 -27
  85. package/site/components/utils/components.ts +1 -4
  86. package/site/components/utils/elements.ts +1 -1
  87. package/site/index.html +49 -49
  88. package/site/mobile/App.vue +27 -26
  89. package/site/mobile/components/AppHome.vue +2 -1
  90. package/site/mobile/components/app-bar/index.ts +10 -10
  91. package/site/mobile/components/app-bar/props.ts +25 -25
  92. package/site/mobile.html +41 -41
  93. package/site/module.d.ts +5 -5
  94. package/site/pc/App.vue +2 -1
  95. package/site/pc/Layout.vue +2 -1
  96. package/site/pc/components/AppHeader.vue +4 -2
  97. package/site/pc/pages/index/index.vue +8 -4
  98. package/site/tsconfig.json +11 -11
  99. package/site/useProgress.ts +2 -1
  100. package/site/utils.ts +6 -137
  101. package/template/generators/config/default/base/{varlet.config.js → varlet.config.mjs} +2 -2
  102. package/template/generators/config/i18n/base/{varlet.config.js → varlet.config.mjs} +2 -2
  103. package/tsconfig.json +2 -9
  104. package/lib/bin.js +0 -102
  105. package/lib/commands/build.js +0 -67
  106. package/lib/commands/changelog.js +0 -27
  107. package/lib/commands/commitLint.js +0 -21
  108. package/lib/commands/compile.js +0 -119
  109. package/lib/commands/create.js +0 -166
  110. package/lib/commands/dev.js +0 -123
  111. package/lib/commands/gen.js +0 -138
  112. package/lib/commands/jest.js +0 -85
  113. package/lib/commands/lint.js +0 -123
  114. package/lib/commands/preview.js +0 -74
  115. package/lib/commands/release.js +0 -270
  116. package/lib/commands/vite.js +0 -69
  117. package/lib/compiler/compileModule.js +0 -190
  118. package/lib/compiler/compileSFC.js +0 -135
  119. package/lib/compiler/compileScript.js +0 -194
  120. package/lib/compiler/compileSiteEntry.js +0 -237
  121. package/lib/compiler/compileStyle.js +0 -91
  122. package/lib/compiler/compileTemplateHighlight.js +0 -193
  123. package/lib/compiler/compileTypes.js +0 -85
  124. package/lib/config/babel.config.d.ts +0 -2
  125. package/lib/config/babel.config.js +0 -31
  126. package/lib/config/babel.sfc.transform.d.ts +0 -1
  127. package/lib/config/babel.sfc.transform.js +0 -18
  128. package/lib/config/jest.config.d.ts +0 -1
  129. package/lib/config/jest.config.js +0 -37
  130. package/lib/config/jest.media.mock.d.ts +0 -0
  131. package/lib/config/jest.media.mock.js +0 -2
  132. package/lib/config/jest.style.mock.d.ts +0 -0
  133. package/lib/config/jest.style.mock.js +0 -2
  134. package/lib/config/varlet.config.js +0 -35
  135. package/lib/config/vite.config.d.ts +0 -5
  136. package/lib/config/vite.config.js +0 -162
  137. package/lib/index.d.ts +0 -1
  138. package/lib/index.js +0 -5
  139. package/lib/shared/constant.js +0 -50
  140. package/lib/shared/fsUtils.js +0 -108
  141. package/lib/shared/logger.js +0 -23
  142. package/site/mobile/components/AppType.vue +0 -22
  143. package/varlet.default.config.js +0 -267
@@ -1,5 +1,5 @@
1
- interface DevCommandOptions {
2
- force?: boolean;
3
- }
4
- export declare function dev(options: DevCommandOptions): Promise<void>;
5
- export {};
1
+ interface DevCommandOptions {
2
+ force?: boolean;
3
+ }
4
+ export declare function dev(options: DevCommandOptions): Promise<void>;
5
+ export {};
@@ -0,0 +1,38 @@
1
+ import chokidar from 'chokidar';
2
+ import fse from 'fs-extra';
3
+ import logger from '../shared/logger.js';
4
+ import { createServer } from 'vite';
5
+ import { SRC_DIR, VARLET_CONFIG } from '../shared/constant.js';
6
+ import { buildSiteEntry } from '../compiler/compileSiteEntry.js';
7
+ import { getDevConfig } from '../config/vite.config.js';
8
+ import { getVarletConfig } from '../config/varlet.config.js';
9
+ import { merge } from 'lodash-es';
10
+ const { ensureDirSync, pathExistsSync } = fse;
11
+ let server;
12
+ let watcher;
13
+ async function startServer(force) {
14
+ const isRestart = Boolean(server);
15
+ logger.info(`${isRestart ? 'Res' : 'S'}tarting server...`);
16
+ // close all instance
17
+ server && (await server.close());
18
+ watcher && (await watcher.close());
19
+ // build all config
20
+ await buildSiteEntry();
21
+ const varletConfig = await getVarletConfig();
22
+ const devConfig = getDevConfig(varletConfig);
23
+ const inlineConfig = merge(devConfig, force ? { optimizeDeps: { force: true } } : {});
24
+ // create all instance
25
+ server = await createServer(inlineConfig);
26
+ await server.listen();
27
+ server.printUrls();
28
+ if (pathExistsSync(VARLET_CONFIG)) {
29
+ watcher = chokidar.watch(VARLET_CONFIG);
30
+ watcher.on('change', () => startServer(force));
31
+ }
32
+ logger.success(`\n${isRestart ? 'Res' : 'S'}tart successfully!!!`);
33
+ }
34
+ export async function dev(options) {
35
+ process.env.NODE_ENV = 'development';
36
+ ensureDirSync(SRC_DIR);
37
+ await startServer(options.force);
38
+ }
@@ -1,8 +1,8 @@
1
- interface GenCommandOptions {
2
- name?: string;
3
- i18n?: boolean;
4
- sfc?: boolean;
5
- tsx?: boolean;
6
- }
7
- export declare function gen(options: GenCommandOptions): Promise<void>;
8
- export {};
1
+ interface GenCommandOptions {
2
+ name?: string;
3
+ i18n?: boolean;
4
+ sfc?: boolean;
5
+ tsx?: boolean;
6
+ }
7
+ export declare function gen(options: GenCommandOptions): Promise<void>;
8
+ export {};
@@ -0,0 +1,75 @@
1
+ import logger from '../shared/logger.js';
2
+ import fse from 'fs-extra';
3
+ import inquirer from 'inquirer';
4
+ import { resolve } from 'path';
5
+ import { CLI_PACKAGE_JSON, CWD, GENERATORS_DIR } from '../shared/constant.js';
6
+ const { copy, pathExistsSync, readFileSync, writeFileSync, rename } = fse;
7
+ const { prompt } = inquirer;
8
+ function syncVersion(name) {
9
+ const file = resolve(CWD, name, 'package.json');
10
+ const pkg = JSON.parse(readFileSync(file, 'utf-8'));
11
+ const cliPkg = JSON.parse(readFileSync(CLI_PACKAGE_JSON, 'utf-8'));
12
+ Object.keys(pkg.devDependencies).forEach((key) => {
13
+ if (key.startsWith('@varlet')) {
14
+ pkg.devDependencies[key] = `^${cliPkg.version}`;
15
+ }
16
+ });
17
+ pkg.files = ['es', 'lib', 'umd', 'highlight', 'types'];
18
+ writeFileSync(file, JSON.stringify(pkg, null, 2));
19
+ }
20
+ export async function gen(options) {
21
+ logger.title('\n📦📦 Generate cli application ! \n');
22
+ const { name } = options.name
23
+ ? options
24
+ : await prompt({
25
+ name: 'name',
26
+ message: 'Name of the generate application: ',
27
+ default: 'varlet-cli-app',
28
+ });
29
+ const dest = resolve(CWD, name);
30
+ if (pathExistsSync(dest)) {
31
+ logger.error(`${name} already exists and cannot be recreated...`);
32
+ return;
33
+ }
34
+ let codeStyle;
35
+ // Determine whether the parameter carries a coding style
36
+ if (options.sfc || options.tsx) {
37
+ codeStyle = options.sfc ? 'sfc' : 'tsx';
38
+ }
39
+ else {
40
+ const { style } = await prompt({
41
+ name: 'style',
42
+ type: 'list',
43
+ message: 'Please select your component library programming format',
44
+ choices: ['sfc', 'tsx'],
45
+ });
46
+ codeStyle = style;
47
+ }
48
+ const { i18n } = options.i18n
49
+ ? options
50
+ : await prompt({
51
+ name: 'i18n',
52
+ type: 'confirm',
53
+ message: 'Whether to use i18n?',
54
+ default: false,
55
+ });
56
+ const dirName = i18n ? 'i18n' : 'default';
57
+ const base = resolve(GENERATORS_DIR, 'base');
58
+ const configBase = resolve(GENERATORS_DIR, 'config', dirName, 'base');
59
+ const code = resolve(GENERATORS_DIR, 'config', dirName, codeStyle);
60
+ await copy(base, dest);
61
+ await copy(configBase, dest);
62
+ await copy(code, dest);
63
+ await rename(resolve(dest, '_gitignore'), resolve(dest, '.gitignore'));
64
+ syncVersion(name);
65
+ logger.success('✨ Application generated successfully!');
66
+ logger.info(`\
67
+ cd ${name}
68
+ pnpm install
69
+ pnpm dev`);
70
+ logger.success(`\
71
+ =======================
72
+ Good luck have fun
73
+ =======================\
74
+ `);
75
+ }
@@ -1,8 +1,8 @@
1
- interface JestCommandOptions {
2
- watch?: boolean;
3
- watchAll?: boolean;
4
- component?: string;
5
- clearCache?: boolean;
6
- }
7
- export declare function jest(cmd: JestCommandOptions): Promise<void>;
8
- export {};
1
+ interface JestCommandOptions {
2
+ watch?: boolean;
3
+ watchAll?: boolean;
4
+ component?: string;
5
+ clearCache?: boolean;
6
+ }
7
+ export declare function jest(cmd: JestCommandOptions): Promise<void>;
8
+ export {};
@@ -0,0 +1,27 @@
1
+ import logger from '../shared/logger.js';
2
+ import jestModule from 'jest';
3
+ import { CWD, JEST_CONFIG } from '../shared/constant.js';
4
+ import { buildSiteEntry } from '../compiler/compileSiteEntry.js';
5
+ const { runCLI } = jestModule;
6
+ export async function jest(cmd) {
7
+ process.env.NODE_ENV = 'test';
8
+ const config = {
9
+ rootDir: CWD,
10
+ watch: cmd.watch,
11
+ watchAll: cmd.watchAll,
12
+ clearCache: cmd.clearCache,
13
+ config: JEST_CONFIG,
14
+ testRegex: cmd.component && `${cmd.component}/__tests__/.*.spec.[jt]s?$`,
15
+ };
16
+ await buildSiteEntry();
17
+ try {
18
+ const response = await runCLI(config, [CWD]);
19
+ if (!response.results.success && !cmd.watch) {
20
+ process.exit(1);
21
+ }
22
+ }
23
+ catch (e) {
24
+ logger.error(e.toString());
25
+ process.exit(1);
26
+ }
27
+ }
@@ -1 +1 @@
1
- export declare function lint(): Promise<void>;
1
+ export declare function lint(): Promise<void>;
@@ -0,0 +1,41 @@
1
+ import execa from 'execa';
2
+ import ora from 'ora';
3
+ import { CWD, ESLINT_EXTENSIONS } from '../shared/constant.js';
4
+ import { isDir } from '../shared/fsUtils.js';
5
+ import { resolve } from 'path';
6
+ export async function lint() {
7
+ let spinner;
8
+ try {
9
+ spinner = ora('prettier starting...').start();
10
+ await execa('prettier', ['--write', '.']);
11
+ spinner.succeed('prettier success');
12
+ spinner = ora('stylelint starting...').start();
13
+ const stylelintPattern = ['./src/**/*.vue', './src/**/*.css', './src/**/*.less'];
14
+ const hasPackages = isDir(resolve(CWD, 'packages'));
15
+ hasPackages && stylelintPattern.push('./packages/**/*.vue', './packages/**/*.css', './packages/**/*.less');
16
+ await execa('stylelint', [...stylelintPattern, '--fix']);
17
+ spinner.succeed('stylelint success');
18
+ spinner = ora('eslint starting...').start();
19
+ const eslintPatterns = [
20
+ './src',
21
+ './packages/varlet-cli/src',
22
+ './packages/varlet-ui/src',
23
+ './packages/varlet-icons/lib',
24
+ './packages/varlet-markdown-vite-plugin',
25
+ './packages/varlet-touch-emulator',
26
+ './packages/varlet-vscode-extension/src',
27
+ ];
28
+ const { stdout } = await execa('eslint', [
29
+ ...eslintPatterns.filter((pattern) => isDir(resolve(CWD, pattern))),
30
+ '--fix',
31
+ '--ext',
32
+ ESLINT_EXTENSIONS.join(),
33
+ ]);
34
+ const type = stdout ? 'warn' : 'succeed';
35
+ spinner[type](stdout || 'eslint success');
36
+ }
37
+ catch (e) {
38
+ spinner.fail(e.toString());
39
+ process.exit(1);
40
+ }
41
+ }
@@ -1 +1 @@
1
- export declare function preview(): Promise<void>;
1
+ export declare function preview(): Promise<void>;
@@ -0,0 +1,18 @@
1
+ import fse from 'fs-extra';
2
+ import logger from '../shared/logger.js';
3
+ import execa from 'execa';
4
+ import { SITE_OUTPUT_PATH } from '../shared/constant.js';
5
+ const { pathExistsSync } = fse;
6
+ export async function preview() {
7
+ var _a;
8
+ if (!pathExistsSync(SITE_OUTPUT_PATH)) {
9
+ logger.warning('Cannot find the site folder, you must first run the build command to build the document site');
10
+ return;
11
+ }
12
+ try {
13
+ await ((_a = execa.command('live-server --port=5500', { cwd: SITE_OUTPUT_PATH }).stdout) === null || _a === void 0 ? void 0 : _a.pipe(process.stdout));
14
+ }
15
+ catch (e) {
16
+ logger.error(e.toString());
17
+ }
18
+ }
@@ -1,5 +1,5 @@
1
- interface ReleaseCommandOptions {
2
- remote?: string;
3
- }
4
- export declare function release(options: ReleaseCommandOptions): Promise<void>;
5
- export {};
1
+ interface ReleaseCommandOptions {
2
+ remote?: string;
3
+ }
4
+ export declare function release(options: ReleaseCommandOptions): Promise<void>;
5
+ export {};
@@ -0,0 +1,146 @@
1
+ import ora from 'ora';
2
+ import fse from 'fs-extra';
3
+ import execa from 'execa';
4
+ import logger from '../shared/logger.js';
5
+ import semver from 'semver';
6
+ import glob from 'glob';
7
+ import inquirer from 'inquirer';
8
+ import { CWD } from '../shared/constant.js';
9
+ import { resolve } from 'path';
10
+ import { changelog } from './changelog.js';
11
+ const { writeFileSync, readJSONSync } = fse;
12
+ const { prompt } = inquirer;
13
+ const releaseTypes = ['premajor', 'preminor', 'prepatch', 'major', 'minor', 'patch'];
14
+ async function isWorktreeEmpty() {
15
+ const ret = await execa('git', ['status', '--porcelain']);
16
+ return !ret.stdout;
17
+ }
18
+ async function publish(preRelease) {
19
+ const s = ora().start('Publishing all packages');
20
+ const args = ['-r', 'publish', '--no-git-checks', '--access', 'public'];
21
+ preRelease && args.push('--tag', 'alpha');
22
+ const ret = await execa('pnpm', args);
23
+ if (ret.stderr && ret.stderr.includes('npm ERR!')) {
24
+ throw new Error('\n' + ret.stderr);
25
+ }
26
+ else {
27
+ s.succeed('Publish all packages successfully');
28
+ ret.stdout && logger.info(ret.stdout);
29
+ }
30
+ }
31
+ async function pushGit(version, remote = 'origin') {
32
+ const s = ora().start('Pushing to remote git repository');
33
+ await execa('git', ['add', '.']);
34
+ await execa('git', ['commit', '-m', `v${version}`]);
35
+ await execa('git', ['tag', `v${version}`]);
36
+ await execa('git', ['push', remote, `v${version}`]);
37
+ const ret = await execa('git', ['push']);
38
+ s.succeed('Push remote repository successfully');
39
+ ret.stdout && logger.info(ret.stdout);
40
+ }
41
+ function updateVersion(version) {
42
+ const packageJsons = glob.sync('packages/*/package.json');
43
+ packageJsons.push('package.json');
44
+ packageJsons.forEach((path) => {
45
+ const file = resolve(CWD, path);
46
+ const config = readJSONSync(file);
47
+ config.version = version;
48
+ writeFileSync(file, JSON.stringify(config, null, 2));
49
+ });
50
+ }
51
+ async function confirmRegistry() {
52
+ const registry = (await execa('npm', ['config', 'get', 'registry'])).stdout;
53
+ const name = 'Registry confirm';
54
+ const ret = await prompt([
55
+ {
56
+ name,
57
+ type: 'confirm',
58
+ message: `Current registry is: ${registry}`,
59
+ },
60
+ ]);
61
+ return ret[name];
62
+ }
63
+ async function confirmVersion(currentVersion, expectVersion) {
64
+ const name = 'Version confirm';
65
+ const ret = await prompt([
66
+ {
67
+ name,
68
+ type: 'confirm',
69
+ message: `All packages version ${currentVersion} -> ${expectVersion}:`,
70
+ },
71
+ ]);
72
+ return ret[name];
73
+ }
74
+ async function confirmRefs(remote = 'origin') {
75
+ var _a;
76
+ const { stdout } = await execa('git', ['remote', '-v']);
77
+ const reg = new RegExp(`${remote}\t(.*) \\(push`);
78
+ const repo = (_a = stdout.match(reg)) === null || _a === void 0 ? void 0 : _a[1];
79
+ const { stdout: branch } = await execa('git', ['branch', '--show-current']);
80
+ const name = 'Refs confirm';
81
+ const ret = await prompt([
82
+ {
83
+ name,
84
+ type: 'confirm',
85
+ message: `Current refs ${repo}:refs/for/${branch}`,
86
+ },
87
+ ]);
88
+ return ret[name];
89
+ }
90
+ async function getReleaseType() {
91
+ const name = 'Please select release type';
92
+ const ret = await prompt([
93
+ {
94
+ name,
95
+ type: 'list',
96
+ choices: releaseTypes,
97
+ },
98
+ ]);
99
+ return ret[name];
100
+ }
101
+ export async function release(options) {
102
+ try {
103
+ const currentVersion = readJSONSync(resolve(CWD, 'package.json')).version;
104
+ if (!currentVersion) {
105
+ logger.error('Your package is missing the version field');
106
+ return;
107
+ }
108
+ if (!(await isWorktreeEmpty())) {
109
+ logger.error('Git worktree is not empty, please commit changed');
110
+ return;
111
+ }
112
+ if (!(await confirmRefs(options.remote))) {
113
+ return;
114
+ }
115
+ if (!(await confirmRegistry())) {
116
+ return;
117
+ }
118
+ const type = await getReleaseType();
119
+ const isPreRelease = type.startsWith('pre');
120
+ let expectVersion = semver.inc(currentVersion, type, `alpha.${Date.now()}`);
121
+ expectVersion = isPreRelease ? expectVersion.slice(0, -2) : expectVersion;
122
+ if (!(await confirmVersion(currentVersion, expectVersion))) {
123
+ return;
124
+ }
125
+ updateVersion(expectVersion);
126
+ await publish(isPreRelease);
127
+ if (!isPreRelease) {
128
+ await changelog();
129
+ await pushGit(expectVersion, options.remote);
130
+ }
131
+ logger.success(`Release version ${expectVersion} successfully!`);
132
+ if (isPreRelease) {
133
+ try {
134
+ await execa('git', ['restore', '**/package.json']);
135
+ await execa('git', ['restore', 'package.json']);
136
+ }
137
+ catch (_a) {
138
+ logger.error('Restore package.json has failed, please restore manually');
139
+ }
140
+ }
141
+ }
142
+ catch (error) {
143
+ logger.error(error.toString());
144
+ process.exit(1);
145
+ }
146
+ }
@@ -1,3 +1,3 @@
1
- declare type ViteCommandMode = 'dev' | 'build';
2
- export declare function vite(mode: ViteCommandMode): Promise<void>;
3
- export {};
1
+ declare type ViteCommandMode = 'dev' | 'build';
2
+ export declare function vite(mode: ViteCommandMode): Promise<void>;
3
+ export {};
@@ -0,0 +1,13 @@
1
+ import vue from '@vitejs/plugin-vue';
2
+ import jsx from '@vitejs/plugin-vue-jsx';
3
+ import { build, createServer } from 'vite';
4
+ export async function vite(mode) {
5
+ const run = mode === 'build' ? build : createServer;
6
+ const result = await run({
7
+ plugins: [vue(), jsx()],
8
+ });
9
+ if (mode === 'dev') {
10
+ await result.listen();
11
+ result.printUrls();
12
+ }
13
+ }
@@ -1,5 +1,5 @@
1
- export declare function compileUMD(): Promise<void>;
2
- export declare function compileESMBundle(): Promise<void>;
3
- export declare function compileDir(dir: string): Promise<void>;
4
- export declare function compileFile(file: string): Promise<void>;
5
- export declare function compileModule(modules?: 'umd' | 'commonjs' | 'esm-bundle' | boolean): Promise<void>;
1
+ export declare function compileUMD(): Promise<void>;
2
+ export declare function compileESMBundle(): Promise<void>;
3
+ export declare function compileDir(dir: string): Promise<void>;
4
+ export declare function compileFile(file: string): Promise<void>;
5
+ export declare function compileModule(modules?: 'umd' | 'commonjs' | 'esm-bundle' | boolean): Promise<void>;
@@ -0,0 +1,74 @@
1
+ import fse from 'fs-extra';
2
+ import { build } from 'vite';
3
+ import { resolve } from 'path';
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
+ import { getPublicDirs, isDir, isDTS, isLess, isScript, isSFC } from '../shared/fsUtils.js';
6
+ import { compileSFC } from './compileSFC.js';
7
+ import { compileESEntry, compileCommonJSEntry, compileScriptFile } from './compileScript.js';
8
+ import { compileLess } from './compileStyle.js';
9
+ import { getESMBundleConfig, getUMDConfig } from '../config/vite.config.js';
10
+ import { getVarletConfig } from '../config/varlet.config.js';
11
+ import { generateReference } from './compileTypes.js';
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
+ });
21
+ }
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
+ });
30
+ }
31
+ export async function compileDir(dir) {
32
+ const dirs = await readdir(dir);
33
+ await Promise.all(dirs.map((filename) => {
34
+ const file = resolve(dir, filename);
35
+ [TESTS_DIR_NAME, EXAMPLE_DIR_NAME, DOCS_DIR_NAME].includes(filename) && removeSync(file);
36
+ if (isDTS(file) || filename === STYLE_DIR_NAME) {
37
+ return Promise.resolve();
38
+ }
39
+ return compileFile(file);
40
+ }));
41
+ }
42
+ export async function compileFile(file) {
43
+ isSFC(file) && (await compileSFC(file));
44
+ isScript(file) && (await compileScriptFile(file));
45
+ isLess(file) && (await compileLess(file));
46
+ isDir(file) && (await compileDir(file));
47
+ }
48
+ export async function compileModule(modules = false) {
49
+ if (modules === 'umd') {
50
+ await compileUMD();
51
+ return;
52
+ }
53
+ if (modules === 'esm-bundle') {
54
+ await compileESMBundle();
55
+ return;
56
+ }
57
+ process.env.BABEL_MODULE = modules === 'commonjs' ? 'commonjs' : 'module';
58
+ const dest = modules === 'commonjs' ? LIB_DIR : ES_DIR;
59
+ await copy(SRC_DIR, dest);
60
+ const moduleDir = await readdir(dest);
61
+ await Promise.all(moduleDir.map((filename) => {
62
+ const file = resolve(dest, filename);
63
+ isDir(file) && ensureFileSync(resolve(file, './style/index.js'));
64
+ return isDir(file) ? compileDir(file) : null;
65
+ }));
66
+ const publicDirs = await getPublicDirs();
67
+ if (modules === 'commonjs') {
68
+ await compileCommonJSEntry(dest, publicDirs);
69
+ }
70
+ else {
71
+ await compileESEntry(dest, publicDirs);
72
+ }
73
+ generateReference(dest);
74
+ }
@@ -1,2 +1,2 @@
1
- export declare function injectRender(script: string, render: string): string;
2
- export declare function compileSFC(sfc: string): Promise<void>;
1
+ export declare function injectRender(script: string, render: string): string;
2
+ export declare function compileSFC(sfc: string): Promise<void>;
@@ -0,0 +1,79 @@
1
+ import fse from 'fs-extra';
2
+ import hash from 'hash-sum';
3
+ import { parse, resolve } from 'path';
4
+ import { parse as parseSFC, compileTemplate, compileStyle } from '@vue/compiler-sfc';
5
+ import { replaceExt, smartAppendFileSync } from '../shared/fsUtils.js';
6
+ import { compileScript } from './compileScript.js';
7
+ import { clearEmptyLine, compileLess, extractStyleDependencies, normalizeStyleDependency, STYLE_IMPORT_RE, } from './compileStyle.js';
8
+ import logger from '../shared/logger.js';
9
+ const { readFile, writeFileSync } = fse;
10
+ const NORMAL_EXPORT_START_RE = /export\s+default\s+{/;
11
+ const DEFINE_EXPORT_START_RE = /export\s+default\s+defineComponent\s*\(\s*{/;
12
+ export function injectRender(script, render) {
13
+ if (DEFINE_EXPORT_START_RE.test(script.trim())) {
14
+ return script.trim().replace(DEFINE_EXPORT_START_RE, `${render}\nexport default defineComponent({
15
+ render,\
16
+ `);
17
+ }
18
+ if (NORMAL_EXPORT_START_RE.test(script.trim())) {
19
+ return script.trim().replace(NORMAL_EXPORT_START_RE, `${render}\nexport default {
20
+ render,\
21
+ `);
22
+ }
23
+ return script;
24
+ }
25
+ export async function compileSFC(sfc) {
26
+ const sources = await readFile(sfc, 'utf-8');
27
+ const { descriptor } = parseSFC(sources, { sourceMap: false });
28
+ const { script, scriptSetup, template, styles } = descriptor;
29
+ if (scriptSetup) {
30
+ logger.warning(`\n Varlet Cli does not support compiling script setup syntax\
31
+ \n The error in ${sfc}`);
32
+ return;
33
+ }
34
+ // scoped
35
+ const hasScope = styles.some((style) => style.scoped);
36
+ const id = hash(sources);
37
+ const scopeId = hasScope ? `data-v-${id}` : '';
38
+ if (script) {
39
+ // template
40
+ const render = template &&
41
+ compileTemplate({
42
+ id,
43
+ source: template.content,
44
+ filename: sfc,
45
+ compilerOptions: {
46
+ scopeId,
47
+ },
48
+ });
49
+ let { content } = script;
50
+ if (render) {
51
+ const { code } = render;
52
+ content = injectRender(content, code);
53
+ }
54
+ // script
55
+ await compileScript(content, sfc);
56
+ // style
57
+ for (let index = 0; index < styles.length; index++) {
58
+ const style = styles[index];
59
+ const file = replaceExt(sfc, `Sfc${index || ''}.${style.lang || 'css'}`);
60
+ const { base, dir } = parse(file);
61
+ const dependencyPath = normalizeStyleDependency(base, STYLE_IMPORT_RE);
62
+ const cssFile = resolve(dir, './style/index.js');
63
+ let { code } = compileStyle({
64
+ source: style.content,
65
+ filename: file,
66
+ id: scopeId,
67
+ scoped: style.scoped,
68
+ });
69
+ code = extractStyleDependencies(file, code, STYLE_IMPORT_RE);
70
+ writeFileSync(file, clearEmptyLine(code), 'utf-8');
71
+ smartAppendFileSync(cssFile, process.env.BABEL_MODULE === 'commonjs'
72
+ ? `require('${dependencyPath}.css')\n`
73
+ : `import '${dependencyPath}.css'\n`);
74
+ if (style.lang === 'less') {
75
+ await compileLess(file);
76
+ }
77
+ }
78
+ }
79
+ }
@@ -1,17 +1,17 @@
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;
13
- export declare const moduleCompatible: (script: string) => string;
14
- export declare function compileScript(script: string, file: string): Promise<void>;
15
- export declare function compileScriptFile(file: string): Promise<void>;
16
- export declare function compileESEntry(dir: string, publicDirs: string[]): Promise<void>;
17
- export declare function compileCommonJSEntry(dir: string, publicDirs: string[]): Promise<void>;
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;
13
+ export declare const moduleCompatible: (script: string) => Promise<string>;
14
+ export declare function compileScript(script: string, file: string): Promise<void>;
15
+ export declare function compileScriptFile(file: string): Promise<void>;
16
+ export declare function compileESEntry(dir: string, publicDirs: string[]): Promise<void>;
17
+ export declare function compileCommonJSEntry(dir: string, publicDirs: string[]): Promise<void>;