common.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. const argv = require('minimist')(process.argv);
  2. const os = require('os');
  3. const gulp = require('gulp');
  4. const shell = require('gulp-shell');
  5. const FwdRef = require('undertaker-forward-reference');
  6. const path = require('path');
  7. // https://github.com/gulpjs/undertaker-forward-reference
  8. // https://github.com/gulpjs/gulp/issues/802
  9. gulp.registry(FwdRef());
  10. module.exports = (config, projectBase) => {
  11. function filterSections(func) {
  12. const sections = {};
  13. for (const section in config.sections) {
  14. const sectionConfig = config.sections[section];
  15. if (func(sectionConfig, section)) {
  16. sections[section] = sectionConfig;
  17. }
  18. }
  19. return sections;
  20. }
  21. config.production = argv.production || false;
  22. config.watching = argv._.indexOf('watch') !== -1 ? 'initial' : false;
  23. config.write = argv.fs || false;
  24. config.analyzeBundle = argv['analyze-bundle'] || false;
  25. config.ssr = argv.ssr || false; // 'client' | 'server' | false
  26. config.client = argv.client || false;
  27. // If true, will not push the client package using gjpush.
  28. config.noGjPush = argv.noGjPush || false;
  29. // If true, the client package will be pushed to the test package.
  30. config.useTestPackage = argv.useTestPackage || false;
  31. config.noClean = argv.noClean || false;
  32. // Whether or not the environment of angular should be production or development.
  33. // Even when not doing prod builds we use the prod environment by default.
  34. // This way it's easy for anyone to build without the GJ dev environment.
  35. // You can pass this flag in to include the dev environment config for angular instead.
  36. config.developmentEnv = argv.development || false;
  37. // If true, will enable the auto updater checks for the client package.
  38. config.withUpdater = argv.withUpdater || false;
  39. config.port = config.port || argv.port || 8080;
  40. // On start, the client redirects to auth when it doesnt have a user in localstorage,
  41. // and redirects to app when it does.
  42. // When watching the client (as opposed to building it fully), this is undesired because
  43. // at the time of writing we are limited to watching one section at a time in the client.
  44. config.withLocalStorageAuthRedirect = argv.withLocalStorageAuthRedirect || !config.watching;
  45. config.translationSections = config.translationSections || [];
  46. config.buildSection = argv['section'] || 'app';
  47. if (config.ssr === 'server') {
  48. config.sections = filterSections(i => i.server);
  49. } else if (config.client) {
  50. config.sections = filterSections(i => i.client);
  51. }
  52. if (argv['section']) {
  53. const newConfigSections = {};
  54. const argSections = argv['section'].split(',');
  55. for (let argSection of argSections) {
  56. newConfigSections[argSection] = config.sections[argSection];
  57. }
  58. config.sections = newConfigSections;
  59. }
  60. config.projectBase = projectBase;
  61. config.buildBaseDir = process.env.BUILD_DIR || '.';
  62. if (!config.buildBaseDir.endsWith(path.sep)) {
  63. config.buildBaseDir += path.sep;
  64. }
  65. config.buildDir = config.buildBaseDir + (config.production ? 'build/prod' : 'build/dev');
  66. config.libDir = 'src/lib/';
  67. if (config.client || config.ssr) {
  68. config.write = true;
  69. }
  70. if (config.ssr === 'server') {
  71. config.buildDir += '-server';
  72. } else if (config.client) {
  73. config.buildDir += '-client';
  74. config.clientBuildDir = config.buildDir + '-build';
  75. config.clientBuildCacheDir = config.buildDir + '-cache';
  76. config.arch = argv.arch || '64';
  77. // Get our platform that we are building on.
  78. switch (os.type()) {
  79. case 'Linux':
  80. config.platform = 'linux';
  81. break;
  82. case 'Windows_NT':
  83. config.platform = 'win';
  84. break;
  85. case 'Darwin':
  86. config.platform = 'osx';
  87. break;
  88. default:
  89. throw new Error('Can not build client on your OS type.');
  90. }
  91. config.platformArch = config.platform + config.arch;
  92. }
  93. require('./clean.js')(config);
  94. require('./translations.js')(config);
  95. require('./client.js')(config);
  96. require('./webpack.js')(config);
  97. };