Переглянути джерело

feat(Builder): add tasks option and deprecate flag options

evshiron 8 роки тому
батько
коміт
974d9e0548
4 змінених файлів з 25 додано та 4 видалено
  1. 2 1
      README.md
  2. 6 0
      src/bin/build.ts
  3. 14 0
      src/lib/Builder.ts
  4. 3 3
      test/Builder.js

+ 2 - 1
README.md

@@ -62,7 +62,8 @@ This will specify the NW.js version we are using. See more in the following Opti
 // package.json
 {
     "scripts": {
-        "dist": "build --win --mac --linux --x86 --x64 --mirror https://dl.nwjs.io/ .",
+        // Deprecated. "dist": "build --win --mac --linux --x86 --x64 --mirror https://dl.nwjs.io/ .",
+        "dist": "build --tasks win-x86,win-x64,linux-x86,linux-x64,mac-x64 --mirror https://dl.nwjs.io/ .",
         "start": "run --x86 --mirror https://dl.nwjs.io/ ."
     }
 }

+ 6 - 0
src/bin/build.ts

@@ -35,6 +35,11 @@ const argv = require('yargs')
     describe: 'Build for x64 arch',
     default: Builder.DEFAULT_OPTIONS.x64,
 })
+.option('tasks', {
+    type: 'string',
+    describe: 'List of <PLATFORM>-<ARCH> to build, separated by comma.',
+    default: '',
+})
 .option('chrome-app', {
     type: 'boolean',
     describe: 'Build from Chrome App',
@@ -62,6 +67,7 @@ const argv = require('yargs')
         linux: argv.linux,
         x86: argv.x86,
         x64: argv.x64,
+        tasks: argv.tasks.split(','),
         chromeApp: argv['chrome-app'],
         mirror: argv.mirror,
         concurrent: argv.concurrent,

+ 14 - 0
src/lib/Builder.ts

@@ -30,6 +30,7 @@ interface IBuilderOptions {
     linux?: boolean;
     x86?: boolean;
     x64?: boolean;
+    tasks?: string[];
     chromeApp?: boolean;
     mirror?: string;
     concurrent?: boolean;
@@ -44,6 +45,7 @@ export class Builder {
         linux: false,
         x86: false,
         x64: false,
+        tasks: [],
         chromeApp: false,
         mirror: Downloader.DEFAULT_OPTIONS.mirror,
         concurrent: false,
@@ -73,6 +75,18 @@ export class Builder {
             });
         });
 
+        for(const task of this.options.tasks) {
+
+            const [ platform, arch ] = task.split('-');
+
+            if([ 'win', 'mac', 'linux' ].indexOf(platform) >= 0) {
+                if([ 'x86', 'x64' ].indexOf(arch) >= 0) {
+                    tasks.push([ platform, arch ]);
+                }
+            }
+
+        }
+
         if(!this.options.mute) {
             console.info('Starting building tasks...', {
                 tasks,

+ 3 - 3
test/Builder.js

@@ -6,18 +6,18 @@ import { spawnAsync } from '../dist/lib/util';
 
 const dir = './assets/project/';
 
-test('commandline --concurrent', async (t) => {
+test.serial('commandline --concurrent', async (t) => {
 
     const mirror = process.env.CI ? '' : '--mirror https://npm.taobao.org/mirrors/nwjs/';
 
-    const { code, signal } = await spawnAsync('node', `./dist/bin/build.js --win --mac --linux --x64 --concurrent ${ mirror } ${ dir }`.split(' '), {
+    const { code, signal } = await spawnAsync('node', `./dist/bin/build.js --tasks win-x64,linux-x64,mac-x64 --concurrent ${ mirror } ${ dir }`.split(' '), {
         stdio: 'inherit',
     });
     t.is(code, 0);
 
 });
 
-test.skip('module', async (t) => {
+test.serial('module', async (t) => {
 
     const mirror = process.env.CI ? undefined : 'https://npm.taobao.org/mirrors/nwjs/';