UI for Zipcoin Blue

gulp.js 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const tslib_1 = require("tslib");
  4. const path = require("path");
  5. const chalk_1 = require("chalk");
  6. const errors_1 = require("./errors");
  7. const promise_1 = require("@ionic/cli-framework/utils/promise");
  8. let _gulpInst;
  9. function loadGulp(env) {
  10. return tslib_1.__awaiter(this, void 0, void 0, function* () {
  11. const { prettyPath } = yield Promise.resolve().then(() => require('./utils/format'));
  12. const { pkgManagerArgs } = yield Promise.resolve().then(() => require('./utils/npm'));
  13. const project = yield env.project.load();
  14. if (typeof project.integrations.gulp === 'undefined' || project.integrations.gulp.enabled === false) {
  15. throw new errors_1.FatalException('Not attempting to load gulp from a project with gulp integration disabled.');
  16. }
  17. const gulpFilePath = path.join(env.project.directory, project.integrations.gulp.file ? project.integrations.gulp.file : 'gulpfile.js');
  18. const gulpPath = path.join(env.project.directory, 'node_modules', 'gulp');
  19. try {
  20. _gulpInst = require(gulpPath);
  21. }
  22. catch (e) {
  23. if (e.code !== 'MODULE_NOT_FOUND') {
  24. throw e;
  25. }
  26. const gulpInstallArgs = yield pkgManagerArgs(env, { pkg: 'gulp', saveDev: true, saveExact: false });
  27. throw new errors_1.FatalException(`Gulp is not installed! You can install it locally:\n\n` +
  28. ` ${chalk_1.default.green(gulpInstallArgs.join(' '))}\n\n` +
  29. `Or, if you don't use gulp, you can disable it by running ${chalk_1.default.green('ionic config set gulp.enabled false')}.\n`);
  30. }
  31. try {
  32. require(gulpFilePath); // requiring the gulp file sets up the gulp instance with local gulp task definitions
  33. }
  34. catch (e) {
  35. if (e.code !== 'MODULE_NOT_FOUND') {
  36. throw e;
  37. }
  38. throw new errors_1.FatalException(`Gulpfile (or dependent module) not found: ${chalk_1.default.bold(prettyPath(gulpFilePath))}\n` +
  39. `For custom Gulpfile locations, you can run ${chalk_1.default.green('ionic config set gulp.file <path>')}. Otherwise, the default Ionic Gulpfile can be downloaded from ${chalk_1.default.bold('https://github.com/ionic-team/ionic-app-base/blob/master/gulpfile.js')}\n\n` +
  40. `Or, if you don't use gulp, you can disable it by running ${chalk_1.default.green('ionic config set gulp.enabled false')}.\n` +
  41. `Full error:\n\n` +
  42. chalk_1.default.red(e.stack ? e.stack : e));
  43. }
  44. return _gulpInst;
  45. });
  46. }
  47. exports.loadGulp = loadGulp;
  48. function getGulpVersion(env) {
  49. return tslib_1.__awaiter(this, void 0, void 0, function* () {
  50. let gulpVersion = yield env.shell.cmdinfo('gulp', ['--version']);
  51. if (gulpVersion) {
  52. gulpVersion = gulpVersion.replace(/\[[\d\:]+\]\s/g, '');
  53. gulpVersion = gulpVersion.trim();
  54. }
  55. return gulpVersion;
  56. });
  57. }
  58. exports.getGulpVersion = getGulpVersion;
  59. function checkGulp(env) {
  60. return tslib_1.__awaiter(this, void 0, void 0, function* () {
  61. const project = yield env.project.load();
  62. if (!project.integrations.gulp) {
  63. yield env.runCommand(['integrations', 'enable', 'gulp']);
  64. }
  65. });
  66. }
  67. exports.checkGulp = checkGulp;
  68. function runTask(env, name) {
  69. return tslib_1.__awaiter(this, void 0, void 0, function* () {
  70. const project = yield env.project.load();
  71. if (project.integrations.gulp && project.integrations.gulp.enabled !== false) {
  72. const gulp = yield loadGulp(env);
  73. const gulpStart = promise_1.promisify(gulp.start.bind(gulp));
  74. if (gulp.hasTask(name)) {
  75. env.log.debug(() => `Invoking ${chalk_1.default.cyan(name)} gulp task.`);
  76. try {
  77. yield gulpStart(name);
  78. }
  79. catch (e) {
  80. env.log.error(`Error occurred during ${chalk_1.default.cyan(name)} gulp task. Use ${chalk_1.default.green('--verbose')} to show details.`);
  81. throw e;
  82. }
  83. }
  84. else {
  85. env.log.debug(() => `Missing ${chalk_1.default.cyan(name)} gulp task.`);
  86. }
  87. }
  88. });
  89. }
  90. exports.runTask = runTask;
  91. function registerWatchEvents(env) {
  92. return tslib_1.__awaiter(this, void 0, void 0, function* () {
  93. const project = yield env.project.load();
  94. if (project.integrations.gulp && project.integrations.gulp.enabled !== false) {
  95. const gulp = yield loadGulp(env);
  96. env.events.on('watch:init', () => tslib_1.__awaiter(this, void 0, void 0, function* () {
  97. if (!gulp.hasTask('sass')) {
  98. env.log.warn(`The ${chalk_1.default.cyan('sass')} task not found in your Gulpfile, which is used to compile SCSS files. The default Ionic Gulpfile can be downloaded from ${chalk_1.default.bold('https://github.com/ionic-team/ionic-app-base/blob/master/gulpfile.js')}`);
  99. }
  100. }));
  101. env.events.on('watch:change', (filePath) => tslib_1.__awaiter(this, void 0, void 0, function* () {
  102. if (path.extname(filePath) === '.scss') {
  103. yield runTask(env, 'sass');
  104. }
  105. }));
  106. }
  107. });
  108. }
  109. exports.registerWatchEvents = registerWatchEvents;