123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- var jscodeshift = require('jscodeshift');
- function createArrowFunction(value) {
- return '() => ' + '\'' + value + '\'';
- }
- function createRegularFunction(value) {
- return 'function () {\n return ' + '\'' + value + '\'' + '\n}';
- }
- function createDynamicPromise(arr) {
- if(Array.isArray(arr)) {
- return '() => new Promise((resolve) => resolve([' + arr.map( (n) => {
- return '\'' + n + '\'';
- }) + ']))';
- } else {
- return '() => new Promise((resolve) => resolve(' + '\'' + arr + '\'' + '))';
- }
- }
- function createAssetFilterFunction(value) {
- return 'function (assetFilename) {\n return assetFilename.endsWith(' + '\'' + '.' + value + '\'' + ');\n}';
- }
- function createExternalFunction(regexp) {
- return '\n function (context, request, callback) {\n if ('
- + '/' + regexp + '/.test(request)){' + '\n' + ' return callback(null, \'commonjs\' + request);\n}\n'
- + 'callback();\n}';
- }
- function parseValue(regexp) {
- return jscodeshift(regexp);
- }
- function createCommonsChunkPlugin(value) {
- return 'new webpack.optimize.CommonsChunkPlugin({name:' + '\'' + value + '\'' + ',filename:' + '\'' + value + '\-[hash].min.js\'})';
- }
- function createRequire(val) {
- return 'const ' + val + ' = ' + 'require(' + '\'' + val + '\'' + ');';
- }
- function List(name, message, choices) {
- return ({
- type: 'list',
- name: name,
- message: message,
- choices: choices
- });
- }
- function RawList(name, message, choices) {
- return ({
- type: 'rawlist',
- name: name,
- message: message,
- choices: choices
- });
- }
- function CheckList(name, message, choices) {
- return ({
- type: 'checkbox',
- name: name,
- message: message,
- choices: choices
- });
- }
- function Input(name, message) {
- return ({
- type: 'input',
- name: name,
- message: message
- });
- }
- function InputValidate(name, message, cb) {
- return ({
- type: 'input',
- name: name,
- message: message,
- validate: cb
- });
- }
- function Confirm(name, message) {
- return ({
- type: 'confirm',
- name: name,
- message: message,
- });
- }
- module.exports = {
- createArrowFunction,
- createDynamicPromise,
- createRegularFunction,
- createAssetFilterFunction,
- createExternalFunction,
- parseValue,
- createCommonsChunkPlugin,
- createRequire,
- List,
- RawList,
- CheckList,
- Input,
- InputValidate,
- Confirm
- };
|