feat: 导出build函数

This commit is contained in:
Pan Qiancheng 2026-01-04 16:52:26 +08:00
parent 628cc31704
commit 78449b584b
3 changed files with 58 additions and 54 deletions

View File

@ -1 +1,2 @@
export declare const OAK_IGNORE_TAGS: string[];
export declare const build: (pwd: string, args: any[]) => void;

View File

@ -1,11 +1,10 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.OAK_IGNORE_TAGS = void 0;
exports.build = exports.OAK_IGNORE_TAGS = void 0;
const tslib_1 = require("tslib");
const ts = tslib_1.__importStar(require("typescript"));
const path = tslib_1.__importStar(require("path"));
const fs = tslib_1.__importStar(require("fs"));
const process_1 = require("process");
const verboseLogging = false;
const log = (...args) => {
if (verboseLogging) {
@ -25,8 +24,8 @@ const colors = {
gray: '\x1b[90m'
};
// 解析命令行参数
function parseArgs() {
const args = process.argv.slice(2);
function parseArgs(pargs) {
const args = pargs.slice(2);
let configPath = 'tsconfig.json';
for (let i = 0; i < args.length; i++) {
if (args[i] === '-p' || args[i] === '--project') {
@ -619,30 +618,33 @@ function compile(configPath) {
}
console.log('Compilation completed successfully.');
}
// 执行编译
const configPathArg = parseArgs();
let configPath;
// 判断参数是目录还是文件
if (fs.existsSync(configPathArg)) {
const stat = fs.statSync(configPathArg);
if (stat.isDirectory()) {
configPath = path.resolve(configPathArg, 'tsconfig.json');
}
else {
configPath = path.resolve(configPathArg);
}
}
else {
configPath = path.resolve((0, process_1.cwd)(), configPathArg);
if (!fs.existsSync(configPath)) {
const dirPath = path.resolve((0, process_1.cwd)(), configPathArg);
if (fs.existsSync(dirPath) && fs.statSync(dirPath).isDirectory()) {
configPath = path.join(dirPath, 'tsconfig.json');
const build = (pwd, args) => {
// 执行编译
const configPathArg = parseArgs(args);
let configPath;
// 判断参数是目录还是文件
if (fs.existsSync(configPathArg)) {
const stat = fs.statSync(configPathArg);
if (stat.isDirectory()) {
configPath = path.resolve(configPathArg, 'tsconfig.json');
}
else {
configPath = path.resolve(configPathArg);
}
}
}
if (!fs.existsSync(configPath)) {
console.error(`error TS5058: The specified path does not exist: '${configPath}'.`);
process.exit(1);
}
compile(configPath);
else {
configPath = path.resolve(pwd, configPathArg);
if (!fs.existsSync(configPath)) {
const dirPath = path.resolve(pwd, configPathArg);
if (fs.existsSync(dirPath) && fs.statSync(dirPath).isDirectory()) {
configPath = path.join(dirPath, 'tsconfig.json');
}
}
}
if (!fs.existsSync(configPath)) {
console.error(`error TS5058: The specified path does not exist: '${configPath}'.`);
process.exit(1);
}
compile(configPath);
};
exports.build = build;

View File

@ -1,7 +1,6 @@
import * as ts from 'typescript';
import * as path from 'path';
import * as fs from 'fs';
import { cwd } from 'process';
const verboseLogging = false;
@ -51,8 +50,8 @@ const colors = {
} as const;
// 解析命令行参数
function parseArgs(): string {
const args: string[] = process.argv.slice(2);
function parseArgs(pargs: string[]): string {
const args: string[] = pargs.slice(2);
let configPath = 'tsconfig.json';
for (let i = 0; i < args.length; i++) {
@ -790,31 +789,33 @@ function compile(configPath: string): void {
console.log('Compilation completed successfully.');
}
// 执行编译
const configPathArg: string = parseArgs();
let configPath: string;
export const build = (pwd: string, args: any[]) => {
// 执行编译
const configPathArg: string = parseArgs(args);
let configPath: string;
// 判断参数是目录还是文件
if (fs.existsSync(configPathArg)) {
const stat = fs.statSync(configPathArg);
if (stat.isDirectory()) {
configPath = path.resolve(configPathArg, 'tsconfig.json');
// 判断参数是目录还是文件
if (fs.existsSync(configPathArg)) {
const stat = fs.statSync(configPathArg);
if (stat.isDirectory()) {
configPath = path.resolve(configPathArg, 'tsconfig.json');
} else {
configPath = path.resolve(configPathArg);
}
} else {
configPath = path.resolve(configPathArg);
}
} else {
configPath = path.resolve(cwd(), configPathArg);
if (!fs.existsSync(configPath)) {
const dirPath = path.resolve(cwd(), configPathArg);
if (fs.existsSync(dirPath) && fs.statSync(dirPath).isDirectory()) {
configPath = path.join(dirPath, 'tsconfig.json');
configPath = path.resolve(pwd, configPathArg);
if (!fs.existsSync(configPath)) {
const dirPath = path.resolve(pwd, configPathArg);
if (fs.existsSync(dirPath) && fs.statSync(dirPath).isDirectory()) {
configPath = path.join(dirPath, 'tsconfig.json');
}
}
}
}
if (!fs.existsSync(configPath)) {
console.error(`error TS5058: The specified path does not exist: '${configPath}'.`);
process.exit(1);
}
if (!fs.existsSync(configPath)) {
console.error(`error TS5058: The specified path does not exist: '${configPath}'.`);
process.exit(1);
}
compile(configPath);
compile(configPath);
}