oak-cli build 命令改

This commit is contained in:
Wang Kejun 2022-04-25 13:23:50 +08:00
parent fe1ce346ea
commit 4d6c25aeca
11 changed files with 50 additions and 49 deletions

View File

@ -15,7 +15,10 @@ function traverse(doc, callback) {
} }
module.exports = function (content) { module.exports = function (content) {
//console.log(content); const options = this.getOptions() || {}; //获取配置参数
// const callback = this.async();
// console.log(content, options);
const doc = new DOMParser().parseFromString(content, 'text/xml'); const doc = new DOMParser().parseFromString(content, 'text/xml');
traverse(doc, (node) => { traverse(doc, (node) => {
if (node.nodeType === node.ELEMENT_NODE) { if (node.nodeType === node.ELEMENT_NODE) {
@ -28,8 +31,7 @@ module.exports = function (content) {
if (node.hasAttribute('oak:forbidFocus')) { if (node.hasAttribute('oak:forbidFocus')) {
node.removeAttribute('oak:forbidFocus'); node.removeAttribute('oak:forbidFocus');
} } else {
else {
node.setAttribute('focus', `{{!!oakFocused.${oakValue}}}`); node.setAttribute('focus', `{{!!oakFocused.${oakValue}}}`);
} }
} }

View File

@ -95,7 +95,8 @@ module.exports = {
}, },
{ {
test: /\.less$/, test: /\.less$/,
include: /oak-general-business\/wechatMp|oak-general-business\\wechatMp/, include:
/oak-general-business\/wechatMp|oak-general-business\\wechatMp/,
// include: [ // include: [
// path.resolve( // path.resolve(
// process.cwd(), // process.cwd(),
@ -158,17 +159,12 @@ module.exports = {
{ {
test: /\.(xml|wxml)$/, test: /\.(xml|wxml)$/,
include: /oak-general-business\/wechatMp|oak-general-business\\wechatMp/, include: /oak-general-business\/wechatMp|oak-general-business\\wechatMp/,
// include: [
// path.resolve(
// process.cwd(),
// 'node_modules/oak-general-business/wechatMp'
// ),
// ],
type: 'javascript/auto', type: 'javascript/auto',
use: [ use: [
oakFileLoader('wxml'), oakFileLoader('wxml'),
{ {
loader: 'wxml-loader', loader: 'wxml-loader',
options: {},
}, },
], ],
}, },

2
lib/build.d.ts vendored
View File

@ -1 +1 @@
export default function build(env: string): Promise<void>; export default function build(cmd: any): Promise<void>;

View File

@ -5,9 +5,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
const tip_style_1 = require("./tip-style"); const tip_style_1 = require("./tip-style");
const cross_spawn_1 = __importDefault(require("cross-spawn")); const cross_spawn_1 = __importDefault(require("cross-spawn"));
async function build(env) { async function build(cmd) {
(0, tip_style_1.Success)(`${(0, tip_style_1.success)(`build环境:${env}`)}`); (0, tip_style_1.Success)(`${(0, tip_style_1.success)(`build ${cmd.target} environment: ${cmd.mode}`)}`);
const result = cross_spawn_1.default.sync(`cross-env NODE_ENV=${env} "${process.execPath}"`, [require.resolve('../scripts/' + 'webpack.js')], { const result = cross_spawn_1.default.sync(`cross-env NODE_ENV=${cmd.mode} "${process.execPath}"`, [require.resolve('../scripts/' + 'webpack.js')], {
stdio: 'inherit', stdio: 'inherit',
shell: true, shell: true,
}); });

View File

@ -46,14 +46,16 @@ commander_1.default
.description('build oak app domain of make on demand') .description('build oak app domain of make on demand')
.action(make_1.default); .action(make_1.default);
commander_1.default commander_1.default
.command('start <env>') .command('start')
.usage('<env>') .option('-t, --target <target>', 'target')
.description('build we chat mp of start on demand') .option('-m, --mode <mode>', 'mode')
.description('build project of start on demand')
.action(build_1.default); .action(build_1.default);
commander_1.default commander_1.default
.command('build <env>') .command('build')
.usage('<env>') .option('-t, --target <target>', 'target')
.description('build we chat mp of build on demand') .option('-m, --mode <mode>', 'mode')
.description('build project of build on demand')
.action(build_1.default); .action(build_1.default);
commander_1.default commander_1.default
.command('create <name>') .command('create <name>')

View File

@ -23,8 +23,8 @@ function packageJsonContent({ name, version, description, cliversion, cliname, i
"description": "${description}", "description": "${description}",
"scripts": { "scripts": {
"make:domain": "${cliname} make", "make:domain": "${cliname} make",
"start:mp": "${cliname} start development", "start:mp": "${cliname} start --target mp --mode development",
"build:mp": "${cliname} build production" "build:mp": "${cliname} build --target mp --mode production"
}, },
"keywords": [], "keywords": [],
"author": "", "author": "",

View File

@ -39,7 +39,6 @@
"fs-extra": "^10.0.0", "fs-extra": "^10.0.0",
"globby": "^11.1.0", "globby": "^11.1.0",
"inquirer": "^7.3.3", "inquirer": "^7.3.3",
"loader-utils": "^3.2.0",
"mini-css-extract-plugin": "^2.5.3", "mini-css-extract-plugin": "^2.5.3",
"postcss-less": "^6.0.0", "postcss-less": "^6.0.0",
"progress-bar-webpack-plugin": "^2.1.0", "progress-bar-webpack-plugin": "^2.1.0",

View File

@ -504,7 +504,7 @@ class OakWeChatMpPlugin {
const emitAssets = []; const emitAssets = [];
for (let entry of this.assetsEntry) { for (let entry of this.assetsEntry) {
const assets = path.resolve(this.basePath, entry); const assets = path.resolve(this.basePath, entry);
if (/\.(sass|scss|css|less|styl|xml)$/.test(assets)) { if (/\.(sass|scss|css|less|styl|xml|wxml)$/.test(assets)) {
continue; continue;
} }
const toTmit = async () => { const toTmit = async () => {
@ -539,7 +539,7 @@ class OakWeChatMpPlugin {
} }
for (let entry of this.oakAssetsEntry) { for (let entry of this.oakAssetsEntry) {
const assets = path.resolve(process.cwd(), entry); const assets = path.resolve(process.cwd(), entry);
if (/\.(sass|scss|css|less|styl|xml)$/.test(assets)) { if (/\.(sass|scss|css|less|styl|xml|wxml)$/.test(assets)) {
continue; continue;
} }
const toTmit = async () => { const toTmit = async () => {

View File

@ -9,21 +9,21 @@ import {
} from './tip-style'; } from './tip-style';
import spawn from 'cross-spawn'; import spawn from 'cross-spawn';
export default async function build(env: string) { export default async function build(cmd: any) {
Success(`${success(`build环境:${env}`)}`); Success(`${success(`build ${cmd.target} environment: ${cmd.mode}`)}`);
const result = spawn.sync( const result = spawn.sync(
`cross-env NODE_ENV=${env} "${process.execPath}"`, `cross-env NODE_ENV=${cmd.mode} "${process.execPath}"`,
[require.resolve('../scripts/' + 'webpack.js')], [require.resolve('../scripts/' + 'webpack.js')],
{ {
stdio: 'inherit', stdio: 'inherit',
shell: true, shell: true,
} }
); );
// const result = spawn.sync('npm -v', [], { stdio: 'inherit', shell: true }); // const result = spawn.sync('npm -v', [], { stdio: 'inherit', shell: true });
if (result.status === 0) { if (result.status === 0) {
Success(`${success(`执行完成`)}`); Success(`${success(`执行完成`)}`);
} else { } else {
Error(`${error(`执行失败`)}`); Error(`${error(`执行失败`)}`);
} }
} }

View File

@ -48,14 +48,16 @@ program
.description('build oak app domain of make on demand') .description('build oak app domain of make on demand')
.action(make); .action(make);
program program
.command('start <env>') .command('start')
.usage('<env>') .option('-t, --target <target>', 'target')
.description('build we chat mp of start on demand') .option('-m, --mode <mode>', 'mode')
.description('build project of start on demand')
.action(build); .action(build);
program program
.command('build <env>') .command('build')
.usage('<env>') .option('-t, --target <target>', 'target')
.description('build we chat mp of build on demand') .option('-m, --mode <mode>', 'mode')
.description('build project of build on demand')
.action(build); .action(build);
program program
.command('create <name>') .command('create <name>')

View File

@ -29,8 +29,8 @@ export function packageJsonContent({
"description": "${description}", "description": "${description}",
"scripts": { "scripts": {
"make:domain": "${cliname} make", "make:domain": "${cliname} make",
"start:mp": "${cliname} start development", "start:mp": "${cliname} start --target mp --mode development",
"build:mp": "${cliname} build production" "build:mp": "${cliname} build --target mp --mode production"
}, },
"keywords": [], "keywords": [],
"author": "", "author": "",