Commit b6de9e21 authored by rockyl's avatar rockyl

构建过程兼容yarnpkg

parent e94c2ebb
const program = require('commander');
const {exit, executeBuildProcess, updateProjectConfig} = require('./tools');
const {exit, executeBuildProcess, updateBuildConfig} = require('./tools');
program
.option('-u, --upload-auto', 'Auto upload after build success', false)
......@@ -8,7 +8,7 @@ program
async function execute() {
const version = await executeBuildProcess('build');
//console.log('detected version:', version);
updateProjectConfig('version', version);
updateBuildConfig('version', version);
if(program.uploadAuto){
console.log('\nAuto uploading...');
......
const path = require('path');
const program = require('commander');
const {exit, getProjectConfig} = require('./tools');
const {exit, getManifest} = require('./tools');
const ossUpload = require('./oss-upload');
program
......@@ -13,11 +13,11 @@ async function execute() {
let version = program.versionCode;
let releasePath = './bin-release/web/';
const gameProjectConfig = getProjectConfig();
if(gameProjectConfig){
remotePath = gameProjectConfig['remote-path'];
version = version ? version : gameProjectConfig['version'];
releasePath = gameProjectConfig['release-path'];
const manifest = getManifest();
if(manifest && manifest.build){
remotePath = manifest.build['remote-path'];
version = version ? version : manifest.build['version'];
releasePath = manifest.build['release-path'] || releasePath;
}
if(version){
......
......@@ -53,49 +53,98 @@ exports.npmRun = function (path, scriptName) {
return childProcess('npm', ['run', scriptName], path);
};
const projectFile = './project.json';
const packageJsonFile = path.resolve('./package.json');
let packageObj;
const getProjectConfig = exports.getProjectConfig = function () {
const gameFile = path.resolve(projectFile);
if (fs.existsSync(gameFile)) {
return require(gameFile)
function ensurePackage() {
if (packageObj) {
return packageObj;
}else{
if (fs.existsSync(packageJsonFile)) {
packageObj = require(packageJsonFile);
return packageObj;
} else {
console.log('package.json is not exist');
}
}
}
function savePackage(){
if(packageObj){
fs.writeFileSync(packageJsonFile, JSON.stringify(packageObj, null, '\t'));
}
}
const getManifest = exports.getManifest = function () {
if(!ensurePackage()){
console.log('package.json is not exist');
return;
}
let manifest = packageObj.manifest;
if (!manifest) {
manifest = packageObj.manifest = {};
}
return manifest;
};
exports.updateProjectConfig = function (key, value) {
const config = getProjectConfig();
if (config) {
config[key] = value;
exports.updateBuildConfig = function (key, value) {
const manifest = getManifest();
if (manifest) {
let build = manifest.build;
if (!build) {
build = manifest.build = {};
}
build[key] = value;
savePackage();
}
fs.writeFileSync(projectFile, JSON.stringify(config, null, '\t'));
};
function findGlobalModulePath(moduleName){
const npm = require('global-modules');
let modulePath = path.resolve(npm, moduleName);
if(fs.existsSync(modulePath)){
return modulePath;
}
const yarnModules = require('yarn-config-directory')();
modulePath = path.resolve(yarnModules, 'global', moduleName);
if(fs.existsSync(modulePath)){
return modulePath;
}
modulePath = path.resolve(yarnModules, 'link', moduleName);
if(fs.existsSync(modulePath)){
return modulePath;
}
}
exports.executeBuildProcess = function (cmd) {
return new Promise((resolve, reject) => {
let buildProcessName;
const gameProjectConfig = getProjectConfig();
if (gameProjectConfig) {
buildProcessName = gameProjectConfig['build-process'];
const manifest = getManifest();
try {
buildProcessName = manifest.build['build-process'];
}catch (e) {
console.log('invalid manifest config')
}
if (buildProcessName) {
const npm = require('global-npm');
let globalModulePath = findGlobalModulePath('game-cli-build-process-' + buildProcessName);
try {
const modulePath = path.resolve(npm.GLOBAL_NPM_PATH, '../game-cli-build-process-' + buildProcessName);
const buildProcess = require(modulePath);
const buildProcess = require(globalModulePath);
if (buildProcess.hasOwnProperty(cmd)) {
resolve(buildProcess);
} else {
console.log(`Build process [${name}] has not implement ${cmd} function`)
console.log(`Build process [${buildProcessName}] has not implement ${cmd} function`)
}
} catch (e) {
reject('Build process is not found, please install with --global\n' + 'GLOBAL_NPM_PATH: ' + npm.GLOBAL_NPM_PATH);
}
}
reject('Build process name is not found, please setup ' + projectFile);
reject('Build process name is not found, please setup ' + packageJsonFile);
}).then(
(buildProcess) => {
return buildProcess[cmd]()
......
This diff is collapsed.
......@@ -372,12 +372,21 @@ glob@^7.0.5, glob@^7.1.2:
once "^1.3.0"
path-is-absolute "^1.0.0"
global-npm@^0.3.0:
version "0.3.0"
resolved "http://registry.npm.taobao.org/global-npm/download/global-npm-0.3.0.tgz#7c5115394a677d1245c4e3ba0b78bb6752797ee0"
integrity sha1-fFEVOUpnfRJFxOO6C3i7Z1J5fuA=
global-modules@^2.0.0:
version "2.0.0"
resolved "http://registry.npm.taobao.org/global-modules/download/global-modules-2.0.0.tgz#997605ad2345f27f51539bea26574421215c7780"
integrity sha1-mXYFrSNF8n9RU5vqJldEISFcd4A=
dependencies:
global-prefix "^3.0.0"
global-prefix@^3.0.0:
version "3.0.0"
resolved "http://registry.npm.taobao.org/global-prefix/download/global-prefix-3.0.0.tgz#fc85f73064df69f50421f47f883fe5b913ba9b97"
integrity sha1-/IX3MGTfafUEIfR/iD/luRO6m5c=
dependencies:
which "^1.2.1"
ini "^1.3.5"
kind-of "^6.0.2"
which "^1.3.1"
graceful-fs@^4.1.2, graceful-fs@^4.1.6:
version "4.1.11"
......@@ -389,6 +398,13 @@ has-flag@^3.0.0:
resolved "http://registry.npm.taobao.org/has-flag/download/has-flag-3.0.0.tgz#b5d454dc2199ae225699f3467e5a07f3b955bafd"
integrity sha1-tdRU3CGZriJWmfNGfloH87lVuv0=
homedir-polyfill@^1.0.1:
version "1.0.3"
resolved "http://registry.npm.taobao.org/homedir-polyfill/download/homedir-polyfill-1.0.3.tgz#743298cef4e5af3e194161fbadcc2151d3a058e8"
integrity sha1-dDKYzvTlrz4ZQWH7rcwhUdOgWOg=
dependencies:
parse-passwd "^1.0.0"
http-errors@1.6.3:
version "1.6.3"
resolved "http://registry.npm.taobao.org/http-errors/download/http-errors-1.6.3.tgz#8b55680bb4be283a0b5bf4ea2e38580be1d9320d"
......@@ -449,6 +465,11 @@ inherits@2, inherits@2.0.3, inherits@^2.0.1, inherits@~2.0.1, inherits@~2.0.3:
resolved "http://registry.npm.taobao.org/inherits/download/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de"
integrity sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=
ini@^1.3.5:
version "1.3.5"
resolved "http://registry.npm.taobao.org/ini/download/ini-1.3.5.tgz#eee25f56db1c9ec6085e0c22778083f596abf927"
integrity sha1-7uJfVtscnsYIXgwid4CD9Zar+Sc=
ip@^1.1.4, ip@^1.1.5:
version "1.1.5"
resolved "http://registry.npm.taobao.org/ip/download/ip-1.1.5.tgz#bdded70114290828c0a039e72ef25f5aaec4354a"
......@@ -505,6 +526,11 @@ jstoxml@^0.2.3:
resolved "http://registry.npm.taobao.org/jstoxml/download/jstoxml-0.2.4.tgz#ff3fb67856883a032953c7ce8ce7486210f48447"
integrity sha1-/z+2eFaIOgMpU8fOjOdIYhD0hEc=
kind-of@^6.0.2:
version "6.0.2"
resolved "http://registry.npm.taobao.org/kind-of/download/kind-of-6.0.2.tgz#01146b36a6218e64e58f3a8d66de5d7fc6f6d051"
integrity sha1-ARRrNqYhjmTljzqNZt5df8b20FE=
ko-sleep@^1.0.3:
version "1.0.3"
resolved "http://registry.npm.taobao.org/ko-sleep/download/ko-sleep-1.0.3.tgz#28a2a0a1485e8b7f415ff488dee17d24788ab082"
......@@ -673,6 +699,11 @@ pac-resolver@^3.0.0:
netmask "^1.0.6"
thunkify "^2.1.2"
parse-passwd@^1.0.0:
version "1.0.0"
resolved "http://registry.npm.taobao.org/parse-passwd/download/parse-passwd-1.0.0.tgz#6d5b934a456993b23d37f40a382d6f1666a8e5c6"
integrity sha1-bVuTSkVpk7I9N/QKOC1vFmao5cY=
path-is-absolute@^1.0.0:
version "1.0.1"
resolved "http://registry.npm.taobao.org/path-is-absolute/download/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f"
......@@ -998,7 +1029,7 @@ utility@^1.12.0, utility@^1.8.0:
mz "^2.7.0"
unescape "^1.0.1"
which@^1.2.1:
which@^1.3.1:
version "1.3.1"
resolved "http://registry.npm.taobao.org/which/download/which-1.3.1.tgz#a45043d54f5805316da8d62f9f50918d3da70b0a"
integrity sha1-pFBD1U9YBTFtqNYvn1CRjT2nCwo=
......@@ -1049,3 +1080,10 @@ yallist@^2.1.2:
version "2.1.2"
resolved "http://registry.npm.taobao.org/yallist/download/yallist-2.1.2.tgz#1c11f9218f076089a47dd512f93c6699a6a81d52"
integrity sha1-HBH5IY8HYImkfdUS+TxmmaaoHVI=
yarn-config-directory@^1.0.2:
version "1.0.2"
resolved "http://registry.npm.taobao.org/yarn-config-directory/download/yarn-config-directory-1.0.2.tgz#2cedebe406c5799193bfcaf5f65a0a3235d2b7ba"
integrity sha1-LO3r5AbFeZGTv8r19loKMjXSt7o=
dependencies:
homedir-polyfill "^1.0.1"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment