ponk
Version:
The development package for central platform of PO team.
103 lines (90 loc) • 2.7 kB
JavaScript
const fs = require('fs');
const path = require('path');
const notifier = require('node-notifier');
const gulpUtil = require('gulp-util');
module.exports = {
root(...args) {
return path.join(__dirname, ...args);
},
cwd(...args) {
return path.join(process.cwd(), ...args);
},
notify(message, title = 'Central Platform Notify!') {
notifier.notify({ title, message });
},
printWebpackStats(err, stats) {
if (err) {
throw new gulpUtil.PluginError('webpack', err);
}
let statColor = stats.compilation.warnings.length < 1 ? 'green' : 'yellow';
if (stats.compilation.warnings.length > 0) {
stats.compilation.errors.forEach(error => {
statColor = 'red';
});
} else {
gulpUtil.log(stats.toString({
colors: gulpUtil.colors.supportsColor,
hash: false,
timings: true,
chunks: true,
chunkModules: false,
modules: false,
children: false,
version: true,
cached: true,
cachedAssets: true,
reasons: false,
source: false,
errorDetails: false
}));
}
},
fileExists(file) {
return fs.existsSync(file);
},
isUpperCase: isUpperCase,
rxjsExternalsFactory: rxjsExternalsFactory
};
function isUpperCase(s) {
return s.toUpperCase() === s;
}
const rootPatterns = [{
// rxjs/operators/map
regex: /^rxjs\/operators\//,
root: ['Rx', 'operators']
}, {
// rxjs/operator/map
regex: /^rxjs\/operator\//,
root: ['Rx', 'Observable', 'prototype']
}, {
// rxjs/observable/interval
regex: /^rxjs\/observable\/[a-z]/,
root: ['Rx', 'Observable']
}, {
// rxjs/observable/MulticastObservable
regex: /^rxjs\/observable\/[A-Z]/,
root: 'Rx'
}, {
// rxjs/scheduler/asap
regex: /^rxjs\/scheduler\/[a-z]/,
root: ['Rx', 'Scheduler']
}, {
// rxjs/scheduler/VirtualTimeScheduler
regex: /^rxjs\/scheduler\/[A-Z]/,
root: 'Rx'
}];
function rootForRequest(path) {
const match = rootPatterns.find(pattern => path.match(pattern.regex));
if (match) {
return match.root.join('.');
}
return 'Rx';
}
function rxjsExternalsFactory() {
return function rxjsExternals(context, request, callback) {
if (request.startsWith('rxjs/')) {
return callback(null, rootForRequest(request));
}
callback();
};
}