Builder.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import { test } from 'ava';
  2. import { Builder } from '../';
  3. import { spawnAsync } from '../dist/lib/util';
  4. const dir = './assets/project/';
  5. test.serial('commandline', async (t) => {
  6. const platform = (() => {
  7. switch(process.platform) {
  8. case 'win32':
  9. return '--win';
  10. case 'darwin':
  11. return '--mac';
  12. case 'linux':
  13. return '--linux';
  14. default:
  15. throw new Error('ERROR_UNKNOWN_PLATFORM');
  16. }
  17. })();
  18. const mirror = process.env.CI ? '' : '--mirror https://npm.taobao.org/mirrors/nwjs/';
  19. const { code, signal } = await spawnAsync('node', `./dist/bin/build.js ${ platform } --x64 ${ mirror } ${ dir }`.split(' '), {
  20. stdio: 'inherit',
  21. });
  22. t.is(code, 0);
  23. });
  24. test.serial('commandline --config', async (t) => {
  25. const platform = (() => {
  26. switch(process.platform) {
  27. case 'win32':
  28. return '--win';
  29. case 'darwin':
  30. return '--mac';
  31. case 'linux':
  32. return '--linux';
  33. default:
  34. throw new Error('ERROR_UNKNOWN_PLATFORM');
  35. }
  36. })();
  37. const mirror = process.env.CI ? '' : '--mirror https://npm.taobao.org/mirrors/nwjs/';
  38. const { code, signal } = await spawnAsync('node', `./dist/bin/build.js ${ platform } --x64 ${ mirror } --config ${ dir }/package.json ${ dir }`.split(' '), {
  39. stdio: 'inherit',
  40. });
  41. t.is(code, 0);
  42. });
  43. (process.env.CI ? test.skip.serial : test.serial)('module', async (t) => {
  44. const mirror = process.env.CI ? undefined : 'https://npm.taobao.org/mirrors/nwjs/';
  45. const builder = new Builder({
  46. win: true,
  47. mac: true,
  48. linux: true,
  49. x64: true,
  50. mirror,
  51. }, dir);
  52. await builder.build();
  53. });