mirror of
https://gitee.com/bootx/dax-pay-ui.git
synced 2025-09-09 05:29:32 +00:00
initial commit
This commit is contained in:
39
build/script/changelog.ts
Normal file
39
build/script/changelog.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
// #!/usr/bin/env node
|
||||
|
||||
import { sh } from 'tasksfile';
|
||||
import chalk from 'chalk';
|
||||
|
||||
const createChangeLog = async () => {
|
||||
try {
|
||||
let cmd = `conventional-changelog -p angular -i CHANGELOG.md -s -r 0 `;
|
||||
// let cmd = `conventional-changelog -p angular -i CHANGELOG.md -s -r 0 `;
|
||||
// if (shell.which('git')) {
|
||||
// cmd += '&& git add CHANGELOG.md';
|
||||
// }
|
||||
await sh(cmd, {
|
||||
async: true,
|
||||
nopipe: true,
|
||||
});
|
||||
|
||||
await sh('prettier --write **/CHANGELOG.md ', {
|
||||
async: true,
|
||||
nopipe: true,
|
||||
});
|
||||
console.log(
|
||||
chalk.blue.bold('**************** ') +
|
||||
chalk.green.bold('CHANGE_LOG generated successfully!') +
|
||||
chalk.blue.bold(' ****************')
|
||||
);
|
||||
} catch (error) {
|
||||
console.log(
|
||||
chalk.blue.red('**************** ') +
|
||||
chalk.green.red('CHANGE_LOG generated error\n' + error) +
|
||||
chalk.blue.red(' ****************')
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
};
|
||||
createChangeLog();
|
||||
module.exports = {
|
||||
createChangeLog,
|
||||
};
|
10
build/script/postinstall.ts
Normal file
10
build/script/postinstall.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { exec, which } from 'shelljs';
|
||||
|
||||
function ignoreCaseGit() {
|
||||
try {
|
||||
if (which('git')) {
|
||||
exec('git config core.ignorecase false ');
|
||||
}
|
||||
} catch (error) {}
|
||||
}
|
||||
ignoreCaseGit();
|
67
build/script/preserve.ts
Normal file
67
build/script/preserve.ts
Normal file
@@ -0,0 +1,67 @@
|
||||
// 是否需要更新依赖,防止package.json更新了依赖,其他人获取代码后没有install
|
||||
|
||||
import path from 'path';
|
||||
import fs from 'fs-extra';
|
||||
import { isEqual } from 'lodash';
|
||||
import chalk from 'chalk';
|
||||
import { sh } from 'tasksfile';
|
||||
|
||||
const resolve = (dir: string) => {
|
||||
return path.resolve(process.cwd(), dir);
|
||||
};
|
||||
|
||||
let NEED_INSTALL = false;
|
||||
|
||||
fs.mkdirp(resolve('build/.cache'));
|
||||
function checkPkgUpdate() {
|
||||
const pkg = require('../../package.json');
|
||||
const { dependencies, devDependencies } = pkg;
|
||||
const depsFile = resolve('build/.cache/deps.json');
|
||||
if (!fs.pathExistsSync(depsFile)) {
|
||||
NEED_INSTALL = true;
|
||||
return;
|
||||
}
|
||||
const depsJson = require('../.cache/deps.json');
|
||||
|
||||
if (!isEqual(depsJson, { dependencies, devDependencies })) {
|
||||
NEED_INSTALL = true;
|
||||
}
|
||||
}
|
||||
checkPkgUpdate();
|
||||
|
||||
(async () => {
|
||||
if (NEED_INSTALL) {
|
||||
console.log(
|
||||
chalk.blue.bold('**************** ') +
|
||||
chalk.red.bold('检测到依赖变化,正在安装依赖(Tip: 项目首次运行也会执行)!') +
|
||||
chalk.blue.bold(' ****************')
|
||||
);
|
||||
try {
|
||||
// 从代码执行貌似不会自动读取.npmrc 所以手动加上源地址
|
||||
// await run('yarn install --registry=https://registry.npm.taobao.org ', {
|
||||
await sh('yarn install ', {
|
||||
async: true,
|
||||
nopipe: true,
|
||||
});
|
||||
console.log(
|
||||
chalk.blue.bold('**************** ') +
|
||||
chalk.green.bold('依赖安装成功,正在运行!') +
|
||||
chalk.blue.bold(' ****************')
|
||||
);
|
||||
|
||||
const pkg = require('../../package.json');
|
||||
const { dependencies, devDependencies } = pkg;
|
||||
const depsFile = resolve('build/.cache/deps.json');
|
||||
const deps = { dependencies, devDependencies };
|
||||
if (!fs.pathExistsSync(depsFile)) {
|
||||
fs.writeFileSync(depsFile, JSON.stringify(deps));
|
||||
} else {
|
||||
const depsFile = resolve('build/.cache/deps.json');
|
||||
const depsJson = require('../.cache/deps.json');
|
||||
if (!isEqual(depsJson, deps)) {
|
||||
fs.writeFileSync(depsFile, JSON.stringify(deps));
|
||||
}
|
||||
}
|
||||
} catch (error) {}
|
||||
}
|
||||
})();
|
70
build/script/preview.ts
Normal file
70
build/script/preview.ts
Normal file
@@ -0,0 +1,70 @@
|
||||
import chalk from 'chalk';
|
||||
import Koa from 'koa';
|
||||
import inquirer from 'inquirer';
|
||||
import { sh } from 'tasksfile';
|
||||
import staticServer from 'koa-static';
|
||||
import portfinder from 'portfinder';
|
||||
import { resolve } from 'path';
|
||||
import viteConfig from '../../vite.config';
|
||||
import { getIPAddress } from '../utils';
|
||||
|
||||
const BUILD = 1;
|
||||
const NO_BUILD = 2;
|
||||
|
||||
// 启动服务器
|
||||
const startApp = () => {
|
||||
const port = 9680;
|
||||
portfinder.basePort = port;
|
||||
const app = new Koa();
|
||||
// const connect = require('connect');
|
||||
// const serveStatic = require('serve-static');
|
||||
// const app = connect();
|
||||
|
||||
app.use(staticServer(resolve(process.cwd(), viteConfig.outDir || 'dist')));
|
||||
|
||||
portfinder.getPort(async (err, port) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
} else {
|
||||
// const publicPath = process.env.BASE_URL;
|
||||
app.listen(port, function () {
|
||||
const empty = ' ';
|
||||
const common = `The preview program is already running:
|
||||
- LOCAL: http://localhost:${port}/
|
||||
- NETWORK: http://${getIPAddress()}:${port}/
|
||||
`;
|
||||
console.log(chalk.cyan('\n' + empty + common));
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const preview = async () => {
|
||||
const prompt = inquirer.prompt({
|
||||
type: 'list',
|
||||
message: 'Please select a preview method',
|
||||
name: 'type',
|
||||
choices: [
|
||||
{
|
||||
name: 'Preview after packaging',
|
||||
value: BUILD,
|
||||
},
|
||||
{
|
||||
name: `No packaging, preview directly (need to have dist file after packaging)`,
|
||||
value: NO_BUILD,
|
||||
},
|
||||
],
|
||||
});
|
||||
const { type } = await prompt;
|
||||
if (type === BUILD) {
|
||||
await sh('npm run build', {
|
||||
async: true,
|
||||
nopipe: true,
|
||||
});
|
||||
}
|
||||
startApp();
|
||||
};
|
||||
|
||||
(() => {
|
||||
preview();
|
||||
})();
|
Reference in New Issue
Block a user