This repository has been archived by the owner on Apr 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
/
gulp-options-builder.js
executable file
·145 lines (125 loc) · 3.47 KB
/
gulp-options-builder.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import path from 'path';
import fs from 'fs';
import deepAssign from 'deep-assign';
import yargs from 'yargs';
const argv = yargs
.option('minify', {
type: 'boolean',
default: true
})
.option('open', {
type: 'boolean',
default: true
})
.option('preprocess', {
type: 'boolean',
default: true
})
.argv;
delete argv._;
delete argv.$0;
const deprecated = (name, warning) => {
console.warn(`[grommet-toolbox] DEPRECATED: ${name}. ${warning}`);
};
let options;
export function getOptions (opts) {
if (!options) {
if (!opts) {
const configPath = path.resolve(process.cwd(), 'grommet-toolbox.config.js');
try {
fs.accessSync(configPath, fs.F_OK);
} catch (e) {
opts = {};
}
if (!opts) {
const config = require(configPath);
opts = config.default || config;
}
}
options = opts || {};
options.lintCache = opts.lintCache !== undefined ? opts.lintCache : true;
if (options.scsslint || options.scsslint === false) {
console.warn('[grommet-toolbox] scsslint option has been deprecated and will be removed in the next major release. SCSS linting is always enabled now.');
}
options.scsslint = options.scsslint === undefined ? true : options.scsslint;
options.dist = options.dist || path.resolve(process.cwd(), 'dist');
const jsLoader = options.jsLoader || {
test: /\.jsx?|.react$/,
loader: 'babel',
exclude: /(node_modules|bower_components|src\/lib)/
};
const scssLoader = options.scssLoader || {
test: /\.scss$/,
loader: 'style!css!sass?outputStyle=compressed&' +
'includePaths[]=' +
(encodeURIComponent(
path.resolve(options.base || process.cwd(), './node_modules')
)) +
'&includePaths[]=' +
(encodeURIComponent(
path.resolve(options.base || process.cwd(),
'./node_modules/grommet/node_modules'))
)
};
options.webpack = deepAssign({
entry: options.webpack && options.webpack.entry ?
options.webpack.entry : path.resolve(options.mainJs),
output: {
filename: 'index.js'
},
resolve: {
root: [
path.resolve(process.cwd(), 'node_modules')
]
},
module: {
loaders: []
},
resolveLoader: {}
}, options.webpack);
options.webpack.module.loaders = options.webpack.module.loaders.concat(
jsLoader,
scssLoader,
{
test: /\.json$/,
loader: 'json-loader'
},
{
test: /\.png$/,
loader: 'file-loader?mimetype=image/png'
},
{
test: /\.jpg$/,
loader: 'file-loader?mimetype=image/jpg'
},
{
test: /\.woff$/,
loader: 'file-loader?mimetype=application/font-woff'
},
{
test: /\.otf$/,
loader: 'file-loader?mimetype=application/font/opentype'
},
{
test: /\.css$/,
loader: 'style-loader!css-loader'
}
);
// Argv Deprecation warnings
if (argv.skipPreprocess) {
deprecated('skipPreprocess', 'Use --no-preprocess instead.');
argv.preprocess = false;
}
if (argv.skipOpen) {
deprecated('skipOpen', 'Use --no-open instead.');
argv.open = false;
}
if (argv.skipMinify) {
deprecated('skipMinify', 'Use --no-minify instead.');
argv.minify = false;
}
options.argv = deepAssign({}, options.argv, argv);
}
return options;
};
export default getOptions;