build
This commit is contained in:
commit
cd62fc9690
|
|
@ -59,6 +59,7 @@ function getClientEnvironment() {
|
|||
// process.env.OAK_PLATFORM: wechatMp | web | node
|
||||
OAK_PLATFORM: 'wechatMp',
|
||||
OAK_DEV_MODE: process.env.OAK_DEV_MODE || 'server',
|
||||
SUB_DIR_NAME: process.env.SUB_DIR_NAME || 'wechatMp',
|
||||
}
|
||||
);
|
||||
// Stringify all values so we can feed into webpack DefinePlugin
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@ const assert = require('assert');
|
|||
|
||||
const REPLACE_HOLDERS = {
|
||||
OAK_PLATFORM: 'native',
|
||||
PROD: process.env.PROD,
|
||||
OAK_DEV_MODE: process.env.OAK_DEV_MODE,
|
||||
SUB_DIR_NAME: process.env.SUB_DIR_NAME || 'native',
|
||||
};
|
||||
|
||||
function replaceEnvExpressionPlugin() {
|
||||
|
|
|
|||
|
|
@ -91,6 +91,7 @@ function getClientEnvironment(publicUrl) {
|
|||
// process.env.OAK_PLATFORM: wechatMp | web | native
|
||||
OAK_PLATFORM: 'web',
|
||||
OAK_DEV_MODE: process.env.OAK_DEV_MODE || 'server',
|
||||
SUB_DIR_NAME: process.env.SUB_DIR_NAME || 'web',
|
||||
}
|
||||
);
|
||||
// Stringify all values so we can feed into webpack DefinePlugin
|
||||
|
|
|
|||
|
|
@ -161,13 +161,6 @@ async function create(dirName, cmd) {
|
|||
const isDev = cmd.dev ? true : false;
|
||||
const isModule = cmd.module ? true : false;
|
||||
const { name, version, title, description, useOgb, moreDeps, example } = await inquirer_1.default.prompt(prompt);
|
||||
// 获取tsconfig.json内容
|
||||
const tsconfigJson = (0, template_1.tsConfigJsonContent)();
|
||||
const tsConfigBuildJson = (0, template_1.tsConfigBuildJsonContent)();
|
||||
const tsConfigBuildPathsJson = (0, template_1.tsConfigBuildPathsJsonContent)();
|
||||
const tsConfigPathsJson = (0, template_1.tsConfigPathsJsonContent)();
|
||||
const tsConfigMpJson = (0, template_1.tsConfigMpJsonContent)();
|
||||
const tsConfigWebJson = (0, template_1.tsConfigWebJsonContent)();
|
||||
// 项目根路径
|
||||
const rootPath = process.cwd() + '/' + dirName;
|
||||
// package.json路径
|
||||
|
|
@ -196,18 +189,6 @@ async function create(dirName, cmd) {
|
|||
try {
|
||||
// 创建根目录
|
||||
(0, file_handle_1.checkFileExistsAndCreate)(rootPath);
|
||||
// 创建tsconfig.json
|
||||
(0, file_handle_1.checkFileExistsAndCreate)(tsconfigJsonPath, tsconfigJson, enum_1.checkFileExistsAndCreateType.FILE);
|
||||
// 创建tsconfig.build.json
|
||||
(0, file_handle_1.checkFileExistsAndCreate)(tsConfigBuildJsonPath, tsConfigBuildJson, enum_1.checkFileExistsAndCreateType.FILE);
|
||||
// 创建tsconfig.build.paths.json
|
||||
(0, file_handle_1.checkFileExistsAndCreate)(tsConfigBuildPathsJsonPath, tsConfigBuildPathsJson, enum_1.checkFileExistsAndCreateType.FILE);
|
||||
// 创建tsconfig.paths.json
|
||||
(0, file_handle_1.checkFileExistsAndCreate)(tsconfigPathsJsonPath, tsConfigPathsJson, enum_1.checkFileExistsAndCreateType.FILE);
|
||||
// 创建tsconfig.mp.json
|
||||
(0, file_handle_1.checkFileExistsAndCreate)(tsConfigMpJsonPath, tsConfigMpJson, enum_1.checkFileExistsAndCreateType.FILE);
|
||||
// 创建tsconfig.web.json
|
||||
(0, file_handle_1.checkFileExistsAndCreate)(tsConfigWebJsonPath, tsConfigWebJson, enum_1.checkFileExistsAndCreateType.FILE);
|
||||
// 复制项目文件
|
||||
if (isModule) {
|
||||
// 模块化的项目,只拷贝src和typings目录
|
||||
|
|
@ -227,7 +208,6 @@ async function create(dirName, cmd) {
|
|||
Success(`${success(`Dependencies are now being installed`)}`);
|
||||
shell.cd(dirName).exec('npm install'); */
|
||||
}
|
||||
(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 deps = [];
|
||||
if (useOgb) {
|
||||
deps.push('oak-general-business');
|
||||
|
|
@ -235,6 +215,28 @@ async function create(dirName, cmd) {
|
|||
if (moreDeps) {
|
||||
deps.push(...(moreDeps.split(',').map(ele => ele.trim()).filter(ele => !!ele)));
|
||||
}
|
||||
// 获取tsconfig.json内容
|
||||
const tsconfigJson = (0, template_1.tsConfigJsonContent)();
|
||||
const tsConfigBuildJson = (0, template_1.tsConfigBuildJsonContent)();
|
||||
const tsConfigBuildPathsJson = (0, template_1.tsConfigPathsJsonContent)(deps);
|
||||
const tsConfigPathsJson = (0, template_1.tsConfigPathsJsonContent)(deps);
|
||||
const tsConfigMpJson = (0, template_1.tsConfigMpJsonContent)();
|
||||
const tsConfigWebJson = (0, template_1.tsConfigWebJsonContent)();
|
||||
// 创建tsconfig.json
|
||||
(0, file_handle_1.checkFileExistsAndCreate)(tsconfigJsonPath, tsconfigJson, enum_1.checkFileExistsAndCreateType.FILE);
|
||||
// 创建tsconfig.build.json
|
||||
(0, file_handle_1.checkFileExistsAndCreate)(tsConfigBuildJsonPath, tsConfigBuildJson, enum_1.checkFileExistsAndCreateType.FILE);
|
||||
// 创建tsconfig.build.paths.json
|
||||
(0, file_handle_1.checkFileExistsAndCreate)(tsConfigBuildPathsJsonPath, tsConfigBuildPathsJson, enum_1.checkFileExistsAndCreateType.FILE);
|
||||
// 创建tsconfig.paths.json
|
||||
(0, file_handle_1.checkFileExistsAndCreate)(tsconfigPathsJsonPath, tsConfigPathsJson, enum_1.checkFileExistsAndCreateType.FILE);
|
||||
// 创建tsconfig.mp.json
|
||||
(0, file_handle_1.checkFileExistsAndCreate)(tsConfigMpJsonPath, tsConfigMpJson, enum_1.checkFileExistsAndCreateType.FILE);
|
||||
// 创建tsconfig.web.json
|
||||
(0, file_handle_1.checkFileExistsAndCreate)(tsConfigWebJsonPath, tsConfigWebJson, enum_1.checkFileExistsAndCreateType.FILE);
|
||||
// 更新configuration/compiler.js
|
||||
(0, template_1.updateCompilerJsContent)(rootPath, deps);
|
||||
(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)}`)}`);
|
||||
shelljs_1.default.cd(dirName);
|
||||
if (deps.length > 0) {
|
||||
addDependencies(deps);
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ function concat(...paths) {
|
|||
}
|
||||
async function startup(path, connector, omitWatchers, omitTimers, routine) {
|
||||
const serverConfiguration = require((0, path_1.join)(path, 'lib', 'configuration', 'server')).default;
|
||||
// 拿到package.json,用作项目的唯一标识,否则无法区分不同项目的Redis+socketIO连接
|
||||
const packageJson = require((0, path_1.join)(path, 'package.json'));
|
||||
const corsHeaders = [
|
||||
'Content-Type',
|
||||
|
|
|
|||
|
|
@ -2,11 +2,11 @@ import { PackageJsonInput } from './interface';
|
|||
export declare function packageJsonContent({ name, version, description, cliName, cliBinName, isDev, isModule, dependencies }: PackageJsonInput): string;
|
||||
export declare function tsConfigJsonContent(): string;
|
||||
export declare function tsConfigBuildJsonContent(): string;
|
||||
export declare function tsConfigBuildPathsJsonContent(): string;
|
||||
export declare function tsConfigPathsJsonContent(): string;
|
||||
export declare function tsConfigPathsJsonContent(deps: string[]): string;
|
||||
export declare function tsConfigMpJsonContent(): string;
|
||||
export declare function tsConfigWebJsonContent(): string;
|
||||
export declare function projectConfigContentWithWeChatMp(oakConfigName: string, projectname: string, miniVersion: string): string;
|
||||
export declare function appJsonContentWithWeChatMp(isDev: boolean): string;
|
||||
export declare function oakConfigContentWithWeChatMp(): string;
|
||||
export declare function oakConfigContentWithWeb(): string;
|
||||
export declare function updateCompilerJsContent(directory: string, deps: string[]): void;
|
||||
|
|
|
|||
141
lib/template.js
141
lib/template.js
|
|
@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|||
exports.packageJsonContent = packageJsonContent;
|
||||
exports.tsConfigJsonContent = tsConfigJsonContent;
|
||||
exports.tsConfigBuildJsonContent = tsConfigBuildJsonContent;
|
||||
exports.tsConfigBuildPathsJsonContent = tsConfigBuildPathsJsonContent;
|
||||
exports.tsConfigPathsJsonContent = tsConfigPathsJsonContent;
|
||||
exports.tsConfigMpJsonContent = tsConfigMpJsonContent;
|
||||
exports.tsConfigWebJsonContent = tsConfigWebJsonContent;
|
||||
|
|
@ -11,9 +10,15 @@ exports.projectConfigContentWithWeChatMp = projectConfigContentWithWeChatMp;
|
|||
exports.appJsonContentWithWeChatMp = appJsonContentWithWeChatMp;
|
||||
exports.oakConfigContentWithWeChatMp = oakConfigContentWithWeChatMp;
|
||||
exports.oakConfigContentWithWeb = oakConfigContentWithWeb;
|
||||
exports.updateCompilerJsContent = updateCompilerJsContent;
|
||||
const tslib_1 = require("tslib");
|
||||
const child_process_1 = require("child_process");
|
||||
const fs_1 = require("fs");
|
||||
const path_1 = require("path");
|
||||
const core_1 = require("@babel/core");
|
||||
const t = tslib_1.__importStar(require("@babel/types"));
|
||||
const generator_1 = tslib_1.__importDefault(require("@babel/generator"));
|
||||
const assert_1 = tslib_1.__importDefault(require("assert"));
|
||||
/**
|
||||
* 利用npm info获得相应库的最新版本
|
||||
* @param name
|
||||
|
|
@ -401,43 +406,33 @@ function tsConfigBuildJsonContent() {
|
|||
]
|
||||
}`;
|
||||
}
|
||||
function tsConfigBuildPathsJsonContent() {
|
||||
return `{
|
||||
"compilerOptions": {
|
||||
"baseUrl": "./",
|
||||
"paths": {
|
||||
"@project/*": [
|
||||
"src/*"
|
||||
],
|
||||
"@oak-app-domain": [
|
||||
"src/oak-app-domain/index"
|
||||
],
|
||||
"@oak-app-domain/*": [
|
||||
"src/oak-app-domain/*"
|
||||
],
|
||||
},
|
||||
"typeRoots": ["./typings"]
|
||||
}
|
||||
}`;
|
||||
}
|
||||
function tsConfigPathsJsonContent() {
|
||||
return `{
|
||||
"compilerOptions": {
|
||||
"baseUrl": "./",
|
||||
"paths": {
|
||||
"@project/*": [
|
||||
"src/*"
|
||||
],
|
||||
"@oak-app-domain": [
|
||||
"src/oak-app-domain/index"
|
||||
],
|
||||
"@oak-app-domain/*": [
|
||||
"src/oak-app-domain/*"
|
||||
],
|
||||
},
|
||||
"typeRoots": ["./typings"]
|
||||
}
|
||||
}`;
|
||||
function tsConfigPathsJsonContent(deps) {
|
||||
const paths = {
|
||||
"@project/*": [
|
||||
"src/*"
|
||||
],
|
||||
"@oak-app-domain": [
|
||||
"src/oak-app-domain/index"
|
||||
],
|
||||
"@oak-app-domain/*": [
|
||||
"src/oak-app-domain/*"
|
||||
],
|
||||
"@oak-frontend-base/*": [
|
||||
"node_modules/oak-frontend-base/lib/*"
|
||||
],
|
||||
};
|
||||
deps.forEach((ele) => {
|
||||
Object.assign(paths, {
|
||||
[`@${ele}/*`]: [`node_modules/${ele}/lib/*`],
|
||||
});
|
||||
});
|
||||
return JSON.stringify({
|
||||
compilerOptions: {
|
||||
baseUrl: "./",
|
||||
paths,
|
||||
typeRoots: ["./typings"]
|
||||
}
|
||||
}, null, '\t');
|
||||
}
|
||||
function tsConfigMpJsonContent() {
|
||||
return `{
|
||||
|
|
@ -635,13 +630,71 @@ function appJsonContentWithWeChatMp(isDev) {
|
|||
}
|
||||
function oakConfigContentWithWeChatMp() {
|
||||
return `{
|
||||
"theme": {
|
||||
}
|
||||
}`;
|
||||
"theme": {
|
||||
}
|
||||
}`;
|
||||
}
|
||||
function oakConfigContentWithWeb() {
|
||||
return `{
|
||||
"theme": {
|
||||
}
|
||||
}`;
|
||||
"theme": {
|
||||
}
|
||||
}`;
|
||||
}
|
||||
function updateCompilerJsContent(directory, deps) {
|
||||
const compilerJsPath = (0, path_1.join)(directory, 'configuration', 'compiler.js');
|
||||
(0, assert_1.default)((0, fs_1.existsSync)(compilerJsPath));
|
||||
if (deps.length > 0) {
|
||||
const { ast } = (0, core_1.transformFileSync)(compilerJsPath, { ast: true });
|
||||
const { program } = ast;
|
||||
const { body } = program;
|
||||
const moduleExportStmt = body[body.length - 1];
|
||||
/**
|
||||
* 导出语句:
|
||||
module.exports = CreateCompilerConfig({
|
||||
webpack: {
|
||||
extraOakModules: [],
|
||||
resolve: {
|
||||
alias: {
|
||||
'@oak-frontend-base': oakFrontendBasePath,
|
||||
'@project': path.resolve('src'),
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
*/
|
||||
(0, assert_1.default)(t.isExpressionStatement(moduleExportStmt));
|
||||
const { expression } = moduleExportStmt;
|
||||
(0, assert_1.default)(t.isAssignmentExpression(expression));
|
||||
const { left, right } = expression;
|
||||
(0, assert_1.default)(t.isMemberExpression(left));
|
||||
const { property, object } = left;
|
||||
(0, assert_1.default)(t.isIdentifier(object) && object.name === 'module');
|
||||
(0, assert_1.default)(t.isIdentifier(property) && property.name === 'exports');
|
||||
(0, assert_1.default)(t.isCallExpression(right));
|
||||
const [webPackExpr] = right.arguments;
|
||||
(0, assert_1.default)(t.isObjectExpression(webPackExpr));
|
||||
const [webPackProp] = webPackExpr.properties;
|
||||
(0, assert_1.default)(t.isObjectProperty(webPackProp));
|
||||
const { key, value } = webPackProp;
|
||||
(0, assert_1.default)(t.isIdentifier(key) && key.name === 'webpack');
|
||||
const [modulesProp, resolveProp] = value.properties;
|
||||
(0, assert_1.default)(t.isObjectProperty(modulesProp));
|
||||
const { value: value2 } = modulesProp;
|
||||
(0, assert_1.default)(t.isArrayExpression(value2));
|
||||
value2.elements.push(...deps.map((ele) => t.regExpLiteral(ele)));
|
||||
(0, assert_1.default)(t.isObjectProperty(resolveProp));
|
||||
const { value: value3 } = resolveProp;
|
||||
(0, assert_1.default)(t.isObjectExpression(value3));
|
||||
const [aliasProp] = value3.properties;
|
||||
(0, assert_1.default)(t.isObjectProperty(aliasProp));
|
||||
const { value: value4 } = aliasProp;
|
||||
(0, assert_1.default)(t.isObjectExpression(value4));
|
||||
const { properties: aliasProperties } = value4;
|
||||
(0, assert_1.default)(aliasProperties.length === 2); // @project和@oak-frontend-base
|
||||
aliasProperties.push(...deps.map((ele) => t.objectProperty(t.stringLiteral(`@${ele}`), t.callExpression(t.memberExpression(t.identifier('path'), t.identifier('resolve')), [
|
||||
t.stringLiteral(`node_modules/${ele}/es`)
|
||||
]))));
|
||||
const { code } = (0, generator_1.default)(ast);
|
||||
(0, fs_1.writeFileSync)(compilerJsPath, code);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -129,7 +129,7 @@
|
|||
"sass-loader": "^12.3.0",
|
||||
"semver": "^7.3.5",
|
||||
"shelljs": "^0.8.4",
|
||||
"socket.io": "^4.7.2",
|
||||
"socket.io": "^4.8.1",
|
||||
"source-map-loader": "^3.0.0",
|
||||
"stream-browserify": "^3.0.0",
|
||||
"style-loader": "^3.3.1",
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ import {
|
|||
packageJsonContent,
|
||||
tsConfigJsonContent,
|
||||
tsConfigBuildJsonContent,
|
||||
tsConfigBuildPathsJsonContent,
|
||||
tsConfigPathsJsonContent,
|
||||
tsConfigMpJsonContent,
|
||||
tsConfigWebJsonContent,
|
||||
|
|
@ -29,6 +28,7 @@ import {
|
|||
projectConfigContentWithWeChatMp,
|
||||
oakConfigContentWithWeChatMp,
|
||||
oakConfigContentWithWeb,
|
||||
updateCompilerJsContent,
|
||||
} from './template';
|
||||
import { PromptInput } from './interface';
|
||||
import { join } from 'path';
|
||||
|
|
@ -66,7 +66,7 @@ const prompt = [
|
|||
type: 'confirm',
|
||||
message: 'add oak-general-business into dependency?',
|
||||
default: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'moreDeps',
|
||||
type: 'input',
|
||||
|
|
@ -78,7 +78,7 @@ const prompt = [
|
|||
type: 'confirm',
|
||||
message: 'load an initial example about personal blog? It will load correspond Entities/Pages/Components/Checkers and etc.',
|
||||
default: true,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
@ -247,13 +247,6 @@ export async function create(dirName: string, cmd: any) {
|
|||
prompt
|
||||
);
|
||||
|
||||
// 获取tsconfig.json内容
|
||||
const tsconfigJson = tsConfigJsonContent();
|
||||
const tsConfigBuildJson = tsConfigBuildJsonContent();
|
||||
const tsConfigBuildPathsJson = tsConfigBuildPathsJsonContent();
|
||||
const tsConfigPathsJson = tsConfigPathsJsonContent();
|
||||
const tsConfigMpJson = tsConfigMpJsonContent();
|
||||
const tsConfigWebJson = tsConfigWebJsonContent();
|
||||
|
||||
// 项目根路径
|
||||
const rootPath = process.cwd() + '/' + dirName;
|
||||
|
|
@ -284,6 +277,49 @@ export async function create(dirName: string, cmd: any) {
|
|||
try {
|
||||
// 创建根目录
|
||||
checkFileExistsAndCreate(rootPath);
|
||||
// 复制项目文件
|
||||
if (isModule) {
|
||||
// 模块化的项目,只拷贝src和typings目录
|
||||
copyFolder(join(emptyTemplatePath, 'src'), join(rootPath, 'src'));
|
||||
copyFolder(join(emptyTemplatePath, 'typings'), join(rootPath, 'typings'));
|
||||
}
|
||||
else {
|
||||
copyFolder(emptyTemplatePath, rootPath);
|
||||
|
||||
await createWechatMpBoilplate(weChatMpRootPath, isDev);
|
||||
await createWebBoilplate(webRootPath, isDev);
|
||||
/* if (!shell.which('npm')) {
|
||||
Warn(warn('Sorry, this script requires npm! Please install npm!'));
|
||||
shell.exit(1);
|
||||
}
|
||||
|
||||
Success(`${success(`Waiting...`)}`);
|
||||
Success(`${success(`Dependencies are now being installed`)}`);
|
||||
shell.cd(dirName).exec('npm install'); */
|
||||
}
|
||||
|
||||
const deps = [] as string[];
|
||||
if (useOgb) {
|
||||
deps.push('oak-general-business');
|
||||
}
|
||||
if (moreDeps) {
|
||||
deps.push(
|
||||
...((<string>moreDeps).split(',').map(
|
||||
ele => ele.trim()
|
||||
).filter(
|
||||
ele => !!ele
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
// 获取tsconfig.json内容
|
||||
const tsconfigJson = tsConfigJsonContent();
|
||||
const tsConfigBuildJson = tsConfigBuildJsonContent();
|
||||
const tsConfigBuildPathsJson = tsConfigPathsJsonContent(deps);
|
||||
const tsConfigPathsJson = tsConfigPathsJsonContent(deps);
|
||||
const tsConfigMpJson = tsConfigMpJsonContent();
|
||||
const tsConfigWebJson = tsConfigWebJsonContent();
|
||||
|
||||
// 创建tsconfig.json
|
||||
checkFileExistsAndCreate(
|
||||
tsconfigJsonPath,
|
||||
|
|
@ -320,27 +356,8 @@ export async function create(dirName: string, cmd: any) {
|
|||
tsConfigWebJson,
|
||||
checkFileExistsAndCreateType.FILE
|
||||
);
|
||||
// 复制项目文件
|
||||
if (isModule) {
|
||||
// 模块化的项目,只拷贝src和typings目录
|
||||
copyFolder(join(emptyTemplatePath, 'src'), join(rootPath, 'src'));
|
||||
copyFolder(join(emptyTemplatePath, 'typings'), join(rootPath, 'typings'));
|
||||
}
|
||||
else {
|
||||
copyFolder(emptyTemplatePath, rootPath);
|
||||
|
||||
await createWechatMpBoilplate(weChatMpRootPath, isDev);
|
||||
await createWebBoilplate(webRootPath, isDev);
|
||||
/* if (!shell.which('npm')) {
|
||||
Warn(warn('Sorry, this script requires npm! Please install npm!'));
|
||||
shell.exit(1);
|
||||
}
|
||||
|
||||
Success(`${success(`Waiting...`)}`);
|
||||
Success(`${success(`Dependencies are now being installed`)}`);
|
||||
shell.cd(dirName).exec('npm install'); */
|
||||
}
|
||||
|
||||
// 更新configuration/compiler.js
|
||||
updateCompilerJsContent(rootPath, deps);
|
||||
Success(
|
||||
`${success(
|
||||
`Successfully created project ${primary(
|
||||
|
|
@ -349,20 +366,6 @@ export async function create(dirName: string, cmd: any) {
|
|||
)}`
|
||||
);
|
||||
|
||||
const deps = [] as string[];
|
||||
if (useOgb) {
|
||||
deps.push('oak-general-business');
|
||||
}
|
||||
if (moreDeps) {
|
||||
deps.push(
|
||||
...((<string>moreDeps).split(',').map(
|
||||
ele => ele.trim()
|
||||
).filter(
|
||||
ele => !!ele
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
shell.cd(dirName);
|
||||
if (deps.length > 0) {
|
||||
addDependencies(deps);
|
||||
|
|
|
|||
173
src/template.ts
173
src/template.ts
|
|
@ -1,7 +1,11 @@
|
|||
import { execSync } from 'child_process';
|
||||
import { existsSync } from 'fs';
|
||||
import { existsSync, writeFileSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
import { PackageJsonInput } from './interface';
|
||||
import { transformFileSync } from '@babel/core';
|
||||
import * as t from '@babel/types';
|
||||
import generate from "@babel/generator";
|
||||
import assert from 'assert';
|
||||
|
||||
/**
|
||||
* 利用npm info获得相应库的最新版本
|
||||
|
|
@ -69,7 +73,7 @@ export function packageJsonContent({
|
|||
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 serverStartScript = isDev ? "cross-env NODE_ENV=development cross-env OAK_PLATFORM=server node scripts/startServer.js" : "cross-env OAK_PLATFORM=server node scripts/startServer.js";
|
||||
const serverStartWatchScript = isDev ? "cross-env ENABLE_TRACE=true cross-env NODE_ENV=development cross-env OAK_PLATFORM=server node --stack-size=65500 scripts/watchServer.js" : "cross-env OAK_PLATFORM=server node --stack-size=65500 scripts/watchServer.js";
|
||||
return `{
|
||||
return `{
|
||||
"name": "${name}",
|
||||
"version": "${version}",
|
||||
"description": "${description}",
|
||||
|
|
@ -317,7 +321,7 @@ export function packageJsonContent({
|
|||
}
|
||||
}
|
||||
`;
|
||||
// _moduleAliases用于lib内运行时的模块声明,重载之后require的路径还会保留@project,需要这样的方式来进行路径alias
|
||||
// _moduleAliases用于lib内运行时的模块声明,重载之后require的路径还会保留@project,需要这样的方式来进行路径alias
|
||||
}
|
||||
|
||||
export function tsConfigJsonContent() {
|
||||
|
|
@ -412,45 +416,37 @@ export function tsConfigBuildJsonContent() {
|
|||
}`;
|
||||
}
|
||||
|
||||
export function tsConfigBuildPathsJsonContent() {
|
||||
return `{
|
||||
"compilerOptions": {
|
||||
"baseUrl": "./",
|
||||
"paths": {
|
||||
"@project/*": [
|
||||
"src/*"
|
||||
],
|
||||
"@oak-app-domain": [
|
||||
"src/oak-app-domain/index"
|
||||
],
|
||||
"@oak-app-domain/*": [
|
||||
"src/oak-app-domain/*"
|
||||
],
|
||||
},
|
||||
"typeRoots": ["./typings"]
|
||||
}
|
||||
}`;
|
||||
export function tsConfigPathsJsonContent(deps: string[]) {
|
||||
const paths = {
|
||||
"@project/*": [
|
||||
"src/*"
|
||||
],
|
||||
"@oak-app-domain": [
|
||||
"src/oak-app-domain/index"
|
||||
],
|
||||
"@oak-app-domain/*": [
|
||||
"src/oak-app-domain/*"
|
||||
],
|
||||
"@oak-frontend-base/*": [
|
||||
"node_modules/oak-frontend-base/lib/*"
|
||||
],
|
||||
};
|
||||
deps.forEach(
|
||||
(ele) => {
|
||||
Object.assign(paths, {
|
||||
[`@${ele}/*`]: [`node_modules/${ele}/lib/*`],
|
||||
});
|
||||
}
|
||||
);
|
||||
return JSON.stringify({
|
||||
compilerOptions: {
|
||||
baseUrl: "./",
|
||||
paths,
|
||||
typeRoots: ["./typings"]
|
||||
}
|
||||
}, null, '\t');
|
||||
}
|
||||
|
||||
export function tsConfigPathsJsonContent() {
|
||||
return `{
|
||||
"compilerOptions": {
|
||||
"baseUrl": "./",
|
||||
"paths": {
|
||||
"@project/*": [
|
||||
"src/*"
|
||||
],
|
||||
"@oak-app-domain": [
|
||||
"src/oak-app-domain/index"
|
||||
],
|
||||
"@oak-app-domain/*": [
|
||||
"src/oak-app-domain/*"
|
||||
],
|
||||
},
|
||||
"typeRoots": ["./typings"]
|
||||
}
|
||||
}`;
|
||||
}
|
||||
|
||||
export function tsConfigMpJsonContent() {
|
||||
return `{
|
||||
|
|
@ -657,15 +653,98 @@ export function appJsonContentWithWeChatMp(isDev: boolean) {
|
|||
|
||||
export function oakConfigContentWithWeChatMp() {
|
||||
return `{
|
||||
"theme": {
|
||||
}
|
||||
}`;
|
||||
"theme": {
|
||||
}
|
||||
}`;
|
||||
}
|
||||
|
||||
|
||||
export function oakConfigContentWithWeb() {
|
||||
return `{
|
||||
"theme": {
|
||||
}
|
||||
}`;
|
||||
}
|
||||
"theme": {
|
||||
}
|
||||
}`;
|
||||
}
|
||||
|
||||
|
||||
export function updateCompilerJsContent(directory: string, deps: string[]) {
|
||||
const compilerJsPath = join(directory, 'configuration', 'compiler.js');
|
||||
assert(existsSync(compilerJsPath));
|
||||
|
||||
if (deps.length > 0) {
|
||||
const { ast } = transformFileSync(compilerJsPath, { ast: true })!;
|
||||
const { program } = ast!;
|
||||
const { body } = program!;
|
||||
|
||||
const moduleExportStmt = body[body.length - 1];
|
||||
|
||||
/**
|
||||
* 导出语句:
|
||||
module.exports = CreateCompilerConfig({
|
||||
webpack: {
|
||||
extraOakModules: [],
|
||||
resolve: {
|
||||
alias: {
|
||||
'@oak-frontend-base': oakFrontendBasePath,
|
||||
'@project': path.resolve('src'),
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
*/
|
||||
assert(t.isExpressionStatement(moduleExportStmt));
|
||||
const { expression } = moduleExportStmt;
|
||||
assert(t.isAssignmentExpression(expression));
|
||||
const { left, right } = expression;
|
||||
assert(t.isMemberExpression(left));
|
||||
const { property, object } = left;
|
||||
assert(t.isIdentifier(object) && object.name === 'module');
|
||||
assert(t.isIdentifier(property) && property.name === 'exports');
|
||||
assert(t.isCallExpression(right));
|
||||
const [webPackExpr] = right.arguments;
|
||||
assert(t.isObjectExpression(webPackExpr));
|
||||
const [ webPackProp ] = webPackExpr.properties;
|
||||
assert(t.isObjectProperty(webPackProp));
|
||||
const { key, value } = webPackProp;
|
||||
assert(t.isIdentifier(key) && key.name === 'webpack');
|
||||
const [ modulesProp, resolveProp ] = (<t.ObjectExpression>value).properties;
|
||||
|
||||
assert(t.isObjectProperty(modulesProp));
|
||||
const { value: value2 } = modulesProp;
|
||||
assert(t.isArrayExpression(value2));
|
||||
value2.elements.push(
|
||||
...deps.map(
|
||||
(ele) => t.regExpLiteral(ele)
|
||||
)
|
||||
);
|
||||
|
||||
assert(t.isObjectProperty(resolveProp));
|
||||
const { value: value3 } = resolveProp;
|
||||
assert(t.isObjectExpression(value3));
|
||||
const [ aliasProp ] = value3.properties;
|
||||
assert(t.isObjectProperty(aliasProp));
|
||||
const { value: value4 } = aliasProp;
|
||||
assert(t.isObjectExpression(value4));
|
||||
const { properties: aliasProperties } = value4;
|
||||
assert(aliasProperties.length === 2); // @project和@oak-frontend-base
|
||||
aliasProperties.push(
|
||||
...deps.map(
|
||||
(ele) => t.objectProperty(
|
||||
t.stringLiteral(`@${ele}`),
|
||||
t.callExpression(
|
||||
t.memberExpression(
|
||||
t.identifier('path'),
|
||||
t.identifier('resolve')
|
||||
),
|
||||
[
|
||||
t.stringLiteral(`node_modules/${ele}/es`)
|
||||
]
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
const { code } = generate(ast!);
|
||||
writeFileSync(compilerJsPath, code);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,24 +1,13 @@
|
|||
// import { CompilerConfiguration } from 'oak-domain/lib/types/Configuration';
|
||||
const path = require('path');
|
||||
const { CreateCompilerConfig } = require('@xuchangzju/oak-cli/lib/createConfig')
|
||||
const oakGeneralBusinessPath = path.resolve(
|
||||
'node_modules/oak-general-business/es'
|
||||
);
|
||||
const oakFrontendBasePath = path.resolve(
|
||||
'node_modules/oak-frontend-base/es'
|
||||
);
|
||||
|
||||
const oakPayBusinessPath = path.resolve(
|
||||
'node_modules/oak-pay-business/es'
|
||||
);
|
||||
const { CreateCompilerConfig } = require('@xuchangzju/oak-cli/lib/createConfig');
|
||||
|
||||
module.exports = CreateCompilerConfig({
|
||||
webpack: {
|
||||
extraOakModules: [/oak-pay-business/, /oak-general-business/],
|
||||
extraOakModules: [],
|
||||
resolve: {
|
||||
alias: {
|
||||
'@oak-general-business': oakGeneralBusinessPath,
|
||||
'@oak-frontend-base': oakFrontendBasePath,
|
||||
'@oak-frontend-base': path.resolve('node_modules/oak-frontend-base/es'),
|
||||
'@project': path.resolve('src'),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,12 +32,12 @@ export const handler = async (reason: any, features: AFD) => {
|
|||
);
|
||||
} else if (reason instanceof OakInputIllegalException) {
|
||||
features.message.setMessage({
|
||||
content: reason.message,
|
||||
content: features.locales.t(reason.message, {}),
|
||||
type: 'error',
|
||||
});
|
||||
} else if (reason instanceof OakAttrNotNullException) {
|
||||
features.message.setMessage({
|
||||
content: reason.message,
|
||||
content: features.locales.t(reason.message, {}),
|
||||
type: 'error',
|
||||
});
|
||||
}/* else if (reason instanceof OakUserInfoLoadingException || reason instanceof OakApplicationLoadingException) {
|
||||
|
|
@ -48,7 +48,7 @@ export const handler = async (reason: any, features: AFD) => {
|
|||
} else {
|
||||
console.warn(reason);
|
||||
features.message.setMessage({
|
||||
content: reason.message,
|
||||
content: features.locales.t(reason.message, {}),
|
||||
type: 'error',
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,15 @@ window.addEventListener('unhandledrejection', async (event) => {
|
|||
}
|
||||
});
|
||||
|
||||
window.addEventListener('error', async (event) => {
|
||||
const { error } = event;
|
||||
|
||||
const result = await exceptionHandler(error, features);
|
||||
if (result) {
|
||||
event.preventDefault();
|
||||
}
|
||||
});
|
||||
|
||||
const init = async () => {
|
||||
let error;
|
||||
try {
|
||||
|
|
|
|||
Loading…
Reference in New Issue