diff --git a/lib/config.d.ts b/lib/config.d.ts index 79e64b3..3b3ea0d 100644 --- a/lib/config.d.ts +++ b/lib/config.d.ts @@ -1,5 +1,6 @@ export declare const CLI_VERSION: any; -export declare const CLI_NAME: string; +export declare const CLI_NAME: any; +export declare const CLI_BIN_NAME: string; export declare const BASE_DIR: string; export declare const USER_CONFIG_FILE_NAME = "oak.config.json"; export declare const USER_CONFIG_FILE: string; diff --git a/lib/config.js b/lib/config.js index a0dc373..0eb24d0 100644 --- a/lib/config.js +++ b/lib/config.js @@ -1,8 +1,9 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.MINI_VERSION_URL = exports.CNPM_BASE_URL = exports.NODE_MODULES_DIR_NAME = exports.USER_CONFIG_FILE = exports.USER_CONFIG_FILE_NAME = exports.BASE_DIR = exports.CLI_NAME = exports.CLI_VERSION = void 0; +exports.MINI_VERSION_URL = exports.CNPM_BASE_URL = exports.NODE_MODULES_DIR_NAME = exports.USER_CONFIG_FILE = exports.USER_CONFIG_FILE_NAME = exports.BASE_DIR = exports.CLI_BIN_NAME = exports.CLI_NAME = exports.CLI_VERSION = void 0; exports.CLI_VERSION = require('../package.json')['version']; -exports.CLI_NAME = Object.keys(require('../package.json')['bin'])[0]; +exports.CLI_NAME = require('../package.json')['name']; +exports.CLI_BIN_NAME = Object.keys(require('../package.json')['bin'])[0]; exports.BASE_DIR = process.cwd(); exports.USER_CONFIG_FILE_NAME = 'oak.config.json'; exports.USER_CONFIG_FILE = exports.BASE_DIR + '/' + exports.USER_CONFIG_FILE_NAME; diff --git a/lib/create.js b/lib/create.js index 3887873..769cb67 100644 --- a/lib/create.js +++ b/lib/create.js @@ -108,8 +108,9 @@ async function create(dirName, cmd) { name, version, description, - cliversion: config_1.CLI_VERSION, - cliname: config_1.CLI_NAME, + cliVersion: config_1.CLI_VERSION, + cliName: config_1.CLI_NAME, + cliBinName: config_1.CLI_BIN_NAME, isDev, }); // 获取tsconfig.json内容 diff --git a/lib/interface.d.ts b/lib/interface.d.ts index a7367cf..569f81a 100644 --- a/lib/interface.d.ts +++ b/lib/interface.d.ts @@ -7,8 +7,9 @@ export interface PackageJsonInput { name: string; version?: string; description?: string; - cliversion: string; - cliname: string; + cliVersion: string; + cliName: string; + cliBinName: string; isDev?: boolean; } /** diff --git a/lib/template.d.ts b/lib/template.d.ts index 60f9be2..80f83cf 100644 --- a/lib/template.d.ts +++ b/lib/template.d.ts @@ -1,5 +1,5 @@ import { PackageJsonInput } from './interface'; -export declare function packageJsonContent({ name, version, description, cliversion, cliname, isDev, }: PackageJsonInput): string; +export declare function packageJsonContent({ name, version, description, cliVersion, cliName, cliBinName, isDev, }: PackageJsonInput): string; export declare function tsConfigJsonContent(): string; export declare function tsConfigBuildJsonContent(): string; export declare function tsConfigPathsJsonContent(): string; diff --git a/lib/template.js b/lib/template.js index 6ec34be..058165f 100644 --- a/lib/template.js +++ b/lib/template.js @@ -1,39 +1,40 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.oakConfigContentWithWeb = exports.appJsonContentWithWeb = exports.oakConfigContentWithWeChatMp = exports.appJsonContentWithWeChatMp = exports.projectConfigContentWithWeChatMp = exports.tsConfigWebJsonContent = exports.tsConfigMpJsonContent = exports.tsConfigPathsJsonContent = exports.tsConfigBuildJsonContent = exports.tsConfigJsonContent = exports.packageJsonContent = void 0; -function packageJsonContent({ name, version, description, cliversion, cliname, isDev, }) { - let oakPackageStr; +function packageJsonContent({ name, version, description, cliVersion, cliName, cliBinName, isDev, }) { + let oakDependencyStr; + let oakDevDependencyStr; if (isDev) { - oakPackageStr = `"${cliname}": "file:../${cliname}", - "oak-common-aspect": "file:../oak-common-aspect", + oakDependencyStr = `"oak-common-aspect": "file:../oak-common-aspect", "oak-domain": "file:../oak-domain", "oak-frontend-base": "file:../oak-frontend-base", "oak-external-sdk": "file:../oak-external-sdk", "oak-general-business": "file:../oak-general-business", "oak-memory-tree-store": "file:../oak-memory-tree-store",`; + oakDevDependencyStr = `"${cliName}": "file:../oak-cli",`; } else { - oakPackageStr = `"${cliname}": "^${cliversion}", - "oak-common-aspect": "^1.0.0", + oakDependencyStr = `"oak-common-aspect": "^1.0.0", "oak-domain": "^1.0.0", "oak-frontend-base": "^1.0.0", "oak-general-business": "^1.0.0", "oak-external-sdk": "^1.0.0", "oak-memory-tree-store": "^1.0.0",`; + oakDevDependencyStr = `"${cliName}": "^${cliVersion}",`; } return `{ "name": "${name}", "version": "${version}", "description": "${description}", "scripts": { - "make:domain": "${cliname} make", - "start:mp": "${cliname} start --target mp --mode development", - "build:mp": "${cliname} build --target mp --mode production", - "build-analyze:mp": "${cliname} build --target mp --mode production --analyze", - "start:web": "${cliname} start --target web --mode development", - "build:web": "${cliname} build --target web --mode production", - "build-analyze:web": "${cliname} build --target web --mode production --analyze", - "build": "tsc -p tsconfig.build.json", + "make:domain": "${cliBinName} make", + "start:mp": "${cliBinName} start --target mp --mode development", + "build:mp": "${cliBinName} build --target mp --mode production", + "build-analyze:mp": "${cliBinName} build --target mp --mode production --analyze", + "start:web": "${cliBinName} start --target web --mode development", + "build:web": "${cliBinName} build --target web --mode production", + "build-analyze:web": "${cliBinName} build --target web --mode production --analyze", + "build": "tsc", "server:init": "cross-env NODE_ENV=development; cross-env OAK_PLATFORM=server ts-node scripts/initServer.ts", "server:start": "cross-env NODE_ENV=development; cross-env OAK_PLATFORM=server ts-node scripts/startServer.ts", "postinstall": "npm run make:domain" @@ -54,7 +55,7 @@ function packageJsonContent({ name, version, description, cliversion, cliname, i "i18next-resource-store-loader": "^0.1.2", "lodash": "^4.17.21", "nprogress": "^0.2.0", - ${oakPackageStr} + ${oakDependencyStr} "react": "^18.2.0", "react-dom": "^18.1.0", "react-i18next": "^11.18.0", @@ -92,6 +93,7 @@ function packageJsonContent({ name, version, description, cliversion, cliname, i "@types/shelljs": "^0.8.11", "@types/uuid": "^8.3.0", "@types/wechat-miniprogram": "^3.4.0", + ${oakDevDependencyStr} "assert": "^2.0.0", "babel-jest": "^27.4.2", "babel-loader": "^8.2.3", diff --git a/package.json b/package.json index a33a683..d03af1b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@xuchangzju/oak-cli", - "version": "1.0.5", + "version": "1.0.6", "description": "oak-cli脚手架", "main": "lib/index.js", "scripts": { diff --git a/src/config.ts b/src/config.ts index e7bdcfb..2a4b0a7 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,6 +1,7 @@ export const CLI_VERSION = require('../package.json')['version']; -export const CLI_NAME = Object.keys(require('../package.json')['bin'])[0]; +export const CLI_NAME = require('../package.json')['name']; +export const CLI_BIN_NAME = Object.keys(require('../package.json')['bin'])[0]; export const BASE_DIR = process.cwd() diff --git a/src/create.ts b/src/create.ts index 7daa299..fa7b975 100644 --- a/src/create.ts +++ b/src/create.ts @@ -11,6 +11,7 @@ import { USER_CONFIG_FILE_NAME, CLI_NAME, MINI_VERSION_URL, + CLI_BIN_NAME, } from './config'; import { packageJsonContent, @@ -188,8 +189,9 @@ export async function create(dirName: string, cmd: any) { name, version, description, - cliversion: CLI_VERSION, - cliname: CLI_NAME, + cliVersion: CLI_VERSION, + cliName: CLI_NAME, + cliBinName: CLI_BIN_NAME, isDev, }); diff --git a/src/interface.ts b/src/interface.ts index 0b88d5a..19a5d8d 100644 --- a/src/interface.ts +++ b/src/interface.ts @@ -9,8 +9,9 @@ export interface PackageJsonInput { name: string; version?: string; description?: string; - cliversion: string; - cliname: string; + cliVersion: string; + cliName: string; + cliBinName: string; isDev?: boolean; } diff --git a/src/template.ts b/src/template.ts index 0b683d2..3fac250 100644 --- a/src/template.ts +++ b/src/template.ts @@ -3,28 +3,30 @@ export function packageJsonContent({ name, version, description, - cliversion, - cliname, + cliVersion, + cliName, + cliBinName, isDev, }: PackageJsonInput) { - let oakPackageStr; + let oakDependencyStr; + let oakDevDependencyStr; if (isDev) { - oakPackageStr = `"${cliname}": "file:../${cliname}", - "oak-common-aspect": "file:../oak-common-aspect", + oakDependencyStr = `"oak-common-aspect": "file:../oak-common-aspect", "oak-domain": "file:../oak-domain", "oak-frontend-base": "file:../oak-frontend-base", "oak-external-sdk": "file:../oak-external-sdk", "oak-general-business": "file:../oak-general-business", "oak-memory-tree-store": "file:../oak-memory-tree-store",`; + oakDevDependencyStr = `"${cliName}": "file:../oak-cli",` } else { - oakPackageStr = `"${cliname}": "^${cliversion}", - "oak-common-aspect": "^1.0.0", + oakDependencyStr = `"oak-common-aspect": "^1.0.0", "oak-domain": "^1.0.0", "oak-frontend-base": "^1.0.0", "oak-general-business": "^1.0.0", "oak-external-sdk": "^1.0.0", "oak-memory-tree-store": "^1.0.0",`; + oakDevDependencyStr = `"${cliName}": "^${cliVersion}",` } return `{ @@ -32,14 +34,14 @@ export function packageJsonContent({ "version": "${version}", "description": "${description}", "scripts": { - "make:domain": "${cliname} make", - "start:mp": "${cliname} start --target mp --mode development", - "build:mp": "${cliname} build --target mp --mode production", - "build-analyze:mp": "${cliname} build --target mp --mode production --analyze", - "start:web": "${cliname} start --target web --mode development", - "build:web": "${cliname} build --target web --mode production", - "build-analyze:web": "${cliname} build --target web --mode production --analyze", - "build": "tsc -p tsconfig.build.json", + "make:domain": "${cliBinName} make", + "start:mp": "${cliBinName} start --target mp --mode development", + "build:mp": "${cliBinName} build --target mp --mode production", + "build-analyze:mp": "${cliBinName} build --target mp --mode production --analyze", + "start:web": "${cliBinName} start --target web --mode development", + "build:web": "${cliBinName} build --target web --mode production", + "build-analyze:web": "${cliBinName} build --target web --mode production --analyze", + "build": "tsc", "server:init": "cross-env NODE_ENV=development; cross-env OAK_PLATFORM=server ts-node scripts/initServer.ts", "server:start": "cross-env NODE_ENV=development; cross-env OAK_PLATFORM=server ts-node scripts/startServer.ts", "postinstall": "npm run make:domain" @@ -60,7 +62,7 @@ export function packageJsonContent({ "i18next-resource-store-loader": "^0.1.2", "lodash": "^4.17.21", "nprogress": "^0.2.0", - ${oakPackageStr} + ${oakDependencyStr} "react": "^18.2.0", "react-dom": "^18.1.0", "react-i18next": "^11.18.0", @@ -98,6 +100,7 @@ export function packageJsonContent({ "@types/shelljs": "^0.8.11", "@types/uuid": "^8.3.0", "@types/wechat-miniprogram": "^3.4.0", + ${oakDevDependencyStr} "assert": "^2.0.0", "babel-jest": "^27.4.2", "babel-loader": "^8.2.3",