build: add files of vant-cli 2
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
import { join } from 'path';
|
||||
import { remove, copy, readdirSync } from 'fs-extra';
|
||||
import { clean } from './clean';
|
||||
import { compileJs } from '../compiler/compile-js';
|
||||
import { compileSfc } from '../compiler/compile-sfc';
|
||||
import { compileStyle } from '../compiler/compile-style';
|
||||
import { SRC_DIR, LIB_DIR, ES_DIR } from '../common/constant';
|
||||
import {
|
||||
isDir,
|
||||
isSfc,
|
||||
isDemoDir,
|
||||
isTestDir,
|
||||
isScript,
|
||||
isStyle
|
||||
} from '../common';
|
||||
|
||||
async function compileDir(dir: string) {
|
||||
const files = readdirSync(dir);
|
||||
|
||||
files.forEach(async filename => {
|
||||
const filePath = join(dir, filename);
|
||||
|
||||
if (isDemoDir(filePath) || isTestDir(filePath)) {
|
||||
await remove(filePath);
|
||||
} else if (isDir(filePath)) {
|
||||
await compileDir(filePath);
|
||||
} else if (isSfc(filePath)) {
|
||||
await compileSfc(filePath);
|
||||
} else if (isScript(filePath)) {
|
||||
await compileJs(filePath);
|
||||
} else if (isStyle(filePath)) {
|
||||
await compileStyle(filePath);
|
||||
} else {
|
||||
await remove(filePath);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function setModuleEnv(value: string) {
|
||||
process.env.BABEL_MODULE = value;
|
||||
}
|
||||
|
||||
export async function build() {
|
||||
clean();
|
||||
|
||||
await copy(SRC_DIR, ES_DIR);
|
||||
await copy(SRC_DIR, LIB_DIR);
|
||||
|
||||
setModuleEnv('esmodule');
|
||||
await compileDir(ES_DIR);
|
||||
|
||||
setModuleEnv('commonjs');
|
||||
await compileDir(LIB_DIR);
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import { join } from 'path';
|
||||
import { exec } from 'shelljs';
|
||||
|
||||
export function changelog(dist: string, cmd: { tag?: string }) {
|
||||
const basepath = process.cwd();
|
||||
const tag = cmd.tag || 'v1.0.0';
|
||||
|
||||
exec(`
|
||||
basepath=${basepath}
|
||||
|
||||
github_changelog_generator \
|
||||
--header-label "# 更新日志" \
|
||||
--bugs-label "**Bug Fixes**" \
|
||||
--enhancement-label "**Breaking changes**" \
|
||||
--issues-label "**Issue**" \
|
||||
--pr-label "**Features**" \
|
||||
--max-issues 0 \
|
||||
--no-author \
|
||||
--no-unreleased \
|
||||
--since-tag ${tag} \
|
||||
-o ${join(basepath, dist)}
|
||||
`);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
import { emptyDirSync } from 'fs-extra';
|
||||
import { ES_DIR, LIB_DIR, DIST_DIR } from '../common/constant';
|
||||
|
||||
export function clean() {
|
||||
emptyDirSync(ES_DIR);
|
||||
emptyDirSync(LIB_DIR);
|
||||
emptyDirSync(DIST_DIR);
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
import signale from 'signale';
|
||||
import { readFileSync } from 'fs';
|
||||
|
||||
const commitRE = /^(revert: )?(fix|feat|docs|perf|test|types|build|chore|refactor|breaking change)(\(.+\))?: .{1,50}/;
|
||||
|
||||
export function commitLint() {
|
||||
const gitParams = process.env.HUSKY_GIT_PARAMS as string;
|
||||
const commitMsg = readFileSync(gitParams, 'utf-8').trim();
|
||||
|
||||
if (!commitRE.test(commitMsg)) {
|
||||
signale.error(`Error: invalid commit message: "${commitMsg}".
|
||||
|
||||
Proper commit message format is required for automated changelog generation.
|
||||
|
||||
Examples:
|
||||
|
||||
- fix(Button): incorrect style
|
||||
- feat(Button): incorrect style
|
||||
- docs(Button): fix typo
|
||||
|
||||
Allowed Types:
|
||||
|
||||
- fix
|
||||
- feat
|
||||
- docs
|
||||
- perf
|
||||
- test
|
||||
- types
|
||||
- build
|
||||
- chore
|
||||
- refactor
|
||||
- breaking change
|
||||
`);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import webpack from 'webpack';
|
||||
import WebpackDevServer from 'webpack-dev-server';
|
||||
import webpackDevConfig from '../config/webpack.site.dev';
|
||||
import { getPort } from 'portfinder';
|
||||
import { clean } from '../commands/clean';
|
||||
import { genMobileConfig } from '../compiler/gen-mobile-config';
|
||||
import { genDesktopConfig } from '../compiler/gen-desktop-config';
|
||||
|
||||
function runWebpack() {
|
||||
const server = new WebpackDevServer(
|
||||
webpack(webpackDevConfig),
|
||||
(webpackDevConfig as any).devServer
|
||||
);
|
||||
|
||||
getPort(
|
||||
{
|
||||
port: 8080
|
||||
},
|
||||
(err, port) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return;
|
||||
}
|
||||
|
||||
server.listen(port, 'localhost', (err?: Error) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export function dev() {
|
||||
clean();
|
||||
genMobileConfig();
|
||||
genDesktopConfig();
|
||||
runWebpack();
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
import { start, error, success } from 'signale';
|
||||
import { lint as stylelint } from 'stylelint';
|
||||
import { CLIEngine } from 'eslint';
|
||||
|
||||
function lintScript() {
|
||||
start('ESLint Start');
|
||||
|
||||
const cli = new CLIEngine({
|
||||
fix: true,
|
||||
extensions: ['.js', '.jsx', '.vue', '.ts', '.tsx']
|
||||
});
|
||||
|
||||
const report = cli.executeOnFiles(['src/']);
|
||||
const formatter = cli.getFormatter();
|
||||
|
||||
CLIEngine.outputFixes(report);
|
||||
|
||||
// output lint errors
|
||||
const formatted = formatter(report.results);
|
||||
if (formatted) {
|
||||
error('ESLint Failed');
|
||||
console.log(formatter(report.results));
|
||||
} else {
|
||||
success('ESLint Passed');
|
||||
}
|
||||
}
|
||||
|
||||
function lintStyle() {
|
||||
start('Stylelint Start');
|
||||
|
||||
stylelint({
|
||||
fix: true,
|
||||
formatter: 'string',
|
||||
files: ['src/**/*.css', 'src/**/*.less', 'src/**/*.scss', 'src/**/*.vue']
|
||||
}).then(result => {
|
||||
if (result.errored) {
|
||||
error('Stylelint Failed');
|
||||
console.log(result.output);
|
||||
} else {
|
||||
success('Stylelint Passed');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function lint() {
|
||||
lintScript();
|
||||
lintStyle();
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
/* eslint-disable no-template-curly-in-string */
|
||||
import { build } from './build';
|
||||
// @ts-ignore
|
||||
import releaseIt from 'release-it';
|
||||
|
||||
export async function release() {
|
||||
await build();
|
||||
await releaseIt({
|
||||
git: {
|
||||
tagName: 'v${version}',
|
||||
commitMessage: 'chore: release ${version}'
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { runCLI } from 'jest';
|
||||
import { CWD, JEST_CONFIG_FILE } from '../common/constant';
|
||||
|
||||
export function test(command: any) {
|
||||
process.env.NODE_ENV = 'test';
|
||||
|
||||
const config = {
|
||||
rootDir: CWD,
|
||||
watch: command.watch,
|
||||
config: JEST_CONFIG_FILE
|
||||
} as any;
|
||||
|
||||
runCLI(config, [CWD]);
|
||||
}
|
||||
Reference in New Issue
Block a user