Skip to content

Commit

Permalink
NEW COMMAND: "uapp run build:dev --sync"
Browse files Browse the repository at this point in the history
deprecated command: "uapp publish debug"
  • Loading branch information
zencodex committed Oct 12, 2023
1 parent ac13e45 commit 0487fa6
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 38 deletions.
8 changes: 7 additions & 1 deletion doc/help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ uapp 通用命令🔥
uapp prepare

- 发布离线打包基座到 HBuilderX 下
uapp publish debug
uapp run build:dev --sync (uapp publish debug 将弃用)

- 编译开发包,不发布
uapp run build:dev

- 编译 release 包
uapp run build

其他命令:

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "uapp",
"version": "2.1.12",
"version": "2.2.1",
"description": "uapp 是一个方便 uniapp 离线打包的脚手架工具,类似 cordova, expo, Taro 等项目cli的作用。uapp还包含 uapp-android, uapp-ios 两个平台的模板代码",
"main": "bin/uapp",
"bin": {
Expand Down
105 changes: 69 additions & 36 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ const chalk = require('chalk');
const pkg = require('../package.json');
const sync = require('./sync');
const stripJsonComments = require('./stripJsonComments');
const { removeSync } = require('fs-extra')
const { removeSync } = require('fs-extra');

const knownOpts = {
version: Boolean,
help: Boolean
help: Boolean,
sync: Boolean
};

const shortHands = {
Expand Down Expand Up @@ -168,6 +169,71 @@ module.exports = function (inputArgs) {
return;
}

// commands:
// uapp run build
// uapp run build:dev --sync
if (cmd === 'run' && (args.argv.remain[1] === 'build' || args.argv.remain[1] === 'build:dev')) {
checkManifest();

let buildType = args.argv.remain[1];
if (projectType === 'android') {
let assembleTypeMap = {
'build': 'assembleRelease',
'build:dev': 'assembleDebug'
};

let outFileMap = {
'build': 'release/app-release.apk',
'build:dev': 'debug/app-debug.apk'
};

let gradle = require('os').type() === 'Windows_NT' ? 'gradlew.bat' : './gradlew';
require('child_process').execSync(gradle + ` ${assembleTypeMap[buildType]}`, { stdio: 'inherit' });
let buildOutFile = path.join(appDir, 'app/build/outputs/apk/', outFileMap[buildType]);

if (buildType === 'build:dev' && args.sync) {
sync(
buildOutFile,
path.join(path.dirname(fs.realpathSync(localLinkManifest)), 'unpackage/debug/android_debug.apk')
);
}

console.log('\n编译成功,安装包位置: ');
console.log(buildOutFile);
return;
}

if (projectType === 'ios') {
if (buildType !== 'build:dev' || !args.sync) {
console.log('iOS仅支持基座发布命令uapp run build:dev --sync,其他情况请直接使用 xcode');
return;
}

// gererate uapp_debug.xcarchive
require('child_process').execSync(
'xcodebuild -project uapp.xcodeproj -destination "generic/platform=iOS" -scheme "HBuilder" -archivePath out/uapp_debug.xcarchive archive',
{ stdio: 'inherit' }
);

// generate ipa
require('child_process').execSync(
'xcodebuild -exportArchive -archivePath out/uapp_debug.xcarchive -exportPath out -exportOptionsPlist config/export.plist',
{ stdio: 'inherit' }
);

if (args.sync) {
sync(
path.join(appDir, 'out/HBuilder.ipa'),
path.join(path.dirname(fs.realpathSync(localLinkManifest)), 'unpackage/debug/ios_debug.ipa')
);
}
return;
}

console.log('无法识别的工程模板,请参考帮助');
return;
}

// commands:
// uapp manifest sync ${webapp}/src/manifest.json
// uapp manifest info
Expand Down Expand Up @@ -231,40 +297,7 @@ module.exports = function (inputArgs) {

// command: uapp publish debug
if (cmd === 'publish' && args.argv.remain[1] === 'debug') {
checkManifest();

if (projectType === 'ios') {
// gererate uapp_debug.xcarchive
require('child_process').execSync(
'xcodebuild -project uapp.xcodeproj -destination "generic/platform=iOS" -scheme "HBuilder" -archivePath out/uapp_debug.xcarchive archive',
{ stdio: 'inherit' }
);

// generate ipa
require('child_process').execSync(
'xcodebuild -exportArchive -archivePath out/uapp_debug.xcarchive -exportPath out -exportOptionsPlist config/export.plist',
{ stdio: 'inherit' }
);

sync(
path.join(appDir, 'out/HBuilder.ipa'),
path.join(path.dirname(fs.realpathSync(localLinkManifest)), 'unpackage/debug/ios_debug.ipa')
);
return;
}

if (projectType === 'android') {
let gradle = require('os').type() === 'Windows_NT' ? 'gradlew.bat' : './gradlew';
require('child_process').execSync(gradle + ' assembleDebug', { stdio: 'inherit' });

sync(
path.join(appDir, 'app/build/outputs/apk/debug/app-debug.apk'),
path.join(path.dirname(fs.realpathSync(localLinkManifest)), 'unpackage/debug/android_debug.apk')
);
return;
}

console.log('无法识别的工程模板,请参考帮助');
console.log('此命令已弃用,请使用 uapp run build:dev --sync');
return;
}

Expand Down

0 comments on commit 0487fa6

Please sign in to comment.