修改了对module类项目初始化的过程

This commit is contained in:
Xu Chang 2024-04-22 08:33:01 +08:00
parent 3b1ae9a27b
commit 25e4d022e0
15 changed files with 176 additions and 133 deletions

View File

@ -6,7 +6,6 @@ const cross_spawn_1 = tslib_1.__importDefault(require("cross-spawn"));
const path_1 = require("path"); const path_1 = require("path");
const makeLocale_1 = tslib_1.__importDefault(require("./makeLocale")); const makeLocale_1 = tslib_1.__importDefault(require("./makeLocale"));
const makeRouter_1 = tslib_1.__importDefault(require("./makeRouter")); const makeRouter_1 = tslib_1.__importDefault(require("./makeRouter"));
const makeDependency_1 = tslib_1.__importDefault(require("./makeDependency"));
const fs_1 = require("fs"); const fs_1 = require("fs");
async function build(cmd) { async function build(cmd) {
const mode = (cmd.mode || 'development'); const mode = (cmd.mode || 'development');
@ -24,11 +23,13 @@ async function build(cmd) {
: 'web'; : 'web';
} }
// 先makeLocale // 先makeLocale
(0, makeLocale_1.default)('', mode === 'development'); (0, makeLocale_1.default)({
watch: mode === 'development',
});
// 再尝试makeRouter // 再尝试makeRouter
(0, makeRouter_1.default)({ subdir }, mode === 'development'); (0, makeRouter_1.default)({ subdir }, mode === 'development');
// makeDependency // makeDependency 放到npm install之后做一次
(0, makeDependency_1.default)(''); // makeDep('');
//ts类型检查 waring 还是error, //ts类型检查 waring 还是error,
//主要web受影响error级别的话 控制台和网页都报错warning级别的话 控制台报错 //主要web受影响error级别的话 控制台和网页都报错warning级别的话 控制台报错
// development/staging/production // development/staging/production

View File

@ -139,16 +139,8 @@ async function create(dirName, cmd) {
}; };
prompt.unshift(nameOption); prompt.unshift(nameOption);
const isDev = cmd.dev ? true : false; const isDev = cmd.dev ? true : false;
const isModule = cmd.module ? true : false;
const { name, version, title, description } = await inquirer_1.default.prompt(prompt); const { name, version, title, description } = await inquirer_1.default.prompt(prompt);
// 获取package.json内容
const packageJson = (0, template_1.packageJsonContent)({
name: DEFAULT_PROJECT_NAME,
version,
description,
cliName: config_1.CLI_NAME,
cliBinName: config_1.CLI_BIN_NAME,
isDev,
});
// 获取tsconfig.json内容 // 获取tsconfig.json内容
const tsconfigJson = (0, template_1.tsConfigJsonContent)(); const tsconfigJson = (0, template_1.tsConfigJsonContent)();
const tsConfigBuildJson = (0, template_1.tsConfigBuildJsonContent)(); const tsConfigBuildJson = (0, template_1.tsConfigBuildJsonContent)();
@ -183,8 +175,6 @@ async function create(dirName, cmd) {
try { try {
// 创建根目录 // 创建根目录
(0, file_handle_1.checkFileExistsAndCreate)(rootPath); (0, file_handle_1.checkFileExistsAndCreate)(rootPath);
// 创建package.json
(0, file_handle_1.checkFileExistsAndCreate)(packageJsonPath, packageJson, enum_1.checkFileExistsAndCreateType.FILE);
// 创建tsconfig.json // 创建tsconfig.json
(0, file_handle_1.checkFileExistsAndCreate)(tsconfigJsonPath, tsconfigJson, enum_1.checkFileExistsAndCreateType.FILE); (0, file_handle_1.checkFileExistsAndCreate)(tsconfigJsonPath, tsconfigJson, enum_1.checkFileExistsAndCreateType.FILE);
// 创建tsconfig.build.json // 创建tsconfig.build.json
@ -198,17 +188,24 @@ async function create(dirName, cmd) {
// 创建tsconfig.web.json // 创建tsconfig.web.json
(0, file_handle_1.checkFileExistsAndCreate)(tsConfigWebJsonPath, tsConfigWebJson, enum_1.checkFileExistsAndCreateType.FILE); (0, file_handle_1.checkFileExistsAndCreate)(tsConfigWebJsonPath, tsConfigWebJson, enum_1.checkFileExistsAndCreateType.FILE);
// 复制项目文件 // 复制项目文件
(0, file_handle_1.copyFolder)(currentPath, rootPath); if (isModule) {
await createWechatMpBoilplate(weChatMpRootPath, isDev); // 模块化的项目只拷贝src和typings目录
await createWebBoilplate(webRootPath, isDev); (0, file_handle_1.copyFolder)((0, path_1.join)(currentPath, 'src'), (0, path_1.join)(rootPath, 'src'));
if (!shelljs_1.default.which('npm')) { (0, file_handle_1.copyFolder)((0, path_1.join)(currentPath, 'typings'), (0, path_1.join)(rootPath, 'typings'));
(0, tip_style_1.Warn)((0, tip_style_1.warn)('Sorry, this script requires npm! Please install npm!')); }
shelljs_1.default.exit(1); else {
(0, file_handle_1.copyFolder)(currentPath, rootPath);
await createWechatMpBoilplate(weChatMpRootPath, isDev);
await createWebBoilplate(webRootPath, isDev);
if (!shelljs_1.default.which('npm')) {
(0, tip_style_1.Warn)((0, tip_style_1.warn)('Sorry, this script requires npm! Please install npm!'));
shelljs_1.default.exit(1);
}
/* Success(`${success(`Waiting...`)}`);
Success(`${success(`Dependencies are now being installed`)}`);
shell.cd(dirName).exec('npm install'); */
(0, rename_1.renameProject)(rootPath, name, title, DEFAULT_PROJECT_NAME, DEFAULT_PROJECT_TITLE);
} }
/* Success(`${success(`Waiting...`)}`);
Success(`${success(`Dependencies are now being installed`)}`);
shell.cd(dirName).exec('npm install'); */
(0, rename_1.renameProject)(rootPath, name, title, DEFAULT_PROJECT_NAME, DEFAULT_PROJECT_TITLE);
(0, tip_style_1.Success)(`${(0, tip_style_1.success)(`Successfully created project ${(0, tip_style_1.primary)(name)}, directory name is ${(0, tip_style_1.primary)(dirName)}`)}`); (0, tip_style_1.Success)(`${(0, tip_style_1.success)(`Successfully created project ${(0, tip_style_1.primary)(name)}, directory name is ${(0, tip_style_1.primary)(dirName)}`)}`);
const { useOgb, moreDeps } = await inquirer_1.default.prompt([{ const { useOgb, moreDeps } = await inquirer_1.default.prompt([{
name: 'useOgb', name: 'useOgb',
@ -228,10 +225,23 @@ async function create(dirName, cmd) {
if (moreDeps) { if (moreDeps) {
deps.push(...(moreDeps.split(',').map(ele => ele.trim()).filter(ele => !!ele))); deps.push(...(moreDeps.split(',').map(ele => ele.trim()).filter(ele => !!ele)));
} }
shelljs_1.default.cd(dirName);
if (deps.length > 0) { if (deps.length > 0) {
shelljs_1.default.cd(dirName);
addDependencies(deps); addDependencies(deps);
} }
// 获取package.json内容
const packageJson = (0, template_1.packageJsonContent)({
name: DEFAULT_PROJECT_NAME,
version,
description,
cliName: config_1.CLI_NAME,
cliBinName: config_1.CLI_BIN_NAME,
isDev,
isModule,
dependencies: deps,
});
// 创建package.json
(0, file_handle_1.checkFileExistsAndCreate)(packageJsonPath, packageJson, enum_1.checkFileExistsAndCreateType.FILE);
(0, tip_style_1.Success)(`${(0, tip_style_1.success)(`Ok, type 'npm install' to install libs, then start!`)}`); (0, tip_style_1.Success)(`${(0, tip_style_1.success)(`Ok, type 'npm install' to install libs, then start!`)}`);
} }
catch (err) { catch (err) {

View File

@ -50,6 +50,8 @@ commander_1.default
commander_1.default commander_1.default
.command('make:locale') .command('make:locale')
.description('make locales') .description('make locales')
.option('-a --asLib', 'asLib')
.option('-w --watch', 'watch')
.action(makeLocale_1.default); .action(makeLocale_1.default);
commander_1.default commander_1.default
.command('make:dependency') .command('make:dependency')
@ -85,6 +87,7 @@ commander_1.default
.command('create <name>') .command('create <name>')
.usage('<name>') .usage('<name>')
.option('-d, --dev', 'dev') .option('-d, --dev', 'dev')
.option('-m, --module', 'module')
.description(`create a new project powered by ${config_1.CLI_NAME}`) .description(`create a new project powered by ${config_1.CLI_NAME}`)
.action(create_1.create); .action(create_1.create);
commander_1.default commander_1.default

2
lib/interface.d.ts vendored
View File

@ -10,6 +10,8 @@ export interface PackageJsonInput {
cliName: string; cliName: string;
cliBinName: string; cliBinName: string;
isDev?: boolean; isDev?: boolean;
dependencies?: string[];
isModule: boolean;
} }
/** /**
* @name Prompt需要输入的参数 * @name Prompt需要输入的参数

2
lib/makeLocale.d.ts vendored
View File

@ -1 +1 @@
export default function make(cmd: any, watch?: boolean): Promise<void>; export default function make(cmd: any): Promise<void>;

View File

@ -2,34 +2,20 @@
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib"); const tslib_1 = require("tslib");
const tip_style_1 = require("./tip-style"); const tip_style_1 = require("./tip-style");
const cross_spawn_1 = tslib_1.__importDefault(require("cross-spawn")); const localeBuilder_1 = tslib_1.__importDefault(require("oak-domain/lib/compiler/localeBuilder"));
const path_1 = require("path"); async function make(cmd) {
async function make(cmd, watch) {
(0, tip_style_1.Success)(`${(0, tip_style_1.success)(`make locales`)}`); (0, tip_style_1.Success)(`${(0, tip_style_1.success)(`make locales`)}`);
// ts-node scripts/build-app-domain & npm link ./app-domain const asLib = cmd.asLib;
const args = [(0, path_1.resolve)(__dirname, '../scripts/make-locale.js')]; const watch = cmd.watch;
if (watch) { try {
args.push('true'); const builder = new localeBuilder_1.default(!!asLib);
builder.build(!!watch);
(0, tip_style_1.Success)(`${(0, tip_style_1.success)(`make 执行完成`)}`);
} }
if (!watch) { catch (err) {
const result = cross_spawn_1.default.sync('ts-node', args, { (0, tip_style_1.Error)(`${(0, tip_style_1.error)(`make 执行失败`)}`);
stdio: 'inherit', console.error(err);
shell: true, process.exit(-1);
});
// const result2 = spawn.sync('npm -v', [], { stdio: 'inherit', shell: true });
if (result.status === 0) {
(0, tip_style_1.Success)(`${(0, tip_style_1.success)(`make 执行完成`)}`);
}
else {
(0, tip_style_1.Error)(`${(0, tip_style_1.error)(`make 执行失败`)}`);
process.exit(-1);
}
}
else {
(0, cross_spawn_1.default)('ts-node', args, {
stdio: 'inherit',
shell: true,
});
} }
} }
exports.default = make; exports.default = make;

2
lib/template.d.ts vendored
View File

@ -1,5 +1,5 @@
import { PackageJsonInput } from './interface'; import { PackageJsonInput } from './interface';
export declare function packageJsonContent({ name, version, description, cliName, cliBinName, isDev, }: PackageJsonInput): string; export declare function packageJsonContent({ name, version, description, cliName, cliBinName, isDev, isModule, dependencies }: PackageJsonInput): string;
export declare function tsConfigJsonContent(): string; export declare function tsConfigJsonContent(): string;
export declare function tsConfigBuildJsonContent(): string; export declare function tsConfigBuildJsonContent(): string;
export declare function tsConfigBuildPathsJsonContent(): string; export declare function tsConfigBuildPathsJsonContent(): string;

View File

@ -2,6 +2,8 @@
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.oakConfigContentWithWeb = exports.oakConfigContentWithWeChatMp = exports.appJsonContentWithWeChatMp = exports.projectConfigContentWithWeChatMp = exports.tsConfigWebJsonContent = exports.tsConfigMpJsonContent = exports.tsConfigPathsJsonContent = exports.tsConfigBuildPathsJsonContent = exports.tsConfigBuildJsonContent = exports.tsConfigJsonContent = exports.packageJsonContent = void 0; exports.oakConfigContentWithWeb = exports.oakConfigContentWithWeChatMp = exports.appJsonContentWithWeChatMp = exports.projectConfigContentWithWeChatMp = exports.tsConfigWebJsonContent = exports.tsConfigMpJsonContent = exports.tsConfigPathsJsonContent = exports.tsConfigBuildPathsJsonContent = exports.tsConfigBuildJsonContent = exports.tsConfigJsonContent = exports.packageJsonContent = void 0;
const child_process_1 = require("child_process"); const child_process_1 = require("child_process");
const fs_1 = require("fs");
const path_1 = require("path");
/** /**
* 利用npm info获得相应库的最新版本 * 利用npm info获得相应库的最新版本
* @param name * @param name
@ -12,9 +14,9 @@ function getPackageLatestVersion(name) {
const data = result.match(/latest: \d\.\d\.\d\s*published/g); const data = result.match(/latest: \d\.\d\.\d\s*published/g);
return data[0].slice(8, 13); return data[0].slice(8, 13);
} }
function packageJsonContent({ name, version, description, cliName, cliBinName, isDev, }) { function packageJsonContent({ name, version, description, cliName, cliBinName, isDev, isModule, dependencies }) {
let oakDependencyStr; let oakDependencyStr = '';
let oakDevDependencyStr; let oakDevDependencyStr = '';
if (isDev) { if (isDev) {
oakDependencyStr = ` oakDependencyStr = `
"oak-backend-base": "file:../oak-backend-base", "oak-backend-base": "file:../oak-backend-base",
@ -23,8 +25,17 @@ function packageJsonContent({ name, version, description, cliName, cliBinName, i
"oak-domain": "file:../oak-domain", "oak-domain": "file:../oak-domain",
"oak-external-sdk": "file:../oak-external-sdk", "oak-external-sdk": "file:../oak-external-sdk",
"oak-frontend-base": "file:../oak-frontend-base", "oak-frontend-base": "file:../oak-frontend-base",
"oak-general-business": "file:../oak-general-business",
"oak-memory-tree-store": "file:../oak-memory-tree-store",`; "oak-memory-tree-store": "file:../oak-memory-tree-store",`;
if (dependencies?.length) {
dependencies?.forEach((dep) => {
if ((0, fs_1.existsSync)((0, path_1.join)(process.cwd(), '..', dep))) {
oakDependencyStr += `\n"${dep}": "file:../${dep}",`;
}
else {
oakDependencyStr += `\n"${dep}": "^${getPackageLatestVersion(dep)}"`;
}
});
}
oakDevDependencyStr = `"${cliName}": "file:../oak-cli",`; oakDevDependencyStr = `"${cliName}": "file:../oak-cli",`;
} }
else { else {
@ -36,8 +47,12 @@ function packageJsonContent({ name, version, description, cliName, cliBinName, i
"oak-domain": "^${getPackageLatestVersion('oak-domain')}", "oak-domain": "^${getPackageLatestVersion('oak-domain')}",
"oak-external-sdk": "^${getPackageLatestVersion('oak-external-sdk')}", "oak-external-sdk": "^${getPackageLatestVersion('oak-external-sdk')}",
"oak-frontend-base": "^${getPackageLatestVersion('oak-frontend-base')}", "oak-frontend-base": "^${getPackageLatestVersion('oak-frontend-base')}",
"oak-general-business": "^${getPackageLatestVersion('oak-general-business')}",
"oak-memory-tree-store": "^${getPackageLatestVersion('oak-memory-tree-store')}",`; "oak-memory-tree-store": "^${getPackageLatestVersion('oak-memory-tree-store')}",`;
if (dependencies?.length) {
dependencies?.forEach((dep) => {
oakDependencyStr += `\n"${dep}": "^${getPackageLatestVersion(dep)}"`;
});
}
oakDevDependencyStr = `"${cliName}": "^${getPackageLatestVersion(cliName)}",`; oakDevDependencyStr = `"${cliName}": "^${getPackageLatestVersion(cliName)}",`;
} }
const serverInitScript = isDev ? "cross-env NODE_ENV=development cross-env OAK_PLATFORM=server node scripts/initServer.js" : "cross-env OAK_PLATFORM=server node scripts/initServer.js"; const serverInitScript = isDev ? "cross-env NODE_ENV=development cross-env OAK_PLATFORM=server node scripts/initServer.js" : "cross-env OAK_PLATFORM=server node scripts/initServer.js";
@ -47,8 +62,8 @@ function packageJsonContent({ name, version, description, cliName, cliBinName, i
"version": "${version}", "version": "${version}",
"description": "${description}", "description": "${description}",
"scripts": { "scripts": {
"make:domain": "${cliBinName} make:domain", "make:domain": "${isModule ? `cross-env COMPLING_AS_LIB=yes ${cliBinName}` : cliBinName} make:domain",
"make:locale": "${cliBinName} make:locale", "make:locale": "${cliBinName} make:locale ${isModule ? '-m' : ''}",
"make:dep": "${cliBinName} make:dependency", "make:dep": "${cliBinName} make:dependency",
"clean:cache": "rimraf node_modules/.cache", "clean:cache": "rimraf node_modules/.cache",
"copy-config-json": "copyfiles -u 1 src/config/*.json lib/", "copy-config-json": "copyfiles -u 1 src/config/*.json lib/",
@ -68,12 +83,12 @@ function packageJsonContent({ name, version, description, cliName, cliBinName, i
"build-analyze:web": "${cliBinName} build --target web --mode production --analyze", "build-analyze:web": "${cliBinName} build --target web --mode production --analyze",
"build-sourcemap-analyze:web": "${cliBinName} build --target web --mode production --sourcemap --analyze", "build-sourcemap-analyze:web": "${cliBinName} build --target web --mode production --sourcemap --analyze",
"build": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json && npm run copy-config-json", "build": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json && npm run copy-config-json",
"prebuild": "npm run make:locale && npm run make:dep", "prebuild": "npm run make:locale",
"run:ios": "oak-cli run -p ios", "run:ios": "oak-cli run -p ios",
"run:android": "oak-cli run -p android", "run:android": "oak-cli run -p android",
"server:init": "${serverInitScript}", "server:init": "${serverInitScript}",
"server:start": "${serverStartScript}", "server:start": "${serverStartScript}",
"postinstall": "npm run make:domain" "postinstall": "npm run make:dep"
}, },
"keywords": [], "keywords": [],
"author": "", "author": "",

View File

@ -1,5 +1,6 @@
const watch = process.argv[2]; const watch = new Boolean(process.argv[2]);
const asLib = new Boolean(process.argv[3]);
const LocaleBuilder = require('oak-domain/lib/compiler/localeBuilder').default; const LocaleBuilder = require('oak-domain/lib/compiler/localeBuilder').default;
const builder = new LocaleBuilder(false); const builder = new LocaleBuilder(!!asLib);
builder.build(!!watch); builder.build(!!watch);

View File

@ -37,7 +37,9 @@ export default async function build(cmd: any) {
: 'web'; : 'web';
} }
// 先makeLocale // 先makeLocale
makeLocale('', mode === 'development'); makeLocale({
watch: mode === 'development',
});
// 再尝试makeRouter // 再尝试makeRouter
makeRouter({ subdir }, mode === 'development'); makeRouter({ subdir }, mode === 'development');
// makeDependency 放到npm install之后做一次 // makeDependency 放到npm install之后做一次

View File

@ -83,7 +83,7 @@ function addDependencies(dependencies: string[]) {
const stmt1 = statements[1]; const stmt1 = statements[1];
assert(ts.isVariableStatement(stmt1)); assert(ts.isVariableStatement(stmt1));
const { declarationList: { declarations: [ vd ]}} = stmt1; const { declarationList: { declarations: [vd] } } = stmt1;
const { name, initializer } = vd; const { name, initializer } = vd;
assert(ts.isIdentifier(name) && name.text === 'dependencyConfiguration'); assert(ts.isIdentifier(name) && name.text === 'dependencyConfiguration');
assert(ts.isArrayLiteralExpression(initializer!)); assert(ts.isArrayLiteralExpression(initializer!));
@ -222,19 +222,11 @@ export async function create(dirName: string, cmd: any) {
}; };
prompt.unshift(nameOption); prompt.unshift(nameOption);
const isDev = cmd.dev ? true : false; const isDev = cmd.dev ? true : false;
const isModule = cmd.module ? true : false;
const { name, version, title, description }: PromptInput = await inquirer.prompt( const { name, version, title, description }: PromptInput = await inquirer.prompt(
prompt prompt
); );
// 获取package.json内容
const packageJson = packageJsonContent({
name: DEFAULT_PROJECT_NAME, // 后面再统一rename
version,
description,
cliName: CLI_NAME,
cliBinName: CLI_BIN_NAME,
isDev,
});
// 获取tsconfig.json内容 // 获取tsconfig.json内容
const tsconfigJson = tsConfigJsonContent(); const tsconfigJson = tsConfigJsonContent();
@ -272,12 +264,6 @@ export async function create(dirName: string, cmd: any) {
try { try {
// 创建根目录 // 创建根目录
checkFileExistsAndCreate(rootPath); checkFileExistsAndCreate(rootPath);
// 创建package.json
checkFileExistsAndCreate(
packageJsonPath,
packageJson,
checkFileExistsAndCreateType.FILE
);
// 创建tsconfig.json // 创建tsconfig.json
checkFileExistsAndCreate( checkFileExistsAndCreate(
tsconfigJsonPath, tsconfigJsonPath,
@ -315,20 +301,28 @@ export async function create(dirName: string, cmd: any) {
checkFileExistsAndCreateType.FILE checkFileExistsAndCreateType.FILE
); );
// 复制项目文件 // 复制项目文件
copyFolder(currentPath, rootPath); if (isModule) {
// 模块化的项目只拷贝src和typings目录
copyFolder(join(currentPath, 'src'), join(rootPath, 'src'));
copyFolder(join(currentPath, 'typings'), join(rootPath, 'typings'));
}
else {
copyFolder(currentPath, rootPath);
await createWechatMpBoilplate(weChatMpRootPath, isDev); await createWechatMpBoilplate(weChatMpRootPath, isDev);
await createWebBoilplate(webRootPath, isDev); await createWebBoilplate(webRootPath, isDev);
if (!shell.which('npm')) { if (!shell.which('npm')) {
Warn(warn('Sorry, this script requires npm! Please install npm!')); Warn(warn('Sorry, this script requires npm! Please install npm!'));
shell.exit(1); shell.exit(1);
}
/* Success(`${success(`Waiting...`)}`);
Success(`${success(`Dependencies are now being installed`)}`);
shell.cd(dirName).exec('npm install'); */
renameProject(rootPath, name, title, DEFAULT_PROJECT_NAME, DEFAULT_PROJECT_TITLE);
} }
/* Success(`${success(`Waiting...`)}`);
Success(`${success(`Dependencies are now being installed`)}`);
shell.cd(dirName).exec('npm install'); */
renameProject(rootPath, name, title, DEFAULT_PROJECT_NAME, DEFAULT_PROJECT_TITLE);
Success( Success(
`${success( `${success(
@ -362,11 +356,31 @@ export async function create(dirName: string, cmd: any) {
)) ))
); );
} }
shell.cd(dirName);
if (deps.length > 0) { if (deps.length > 0) {
shell.cd(dirName);
addDependencies(deps); addDependencies(deps);
} }
// 获取package.json内容
const packageJson = packageJsonContent({
name: DEFAULT_PROJECT_NAME, // 后面再统一rename
version,
description,
cliName: CLI_NAME,
cliBinName: CLI_BIN_NAME,
isDev,
isModule,
dependencies: deps,
});
// 创建package.json
checkFileExistsAndCreate(
packageJsonPath,
packageJson,
checkFileExistsAndCreateType.FILE
);
Success( Success(
`${success( `${success(
`Ok, type 'npm install' to install libs, then start!` `Ok, type 'npm install' to install libs, then start!`

View File

@ -55,6 +55,8 @@ program
program program
.command('make:locale') .command('make:locale')
.description('make locales') .description('make locales')
.option('-a --asLib', 'asLib')
.option('-w --watch', 'watch')
.action(makeLocale); .action(makeLocale);
@ -94,6 +96,7 @@ program
.command('create <name>') .command('create <name>')
.usage('<name>') .usage('<name>')
.option('-d, --dev', 'dev') .option('-d, --dev', 'dev')
.option('-m, --module', 'module')
.description(`create a new project powered by ${CLI_NAME}`) .description(`create a new project powered by ${CLI_NAME}`)
.action(create); .action(create);
program program

View File

@ -12,6 +12,8 @@ export interface PackageJsonInput {
cliName: string; cliName: string;
cliBinName: string; cliBinName: string;
isDev?: boolean; isDev?: boolean;
dependencies?: string[];
isModule: boolean;
} }
/** /**

View File

@ -9,40 +9,22 @@ import {
} from './tip-style'; } from './tip-style';
import spawn from 'cross-spawn'; import spawn from 'cross-spawn';
import { resolve } from 'path'; import { resolve } from 'path';
import LocaleBuilder from 'oak-domain/lib/compiler/localeBuilder';
export default async function make(cmd: any, watch?: boolean) { export default async function make(cmd: any) {
Success(`${success(`make locales`)}`); Success(`${success(`make locales`)}`);
// ts-node scripts/build-app-domain & npm link ./app-domain const asLib = cmd.asLib;
const args = [resolve(__dirname, '../scripts/make-locale.js')]; const watch = cmd.watch;
if (watch) {
args.push('true'); try {
} const builder = new LocaleBuilder(!!asLib);
if (!watch) {
const result = spawn.sync(
'ts-node',
args,
{
stdio: 'inherit',
shell: true,
}
);
// const result2 = spawn.sync('npm -v', [], { stdio: 'inherit', shell: true });
if (result.status === 0) { builder.build(!!watch);
Success(`${success(`make 执行完成`)}`); Success(`${success(`make 执行完成`)}`);
} else {
Error(`${error(`make 执行失败`)}`);
process.exit(-1);
}
} }
else { catch (err: any) {
spawn( Error(`${error(`make 执行失败`)}`);
'ts-node', console.error(err);
args, process.exit(-1);
{
stdio: 'inherit',
shell: true,
}
);
} }
} }

View File

@ -1,4 +1,6 @@
import { execSync } from 'child_process'; import { execSync } from 'child_process';
import { existsSync } from 'fs';
import { join } from 'path';
import { PackageJsonInput } from './interface'; import { PackageJsonInput } from './interface';
/** /**
@ -20,9 +22,11 @@ export function packageJsonContent({
cliName, cliName,
cliBinName, cliBinName,
isDev, isDev,
isModule,
dependencies
}: PackageJsonInput) { }: PackageJsonInput) {
let oakDependencyStr; let oakDependencyStr = '';
let oakDevDependencyStr; let oakDevDependencyStr = '';
if (isDev) { if (isDev) {
oakDependencyStr = ` oakDependencyStr = `
"oak-backend-base": "file:../oak-backend-base", "oak-backend-base": "file:../oak-backend-base",
@ -31,8 +35,20 @@ export function packageJsonContent({
"oak-domain": "file:../oak-domain", "oak-domain": "file:../oak-domain",
"oak-external-sdk": "file:../oak-external-sdk", "oak-external-sdk": "file:../oak-external-sdk",
"oak-frontend-base": "file:../oak-frontend-base", "oak-frontend-base": "file:../oak-frontend-base",
"oak-general-business": "file:../oak-general-business",
"oak-memory-tree-store": "file:../oak-memory-tree-store",`; "oak-memory-tree-store": "file:../oak-memory-tree-store",`;
if (dependencies?.length) {
dependencies?.forEach(
(dep) => {
if (existsSync(join(process.cwd(), '..', dep))) {
oakDependencyStr += `\n"${dep}": "file:../${dep}",`;
}
else {
oakDependencyStr += `\n"${dep}": "^${getPackageLatestVersion(dep)}"`;
}
}
);
}
oakDevDependencyStr = `"${cliName}": "file:../oak-cli",` oakDevDependencyStr = `"${cliName}": "file:../oak-cli",`
} }
else { else {
@ -44,8 +60,14 @@ export function packageJsonContent({
"oak-domain": "^${getPackageLatestVersion('oak-domain')}", "oak-domain": "^${getPackageLatestVersion('oak-domain')}",
"oak-external-sdk": "^${getPackageLatestVersion('oak-external-sdk')}", "oak-external-sdk": "^${getPackageLatestVersion('oak-external-sdk')}",
"oak-frontend-base": "^${getPackageLatestVersion('oak-frontend-base')}", "oak-frontend-base": "^${getPackageLatestVersion('oak-frontend-base')}",
"oak-general-business": "^${getPackageLatestVersion('oak-general-business')}",
"oak-memory-tree-store": "^${getPackageLatestVersion('oak-memory-tree-store')}",`; "oak-memory-tree-store": "^${getPackageLatestVersion('oak-memory-tree-store')}",`;
if (dependencies?.length) {
dependencies?.forEach(
(dep) => {
oakDependencyStr += `\n"${dep}": "^${getPackageLatestVersion(dep)}"`;
}
);
}
oakDevDependencyStr = `"${cliName}": "^${getPackageLatestVersion(cliName)}",` oakDevDependencyStr = `"${cliName}": "^${getPackageLatestVersion(cliName)}",`
} }
@ -56,8 +78,8 @@ export function packageJsonContent({
"version": "${version}", "version": "${version}",
"description": "${description}", "description": "${description}",
"scripts": { "scripts": {
"make:domain": "${cliBinName} make:domain", "make:domain": "${isModule ? `cross-env COMPLING_AS_LIB=yes ${cliBinName}` : cliBinName} make:domain",
"make:locale": "${cliBinName} make:locale", "make:locale": "${cliBinName} make:locale ${isModule ? '-m' : ''}",
"make:dep": "${cliBinName} make:dependency", "make:dep": "${cliBinName} make:dependency",
"clean:cache": "rimraf node_modules/.cache", "clean:cache": "rimraf node_modules/.cache",
"copy-config-json": "copyfiles -u 1 src/config/*.json lib/", "copy-config-json": "copyfiles -u 1 src/config/*.json lib/",
@ -77,12 +99,12 @@ export function packageJsonContent({
"build-analyze:web": "${cliBinName} build --target web --mode production --analyze", "build-analyze:web": "${cliBinName} build --target web --mode production --analyze",
"build-sourcemap-analyze:web": "${cliBinName} build --target web --mode production --sourcemap --analyze", "build-sourcemap-analyze:web": "${cliBinName} build --target web --mode production --sourcemap --analyze",
"build": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json && npm run copy-config-json", "build": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json && npm run copy-config-json",
"prebuild": "npm run make:locale && npm run make:dep", "prebuild": "npm run make:locale",
"run:ios": "oak-cli run -p ios", "run:ios": "oak-cli run -p ios",
"run:android": "oak-cli run -p android", "run:android": "oak-cli run -p android",
"server:init": "${serverInitScript}", "server:init": "${serverInitScript}",
"server:start": "${serverStartScript}", "server:start": "${serverStartScript}",
"postinstall": "${cliBinName} make:dependency" "postinstall": "npm run make:dep"
}, },
"keywords": [], "keywords": [],
"author": "", "author": "",