123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- const tslib_1 = require("tslib");
- const path = require("path");
- const chalk_1 = require("chalk");
- const errors_1 = require("./errors");
- const promise_1 = require("@ionic/cli-framework/utils/promise");
- let _gulpInst;
- function loadGulp(env) {
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
- const { prettyPath } = yield Promise.resolve().then(() => require('./utils/format'));
- const { pkgManagerArgs } = yield Promise.resolve().then(() => require('./utils/npm'));
- const project = yield env.project.load();
- if (typeof project.integrations.gulp === 'undefined' || project.integrations.gulp.enabled === false) {
- throw new errors_1.FatalException('Not attempting to load gulp from a project with gulp integration disabled.');
- }
- const gulpFilePath = path.join(env.project.directory, project.integrations.gulp.file ? project.integrations.gulp.file : 'gulpfile.js');
- const gulpPath = path.join(env.project.directory, 'node_modules', 'gulp');
- try {
- _gulpInst = require(gulpPath);
- }
- catch (e) {
- if (e.code !== 'MODULE_NOT_FOUND') {
- throw e;
- }
- const gulpInstallArgs = yield pkgManagerArgs(env, { pkg: 'gulp', saveDev: true, saveExact: false });
- throw new errors_1.FatalException(`Gulp is not installed! You can install it locally:\n\n` +
- ` ${chalk_1.default.green(gulpInstallArgs.join(' '))}\n\n` +
- `Or, if you don't use gulp, you can disable it by running ${chalk_1.default.green('ionic config set gulp.enabled false')}.\n`);
- }
- try {
- require(gulpFilePath); // requiring the gulp file sets up the gulp instance with local gulp task definitions
- }
- catch (e) {
- if (e.code !== 'MODULE_NOT_FOUND') {
- throw e;
- }
- throw new errors_1.FatalException(`Gulpfile (or dependent module) not found: ${chalk_1.default.bold(prettyPath(gulpFilePath))}\n` +
- `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` +
- `Or, if you don't use gulp, you can disable it by running ${chalk_1.default.green('ionic config set gulp.enabled false')}.\n` +
- `Full error:\n\n` +
- chalk_1.default.red(e.stack ? e.stack : e));
- }
- return _gulpInst;
- });
- }
- exports.loadGulp = loadGulp;
- function getGulpVersion(env) {
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
- let gulpVersion = yield env.shell.cmdinfo('gulp', ['--version']);
- if (gulpVersion) {
- gulpVersion = gulpVersion.replace(/\[[\d\:]+\]\s/g, '');
- gulpVersion = gulpVersion.trim();
- }
- return gulpVersion;
- });
- }
- exports.getGulpVersion = getGulpVersion;
- function checkGulp(env) {
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
- const project = yield env.project.load();
- if (!project.integrations.gulp) {
- yield env.runCommand(['integrations', 'enable', 'gulp']);
- }
- });
- }
- exports.checkGulp = checkGulp;
- function runTask(env, name) {
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
- const project = yield env.project.load();
- if (project.integrations.gulp && project.integrations.gulp.enabled !== false) {
- const gulp = yield loadGulp(env);
- const gulpStart = promise_1.promisify(gulp.start.bind(gulp));
- if (gulp.hasTask(name)) {
- env.log.debug(() => `Invoking ${chalk_1.default.cyan(name)} gulp task.`);
- try {
- yield gulpStart(name);
- }
- catch (e) {
- env.log.error(`Error occurred during ${chalk_1.default.cyan(name)} gulp task. Use ${chalk_1.default.green('--verbose')} to show details.`);
- throw e;
- }
- }
- else {
- env.log.debug(() => `Missing ${chalk_1.default.cyan(name)} gulp task.`);
- }
- }
- });
- }
- exports.runTask = runTask;
- function registerWatchEvents(env) {
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
- const project = yield env.project.load();
- if (project.integrations.gulp && project.integrations.gulp.enabled !== false) {
- const gulp = yield loadGulp(env);
- env.events.on('watch:init', () => tslib_1.__awaiter(this, void 0, void 0, function* () {
- if (!gulp.hasTask('sass')) {
- 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')}`);
- }
- }));
- env.events.on('watch:change', (filePath) => tslib_1.__awaiter(this, void 0, void 0, function* () {
- if (path.extname(filePath) === '.scss') {
- yield runTask(env, 'sass');
- }
- }));
- }
- });
- }
- exports.registerWatchEvents = registerWatchEvents;
|