小程序appjson 模版生成

This commit is contained in:
Wang Kejun 2022-04-22 14:58:05 +08:00
parent 430dace767
commit eafd734e1a
6 changed files with 64 additions and 22 deletions

View File

@ -81,6 +81,8 @@ async function create(dirName, env) {
});
// 获取tsconfig.json内容
const tsconfigJson = (0, template_1.tsConfigJsonContent)();
// 获取小程序项目app.json内容
const appJsonWithWeChatMp = (0, template_1.appJsonContentWithWeChatMp)(isDev);
// 获取小程序项目project.config.json内容
const projectConfigWithWeChatMp = (0, template_1.projectConfigContentWithWeChatMp)(config_1.USER_CONFIG_FILE_NAME, 'wechatMp', miniVersion);
// 获取小程序项目oak.config.json内容
@ -95,6 +97,7 @@ async function create(dirName, env) {
const webRootPath = `${rootPath}/web`;
// 小程序项目根路径
const weChatMpRootPath = `${rootPath}/wechatMp`;
const appJsonPathWithWeChatMp = `${weChatMpRootPath}/src/app.json`;
// 小程序项目project.config.json路径
const projectConfigPathWithWeChatMp = `${weChatMpRootPath}/src/project.config.json`;
// 小程序项目project.config.json路径
@ -114,6 +117,8 @@ async function create(dirName, env) {
(0, file_handle_1.copyFolder)(currentPath, rootPath);
// 创建小程序项目project.config.json
(0, file_handle_1.checkFileExistsAndCreate)(projectConfigPathWithWeChatMp, projectConfigWithWeChatMp, enum_1.checkFileExistsAndCreateType.FILE);
// 创建小程序项目app.json
(0, file_handle_1.checkFileExistsAndCreate)(appJsonPathWithWeChatMp, appJsonWithWeChatMp, enum_1.checkFileExistsAndCreateType.FILE);
// 创建小程序项目oak.config.json
(0, file_handle_1.checkFileExistsAndCreate)(oakConfigPathWithWeChatMp, oakConfigWithWeChatMp, enum_1.checkFileExistsAndCreateType.FILE);
if (!shelljs_1.default.which('npm')) {
@ -124,9 +129,6 @@ async function create(dirName, env) {
(0, tip_style_1.Success)(`${(0, tip_style_1.success)(`Dependencies are now being installed`)}`);
shelljs_1.default.cd(dirName).exec('npm install');
// checkFileExistsAndCreate(weChatMpRootPath + '/src/styles');
// //const data = readFile(
// // `${rootPath}/node_modules/oak-frontend-boilerplate/src/platforms/wechatMp/styles/base.less`
// //);
// const data = readFile(
// `${rootPath}/node_modules/oak-general-business/src/platforms/wechatMp/styles/base.less`
// );

1
lib/template.d.ts vendored
View File

@ -2,4 +2,5 @@ import { PackageJsonInput } from './interface';
export declare function packageJsonContent({ name, version, description, cliversion, cliname, isDev, }: PackageJsonInput): string;
export declare function tsConfigJsonContent(): string;
export declare function projectConfigContentWithWeChatMp(oakConfigName: string, projectname: string, miniVersion: string): string;
export declare function appJsonContentWithWeChatMp(isDev: boolean): string;
export declare function oakConfigContentWithWeChatMp(): string;

View File

@ -1,6 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.oakConfigContentWithWeChatMp = exports.projectConfigContentWithWeChatMp = exports.tsConfigJsonContent = exports.packageJsonContent = void 0;
exports.oakConfigContentWithWeChatMp = exports.appJsonContentWithWeChatMp = exports.projectConfigContentWithWeChatMp = exports.tsConfigJsonContent = exports.packageJsonContent = void 0;
function packageJsonContent({ name, version, description, cliversion, cliname, isDev, }) {
let oakPackageStr;
if (isDev) {
@ -193,6 +193,29 @@ function projectConfigContentWithWeChatMp(oakConfigName, projectname, miniVersio
}`;
}
exports.projectConfigContentWithWeChatMp = projectConfigContentWithWeChatMp;
function appJsonContentWithWeChatMp(isDev) {
const pages = [];
if (isDev) {
pages.push('oak#pages/address/list/index');
pages.push('oak#pages/address/upsert/index');
pages.push('oak#pages/pickers/area/index');
}
else {
pages.push('pages/index/index');
}
return `{
"pages":${JSON.stringify(pages, null, 4)},
"window":{
"backgroundTextStyle":"light",
"navigationBarBackgroundColor": "#fff",
"navigationBarTitleText": "Weixin",
"navigationBarTextStyle":"black"
},
"style": "v2",
"sitemapLocation": "sitemap.json"
}`;
}
exports.appJsonContentWithWeChatMp = appJsonContentWithWeChatMp;
function oakConfigContentWithWeChatMp() {
return `{
"theme": {

View File

@ -15,6 +15,7 @@ import {
import {
packageJsonContent,
tsConfigJsonContent,
appJsonContentWithWeChatMp,
projectConfigContentWithWeChatMp,
oakConfigContentWithWeChatMp,
} from './template';
@ -118,6 +119,8 @@ export default async function create(dirName: string, env: string) {
// 获取tsconfig.json内容
const tsconfigJson = tsConfigJsonContent();
// 获取小程序项目app.json内容
const appJsonWithWeChatMp = appJsonContentWithWeChatMp(isDev);
// 获取小程序项目project.config.json内容
const projectConfigWithWeChatMp = projectConfigContentWithWeChatMp(
USER_CONFIG_FILE_NAME,
@ -137,6 +140,8 @@ export default async function create(dirName: string, env: string) {
// 小程序项目根路径
const weChatMpRootPath = `${rootPath}/wechatMp`;
const appJsonPathWithWeChatMp = `${weChatMpRootPath}/src/app.json`;
// 小程序项目project.config.json路径
const projectConfigPathWithWeChatMp = `${weChatMpRootPath}/src/project.config.json`;
// 小程序项目project.config.json路径
@ -168,6 +173,12 @@ export default async function create(dirName: string, env: string) {
projectConfigWithWeChatMp,
checkFileExistsAndCreateType.FILE
);
// 创建小程序项目app.json
checkFileExistsAndCreate(
appJsonPathWithWeChatMp,
appJsonWithWeChatMp,
checkFileExistsAndCreateType.FILE
);
// 创建小程序项目oak.config.json
checkFileExistsAndCreate(
oakConfigPathWithWeChatMp,
@ -183,9 +194,6 @@ export default async function create(dirName: string, env: string) {
shell.cd(dirName).exec('npm install');
// checkFileExistsAndCreate(weChatMpRootPath + '/src/styles');
// //const data = readFile(
// // `${rootPath}/node_modules/oak-frontend-boilerplate/src/platforms/wechatMp/styles/base.less`
// //);
// const data = readFile(
// `${rootPath}/node_modules/oak-general-business/src/platforms/wechatMp/styles/base.less`
// );

View File

@ -204,6 +204,29 @@ export function projectConfigContentWithWeChatMp(
}`;
}
export function appJsonContentWithWeChatMp(isDev: boolean) {
const pages = [];
if (isDev) {
pages.push('oak#pages/address/list/index');
pages.push('oak#pages/address/upsert/index');
pages.push('oak#pages/pickers/area/index');
}
else {
pages.push('pages/index/index');
}
return `{
"pages":${JSON.stringify(pages, null, 4)},
"window":{
"backgroundTextStyle":"light",
"navigationBarBackgroundColor": "#fff",
"navigationBarTitleText": "Weixin",
"navigationBarTextStyle":"black"
},
"style": "v2",
"sitemapLocation": "sitemap.json"
}`;
}
export function oakConfigContentWithWeChatMp() {
return `{
"theme": {

View File

@ -1,15 +0,0 @@
{
"pages":[
"pages/index/index",
"oak#pages/address/list/index",
"oak#pages/address/upsert/index"
],
"window":{
"backgroundTextStyle":"light",
"navigationBarBackgroundColor": "#fff",
"navigationBarTitleText": "Weixin",
"navigationBarTextStyle":"black"
},
"style": "v2",
"sitemapLocation": "sitemap.json"
}