build.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import { task } from 'gulp';
  2. import { join } from 'path';
  3. import { DIST_BUILD_ES2015_ROOT, DIST_BUILD_ROOT, DIST_BUILD_UMD_ROOT, ES5, ES_2015, PROJECT_ROOT, UMD_MODULE } from '../constants';
  4. import { copySourceToDest, createTempTsConfig, deleteFiles, runNgc, runTsc } from '../util';
  5. export function buildIonicAngularUmd(excludeSpec: boolean, stripDebug: boolean, done: Function) {
  6. const stream = copySourceToDest(DIST_BUILD_UMD_ROOT, excludeSpec, true, stripDebug);
  7. stream.on('end', () => {
  8. // the source files are copied, copy over a tsconfig from
  9. createTempTsConfig([join('.', '**', '*.ts')], ES5, UMD_MODULE, join(PROJECT_ROOT, 'tsconfig.json'), join(DIST_BUILD_UMD_ROOT, 'tsconfig.json'));
  10. runNgc(join(DIST_BUILD_UMD_ROOT, 'tsconfig.json'), (err) => {
  11. if (err) {
  12. done(err);
  13. return;
  14. }
  15. // clean up any .ts files that remain as well as ngc metadata
  16. deleteFiles([`${DIST_BUILD_UMD_ROOT}/**/*.ts`,
  17. `${DIST_BUILD_UMD_ROOT}/node_modules`,
  18. `${DIST_BUILD_UMD_ROOT}/tsconfig.json`,
  19. `!${DIST_BUILD_UMD_ROOT}/**/*.d.ts`], done);
  20. });
  21. });
  22. }
  23. export function buildIonicAngularUmdTsc(excludeSpec: boolean, stripDebug: boolean, done: Function) {
  24. const stream = copySourceToDest(DIST_BUILD_UMD_ROOT, excludeSpec, true, stripDebug);
  25. stream.on('end', () => {
  26. // the source files are copied, copy over a tsconfig from
  27. createTempTsConfig([join('.', '**', '*.ts')], ES5, UMD_MODULE, join(PROJECT_ROOT, 'tsconfig.json'), join(DIST_BUILD_UMD_ROOT, 'tsconfig.json'));
  28. runTsc(join(DIST_BUILD_UMD_ROOT, 'tsconfig.json'), (err) => {
  29. if (err) {
  30. done(err);
  31. return;
  32. }
  33. // clean up any .ts files that remain as well as ngc metadata
  34. deleteFiles([`${DIST_BUILD_UMD_ROOT}/**/*.ts`,
  35. `${DIST_BUILD_UMD_ROOT}/node_modules`,
  36. `${DIST_BUILD_UMD_ROOT}/tsconfig.json`,
  37. `!${DIST_BUILD_UMD_ROOT}/**/*.d.ts`], done);
  38. });
  39. });
  40. }
  41. export function buildIonicAngularEsm(stripDebug: boolean, done: Function) {
  42. const stream = copySourceToDest(DIST_BUILD_ROOT, true, true, stripDebug);
  43. stream.on('end', () => {
  44. // the source files are copied, copy over a tsconfig from
  45. createTempTsConfig([join('.', '**', '*.ts')], ES5, ES_2015, join(PROJECT_ROOT, 'tsconfig.json'), join(DIST_BUILD_ROOT, 'tsconfig.json'));
  46. runNgc(join(DIST_BUILD_ROOT, 'tsconfig.json'), (err) => {
  47. if (err) {
  48. done(err);
  49. return;
  50. }
  51. // clean up any .ts files that remain as well as ngc metadata
  52. deleteFiles([`${DIST_BUILD_ROOT}/**/*.ts`,
  53. `${DIST_BUILD_ROOT}/node_modules`,
  54. `${DIST_BUILD_ROOT}/tsconfig.json`,
  55. `!${DIST_BUILD_ROOT}/**/*.d.ts`], done);
  56. });
  57. });
  58. }
  59. export function buildIonicPureEs6(stripDebug: boolean, done: Function) {
  60. const stream = copySourceToDest(DIST_BUILD_ES2015_ROOT, true, true, stripDebug);
  61. stream.on('end', () => {
  62. // the source files are copied, copy over a tsconfig from
  63. createTempTsConfig([join('.', '**', '*.ts')], ES_2015, ES_2015, join(PROJECT_ROOT, 'tsconfig.json'), join(DIST_BUILD_ES2015_ROOT, 'tsconfig.json'));
  64. runNgc(join(DIST_BUILD_ES2015_ROOT, 'tsconfig.json'), (err) => {
  65. if (err) {
  66. done(err);
  67. return;
  68. }
  69. // clean up any .ts files that remain as well as ngc metadata
  70. deleteFiles([`${DIST_BUILD_ES2015_ROOT}/**/*.ts`,
  71. `${DIST_BUILD_ES2015_ROOT}/node_modules`,
  72. `${DIST_BUILD_ES2015_ROOT}/tsconfig.json`,
  73. `!${DIST_BUILD_ES2015_ROOT}/**/*.d.ts`], done);
  74. });
  75. });
  76. }
  77. /* this task builds out the necessary stuff for karma */
  78. task('compile.karma', (done: Function) => {
  79. buildIonicAngularUmdTsc(false, false, done);
  80. });
  81. /* this task builds out the ionic-angular (commonjs and esm) directories for release */
  82. task('compile.release', (done: Function) => {
  83. buildIonicAngularEsm(true, () => {
  84. buildIonicAngularUmd(true, true, () => {
  85. buildIonicPureEs6(true, done);
  86. });
  87. });
  88. });