@weapp-tailwindcss/cli 0.0.0-alpha.0 → 0.0.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +523 -62
- package/dist/index.d.cts +42 -3
- package/dist/index.d.mts +42 -3
- package/dist/index.d.ts +42 -3
- package/dist/index.mjs +520 -61
- package/package.json +5 -1
package/dist/index.cjs
CHANGED
|
@@ -3,19 +3,19 @@
|
|
|
3
3
|
const commander = require('commander');
|
|
4
4
|
const loadPostcssConfig = require('postcss-load-config');
|
|
5
5
|
const path = require('node:path');
|
|
6
|
-
const gulp = require('weapp-tailwindcss/gulp');
|
|
7
|
-
const gulp$1 = require('gulp');
|
|
8
6
|
const fs = require('fs-extra');
|
|
7
|
+
const gulp$1 = require('gulp');
|
|
8
|
+
const gulp = require('weapp-tailwindcss/gulp');
|
|
9
9
|
const cosmiconfig = require('cosmiconfig');
|
|
10
10
|
|
|
11
11
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
12
12
|
|
|
13
13
|
const loadPostcssConfig__default = /*#__PURE__*/_interopDefaultCompat(loadPostcssConfig);
|
|
14
14
|
const path__default = /*#__PURE__*/_interopDefaultCompat(path);
|
|
15
|
-
const gulp__default = /*#__PURE__*/_interopDefaultCompat(gulp$1);
|
|
16
15
|
const fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
|
|
16
|
+
const gulp__default = /*#__PURE__*/_interopDefaultCompat(gulp$1);
|
|
17
17
|
|
|
18
|
-
function isPlainObject(value) {
|
|
18
|
+
function isPlainObject$2(value) {
|
|
19
19
|
if (value === null || typeof value !== "object") {
|
|
20
20
|
return false;
|
|
21
21
|
}
|
|
@@ -33,7 +33,7 @@ function isPlainObject(value) {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
function _defu(baseObject, defaults, namespace = ".", merger) {
|
|
36
|
-
if (!isPlainObject(defaults)) {
|
|
36
|
+
if (!isPlainObject$2(defaults)) {
|
|
37
37
|
return _defu(baseObject, {}, namespace, merger);
|
|
38
38
|
}
|
|
39
39
|
const object = Object.assign({}, defaults);
|
|
@@ -50,7 +50,7 @@ function _defu(baseObject, defaults, namespace = ".", merger) {
|
|
|
50
50
|
}
|
|
51
51
|
if (Array.isArray(value) && Array.isArray(object[key])) {
|
|
52
52
|
object[key] = [...value, ...object[key]];
|
|
53
|
-
} else if (isPlainObject(value) && isPlainObject(object[key])) {
|
|
53
|
+
} else if (isPlainObject$2(value) && isPlainObject$2(object[key])) {
|
|
54
54
|
object[key] = _defu(
|
|
55
55
|
value,
|
|
56
56
|
object[key],
|
|
@@ -79,40 +79,21 @@ var AssetType = /* @__PURE__ */ ((AssetType2) => {
|
|
|
79
79
|
return AssetType2;
|
|
80
80
|
})(AssetType || {});
|
|
81
81
|
|
|
82
|
-
|
|
83
|
-
const
|
|
84
|
-
const
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
include
|
|
96
|
-
} = defu(options, {
|
|
97
|
-
outDir: "dist",
|
|
98
|
-
weappTailwindcssOptions: {},
|
|
99
|
-
clean: true,
|
|
100
|
-
src: "",
|
|
101
|
-
exclude: [...defaultNodeModulesDirs],
|
|
102
|
-
extensions: {
|
|
103
|
-
javascript: [...defaultJavascriptExtensions, ...defaultTypescriptExtensions, ...defaultWxsExtensions],
|
|
104
|
-
html: ["wxml"],
|
|
105
|
-
css: ["wxss", "less", "sass", "scss"],
|
|
106
|
-
json: ["json"]
|
|
82
|
+
function getTasks(options) {
|
|
83
|
+
const { root: cwd, weappTailwindcssOptions, outDir, src: srcBase, extensions, exclude, include } = options;
|
|
84
|
+
const globsSet = /* @__PURE__ */ new Set();
|
|
85
|
+
const base = srcBase ? srcBase + "/" : "";
|
|
86
|
+
function globsSetAdd(...value) {
|
|
87
|
+
for (const v of value) {
|
|
88
|
+
if (Array.isArray(v)) {
|
|
89
|
+
for (const vv of v) {
|
|
90
|
+
globsSet.add(vv);
|
|
91
|
+
}
|
|
92
|
+
} else {
|
|
93
|
+
globsSet.add(v);
|
|
94
|
+
}
|
|
107
95
|
}
|
|
108
|
-
});
|
|
109
|
-
if (clean) {
|
|
110
|
-
const { deleteAsync } = await import('del');
|
|
111
|
-
const patterns = [outDir + "/**"];
|
|
112
|
-
await deleteAsync(patterns, { cwd, ignore: defaultNodeModulesDirs });
|
|
113
96
|
}
|
|
114
|
-
await fs.ensureDir(path__default.resolve(cwd, outDir));
|
|
115
|
-
const base = srcBase ? srcBase + "/" : "";
|
|
116
97
|
function getGlobs(type) {
|
|
117
98
|
const globs = [];
|
|
118
99
|
if (typeof include === "function") {
|
|
@@ -130,8 +111,11 @@ async function build(options) {
|
|
|
130
111
|
function getJsTasks() {
|
|
131
112
|
const assetType = AssetType.JavaScript;
|
|
132
113
|
const globs = getGlobs(assetType);
|
|
114
|
+
globsSetAdd(globs);
|
|
133
115
|
return extensions[assetType].map((x) => {
|
|
134
|
-
|
|
116
|
+
const src = `${base}**/*.${x}`;
|
|
117
|
+
globsSetAdd(src);
|
|
118
|
+
return () => gulp__default.src([src, ...globs], { cwd }).pipe(
|
|
135
119
|
transformJs({
|
|
136
120
|
babelParserOptions: x === "ts" ? {
|
|
137
121
|
plugins: ["typescript"]
|
|
@@ -147,8 +131,11 @@ async function build(options) {
|
|
|
147
131
|
function getJsonTasks() {
|
|
148
132
|
const assetType = AssetType.Json;
|
|
149
133
|
const globs = getGlobs(assetType);
|
|
134
|
+
globsSetAdd(globs);
|
|
150
135
|
return extensions[assetType].map((x) => {
|
|
151
|
-
|
|
136
|
+
const src = `${base}**/*.${x}`;
|
|
137
|
+
globsSetAdd(src);
|
|
138
|
+
return () => gulp__default.src([src, ...globs], { cwd }).pipe(
|
|
152
139
|
gulp__default.dest(outDir, {
|
|
153
140
|
cwd
|
|
154
141
|
})
|
|
@@ -158,8 +145,11 @@ async function build(options) {
|
|
|
158
145
|
function getCssTasks() {
|
|
159
146
|
const assetType = AssetType.Css;
|
|
160
147
|
const globs = getGlobs(assetType);
|
|
148
|
+
globsSetAdd(globs);
|
|
161
149
|
return extensions[assetType].map((x) => {
|
|
162
|
-
|
|
150
|
+
const src = `${base}**/*.${x}`;
|
|
151
|
+
globsSetAdd(src);
|
|
152
|
+
return () => gulp__default.src([src, ...globs], { cwd }).pipe(transformWxss()).pipe(
|
|
163
153
|
gulp__default.dest(outDir, {
|
|
164
154
|
cwd
|
|
165
155
|
})
|
|
@@ -169,8 +159,11 @@ async function build(options) {
|
|
|
169
159
|
function getHtmlTasks() {
|
|
170
160
|
const assetType = AssetType.Html;
|
|
171
161
|
const globs = getGlobs(assetType);
|
|
162
|
+
globsSetAdd(globs);
|
|
172
163
|
return extensions[assetType].map((x) => {
|
|
173
|
-
|
|
164
|
+
const src = `${base}**/*.${x}`;
|
|
165
|
+
globsSetAdd(src);
|
|
166
|
+
return () => gulp__default.src([src, ...globs], { cwd }).pipe(transformWxml()).pipe(
|
|
174
167
|
gulp__default.dest(outDir, {
|
|
175
168
|
cwd
|
|
176
169
|
})
|
|
@@ -179,27 +172,468 @@ async function build(options) {
|
|
|
179
172
|
}
|
|
180
173
|
function copyOthers() {
|
|
181
174
|
if (Array.isArray(include)) {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
).pipe(
|
|
175
|
+
const globs = include.map((x) => {
|
|
176
|
+
return `${base}${x}`;
|
|
177
|
+
});
|
|
178
|
+
globsSetAdd(globs);
|
|
179
|
+
return gulp__default.src(globs, { cwd }).pipe(
|
|
188
180
|
gulp__default.dest(outDir, {
|
|
189
181
|
cwd
|
|
190
182
|
})
|
|
191
183
|
);
|
|
192
184
|
}
|
|
193
185
|
}
|
|
186
|
+
return {
|
|
187
|
+
getGlobs,
|
|
188
|
+
getJsTasks,
|
|
189
|
+
getJsonTasks,
|
|
190
|
+
getCssTasks,
|
|
191
|
+
getHtmlTasks,
|
|
192
|
+
copyOthers,
|
|
193
|
+
globsSet
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const defaultJavascriptExtensions = ["js"];
|
|
198
|
+
const defaultTypescriptExtensions = ["ts"];
|
|
199
|
+
const defaultWxsExtensions = ["wxs"];
|
|
200
|
+
const defaultNodeModulesDirs = [
|
|
201
|
+
"**/node_modules/**",
|
|
202
|
+
"**/miniprogram_npm/**",
|
|
203
|
+
"**/project.config.json/**",
|
|
204
|
+
"**/project.private.config.json/**",
|
|
205
|
+
"**/package.json/**",
|
|
206
|
+
"postcss.config.js",
|
|
207
|
+
"tailwind.config.js"
|
|
208
|
+
];
|
|
209
|
+
function createBuilder(options) {
|
|
210
|
+
const {
|
|
211
|
+
root: cwd,
|
|
212
|
+
weappTailwindcssOptions,
|
|
213
|
+
outDir,
|
|
214
|
+
src: srcBase,
|
|
215
|
+
clean,
|
|
216
|
+
extensions,
|
|
217
|
+
exclude,
|
|
218
|
+
include,
|
|
219
|
+
watchOptions
|
|
220
|
+
} = defu(options, {
|
|
221
|
+
outDir: "dist",
|
|
222
|
+
weappTailwindcssOptions: {},
|
|
223
|
+
clean: true,
|
|
224
|
+
src: "",
|
|
225
|
+
exclude: [...defaultNodeModulesDirs],
|
|
226
|
+
extensions: {
|
|
227
|
+
javascript: [...defaultJavascriptExtensions, ...defaultTypescriptExtensions, ...defaultWxsExtensions],
|
|
228
|
+
html: ["wxml"],
|
|
229
|
+
css: ["wxss", "less", "sass", "scss"],
|
|
230
|
+
json: ["json"]
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
const { copyOthers, getCssTasks, getHtmlTasks, getJsTasks, getJsonTasks, globsSet } = getTasks({
|
|
234
|
+
root: cwd,
|
|
235
|
+
weappTailwindcssOptions,
|
|
236
|
+
outDir,
|
|
237
|
+
src: srcBase,
|
|
238
|
+
clean,
|
|
239
|
+
extensions,
|
|
240
|
+
exclude,
|
|
241
|
+
include,
|
|
242
|
+
watchOptions
|
|
243
|
+
});
|
|
194
244
|
const tasks = [...getJsTasks(), ...getJsonTasks(), ...getCssTasks(), ...getHtmlTasks(), copyOthers];
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
245
|
+
return {
|
|
246
|
+
watcher: void 0,
|
|
247
|
+
async build() {
|
|
248
|
+
if (clean) {
|
|
249
|
+
const { deleteAsync } = await import('del');
|
|
250
|
+
const patterns = [outDir + "/**"];
|
|
251
|
+
await deleteAsync(patterns, { cwd, ignore: defaultNodeModulesDirs });
|
|
252
|
+
}
|
|
253
|
+
fs.ensureDirSync(path__default.resolve(cwd, outDir));
|
|
254
|
+
for (const task of tasks) {
|
|
255
|
+
const s = task();
|
|
256
|
+
if (s) {
|
|
257
|
+
await new Promise((resolve, reject) => s.on("finish", resolve).on("error", reject));
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return this;
|
|
261
|
+
},
|
|
262
|
+
watch() {
|
|
263
|
+
fs.ensureDirSync(path__default.resolve(cwd, outDir));
|
|
264
|
+
const watcher = gulp__default.watch([...globsSet], watchOptions, gulp__default.parallel(...tasks));
|
|
265
|
+
watcher.on("change", function(path2) {
|
|
266
|
+
console.log(`File ${path2} was changed`);
|
|
267
|
+
});
|
|
268
|
+
watcher.on("add", function(path2) {
|
|
269
|
+
console.log(`File ${path2} was added`);
|
|
270
|
+
});
|
|
271
|
+
watcher.on("unlink", function(path2) {
|
|
272
|
+
console.log(`File ${path2} was removed`);
|
|
273
|
+
});
|
|
274
|
+
this.watcher = watcher;
|
|
275
|
+
return this;
|
|
276
|
+
},
|
|
277
|
+
globsSet
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
function build(options) {
|
|
281
|
+
const builder = createBuilder(options);
|
|
282
|
+
return builder.build();
|
|
283
|
+
}
|
|
284
|
+
function watch(options) {
|
|
285
|
+
const builder = createBuilder(options);
|
|
286
|
+
return builder.watch();
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
function getDefaultExportFromCjs (x) {
|
|
290
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/*!
|
|
294
|
+
* is-primitive <https://github.com/jonschlinkert/is-primitive>
|
|
295
|
+
*
|
|
296
|
+
* Copyright (c) 2014-present, Jon Schlinkert.
|
|
297
|
+
* Released under the MIT License.
|
|
298
|
+
*/
|
|
299
|
+
|
|
300
|
+
var isPrimitive$1 = function isPrimitive(val) {
|
|
301
|
+
if (typeof val === 'object') {
|
|
302
|
+
return val === null;
|
|
303
|
+
}
|
|
304
|
+
return typeof val !== 'function';
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
/*!
|
|
308
|
+
* isobject <https://github.com/jonschlinkert/isobject>
|
|
309
|
+
*
|
|
310
|
+
* Copyright (c) 2014-2017, Jon Schlinkert.
|
|
311
|
+
* Released under the MIT License.
|
|
312
|
+
*/
|
|
313
|
+
|
|
314
|
+
var isobject = function isObject(val) {
|
|
315
|
+
return val != null && typeof val === 'object' && Array.isArray(val) === false;
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
/*!
|
|
319
|
+
* is-plain-object <https://github.com/jonschlinkert/is-plain-object>
|
|
320
|
+
*
|
|
321
|
+
* Copyright (c) 2014-2017, Jon Schlinkert.
|
|
322
|
+
* Released under the MIT License.
|
|
323
|
+
*/
|
|
324
|
+
|
|
325
|
+
var isObject$2 = isobject;
|
|
326
|
+
|
|
327
|
+
function isObjectObject(o) {
|
|
328
|
+
return isObject$2(o) === true
|
|
329
|
+
&& Object.prototype.toString.call(o) === '[object Object]';
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
var isPlainObject$1 = function isPlainObject(o) {
|
|
333
|
+
var ctor,prot;
|
|
334
|
+
|
|
335
|
+
if (isObjectObject(o) === false) return false;
|
|
336
|
+
|
|
337
|
+
// If has modified constructor
|
|
338
|
+
ctor = o.constructor;
|
|
339
|
+
if (typeof ctor !== 'function') return false;
|
|
340
|
+
|
|
341
|
+
// If has modified prototype
|
|
342
|
+
prot = ctor.prototype;
|
|
343
|
+
if (isObjectObject(prot) === false) return false;
|
|
344
|
+
|
|
345
|
+
// If constructor does not have an Object-specific method
|
|
346
|
+
if (prot.hasOwnProperty('isPrototypeOf') === false) {
|
|
347
|
+
return false;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
// Most likely a plain Object
|
|
351
|
+
return true;
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
/*!
|
|
355
|
+
* set-value <https://github.com/jonschlinkert/set-value>
|
|
356
|
+
*
|
|
357
|
+
* Copyright (c) Jon Schlinkert (https://github.com/jonschlinkert).
|
|
358
|
+
* Released under the MIT License.
|
|
359
|
+
*/
|
|
360
|
+
|
|
361
|
+
const { deleteProperty } = Reflect;
|
|
362
|
+
const isPrimitive = isPrimitive$1;
|
|
363
|
+
const isPlainObject = isPlainObject$1;
|
|
364
|
+
|
|
365
|
+
const isObject$1 = value => {
|
|
366
|
+
return (typeof value === 'object' && value !== null) || typeof value === 'function';
|
|
367
|
+
};
|
|
368
|
+
|
|
369
|
+
const isUnsafeKey = key => {
|
|
370
|
+
return key === '__proto__' || key === 'constructor' || key === 'prototype';
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
const validateKey = key => {
|
|
374
|
+
if (!isPrimitive(key)) {
|
|
375
|
+
throw new TypeError('Object keys must be strings or symbols');
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
if (isUnsafeKey(key)) {
|
|
379
|
+
throw new Error(`Cannot set unsafe key: "${key}"`);
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
|
|
383
|
+
const toStringKey = input => {
|
|
384
|
+
return Array.isArray(input) ? input.flat().map(String).join(',') : input;
|
|
385
|
+
};
|
|
386
|
+
|
|
387
|
+
const createMemoKey = (input, options) => {
|
|
388
|
+
if (typeof input !== 'string' || !options) return input;
|
|
389
|
+
let key = input + ';';
|
|
390
|
+
if (options.arrays !== undefined) key += `arrays=${options.arrays};`;
|
|
391
|
+
if (options.separator !== undefined) key += `separator=${options.separator};`;
|
|
392
|
+
if (options.split !== undefined) key += `split=${options.split};`;
|
|
393
|
+
if (options.merge !== undefined) key += `merge=${options.merge};`;
|
|
394
|
+
if (options.preservePaths !== undefined) key += `preservePaths=${options.preservePaths};`;
|
|
395
|
+
return key;
|
|
396
|
+
};
|
|
397
|
+
|
|
398
|
+
const memoize = (input, options, fn) => {
|
|
399
|
+
const key = toStringKey(options ? createMemoKey(input, options) : input);
|
|
400
|
+
validateKey(key);
|
|
401
|
+
|
|
402
|
+
const value = setValue.cache.get(key) || fn();
|
|
403
|
+
setValue.cache.set(key, value);
|
|
404
|
+
return value;
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
const splitString = (input, options = {}) => {
|
|
408
|
+
const sep = options.separator || '.';
|
|
409
|
+
const preserve = sep === '/' ? false : options.preservePaths;
|
|
410
|
+
|
|
411
|
+
if (typeof input === 'string' && preserve !== false && /\//.test(input)) {
|
|
412
|
+
return [input];
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
const parts = [];
|
|
416
|
+
let part = '';
|
|
417
|
+
|
|
418
|
+
const push = part => {
|
|
419
|
+
let number;
|
|
420
|
+
if (part.trim() !== '' && Number.isInteger((number = Number(part)))) {
|
|
421
|
+
parts.push(number);
|
|
422
|
+
} else {
|
|
423
|
+
parts.push(part);
|
|
424
|
+
}
|
|
425
|
+
};
|
|
426
|
+
|
|
427
|
+
for (let i = 0; i < input.length; i++) {
|
|
428
|
+
const value = input[i];
|
|
429
|
+
|
|
430
|
+
if (value === '\\') {
|
|
431
|
+
part += input[++i];
|
|
432
|
+
continue;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
if (value === sep) {
|
|
436
|
+
push(part);
|
|
437
|
+
part = '';
|
|
438
|
+
continue;
|
|
199
439
|
}
|
|
440
|
+
|
|
441
|
+
part += value;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
if (part) {
|
|
445
|
+
push(part);
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
return parts;
|
|
449
|
+
};
|
|
450
|
+
|
|
451
|
+
const split$1 = (input, options) => {
|
|
452
|
+
if (options && typeof options.split === 'function') return options.split(input);
|
|
453
|
+
if (typeof input === 'symbol') return [input];
|
|
454
|
+
if (Array.isArray(input)) return input;
|
|
455
|
+
return memoize(input, options, () => splitString(input, options));
|
|
456
|
+
};
|
|
457
|
+
|
|
458
|
+
const assignProp = (obj, prop, value, options) => {
|
|
459
|
+
validateKey(prop);
|
|
460
|
+
|
|
461
|
+
// Delete property when "value" is undefined
|
|
462
|
+
if (value === undefined) {
|
|
463
|
+
deleteProperty(obj, prop);
|
|
464
|
+
|
|
465
|
+
} else if (options && options.merge) {
|
|
466
|
+
const merge = options.merge === 'function' ? options.merge : Object.assign;
|
|
467
|
+
|
|
468
|
+
// Only merge plain objects
|
|
469
|
+
if (merge && isPlainObject(obj[prop]) && isPlainObject(value)) {
|
|
470
|
+
obj[prop] = merge(obj[prop], value);
|
|
471
|
+
} else {
|
|
472
|
+
obj[prop] = value;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
} else {
|
|
476
|
+
obj[prop] = value;
|
|
200
477
|
}
|
|
478
|
+
|
|
479
|
+
return obj;
|
|
480
|
+
};
|
|
481
|
+
|
|
482
|
+
const setValue = (target, path, value, options) => {
|
|
483
|
+
if (!path || !isObject$1(target)) return target;
|
|
484
|
+
|
|
485
|
+
const keys = split$1(path, options);
|
|
486
|
+
let obj = target;
|
|
487
|
+
|
|
488
|
+
for (let i = 0; i < keys.length; i++) {
|
|
489
|
+
const key = keys[i];
|
|
490
|
+
const next = keys[i + 1];
|
|
491
|
+
|
|
492
|
+
validateKey(key);
|
|
493
|
+
|
|
494
|
+
if (next === undefined) {
|
|
495
|
+
assignProp(obj, key, value, options);
|
|
496
|
+
break;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
if (typeof next === 'number' && !Array.isArray(obj[key])) {
|
|
500
|
+
obj = obj[key] = [];
|
|
501
|
+
continue;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
if (!isObject$1(obj[key])) {
|
|
505
|
+
obj[key] = {};
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
obj = obj[key];
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
return target;
|
|
512
|
+
};
|
|
513
|
+
|
|
514
|
+
setValue.split = split$1;
|
|
515
|
+
setValue.cache = new Map();
|
|
516
|
+
setValue.clear = () => {
|
|
517
|
+
setValue.cache = new Map();
|
|
518
|
+
};
|
|
519
|
+
|
|
520
|
+
var setValue_1 = setValue;
|
|
521
|
+
|
|
522
|
+
const set = /*@__PURE__*/getDefaultExportFromCjs(setValue_1);
|
|
523
|
+
|
|
524
|
+
/*!
|
|
525
|
+
* get-value <https://github.com/jonschlinkert/get-value>
|
|
526
|
+
*
|
|
527
|
+
* Copyright (c) 2014-2018, Jon Schlinkert.
|
|
528
|
+
* Released under the MIT License.
|
|
529
|
+
*/
|
|
530
|
+
|
|
531
|
+
const isObject = isobject;
|
|
532
|
+
|
|
533
|
+
var getValue = function(target, path, options) {
|
|
534
|
+
if (!isObject(options)) {
|
|
535
|
+
options = { default: options };
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
if (!isValidObject(target)) {
|
|
539
|
+
return typeof options.default !== 'undefined' ? options.default : target;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
if (typeof path === 'number') {
|
|
543
|
+
path = String(path);
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
const isArray = Array.isArray(path);
|
|
547
|
+
const isString = typeof path === 'string';
|
|
548
|
+
const splitChar = options.separator || '.';
|
|
549
|
+
const joinChar = options.joinChar || (typeof splitChar === 'string' ? splitChar : '.');
|
|
550
|
+
|
|
551
|
+
if (!isString && !isArray) {
|
|
552
|
+
return target;
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
if (isString && path in target) {
|
|
556
|
+
return isValid(path, target, options) ? target[path] : options.default;
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
let segs = isArray ? path : split(path, splitChar, options);
|
|
560
|
+
let len = segs.length;
|
|
561
|
+
let idx = 0;
|
|
562
|
+
|
|
563
|
+
do {
|
|
564
|
+
let prop = segs[idx];
|
|
565
|
+
if (typeof prop === 'number') {
|
|
566
|
+
prop = String(prop);
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
while (prop && prop.slice(-1) === '\\') {
|
|
570
|
+
prop = join([prop.slice(0, -1), segs[++idx] || ''], joinChar, options);
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
if (prop in target) {
|
|
574
|
+
if (!isValid(prop, target, options)) {
|
|
575
|
+
return options.default;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
target = target[prop];
|
|
579
|
+
} else {
|
|
580
|
+
let hasProp = false;
|
|
581
|
+
let n = idx + 1;
|
|
582
|
+
|
|
583
|
+
while (n < len) {
|
|
584
|
+
prop = join([prop, segs[n++]], joinChar, options);
|
|
585
|
+
|
|
586
|
+
if ((hasProp = prop in target)) {
|
|
587
|
+
if (!isValid(prop, target, options)) {
|
|
588
|
+
return options.default;
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
target = target[prop];
|
|
592
|
+
idx = n - 1;
|
|
593
|
+
break;
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
if (!hasProp) {
|
|
598
|
+
return options.default;
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
} while (++idx < len && isValidObject(target));
|
|
602
|
+
|
|
603
|
+
if (idx === len) {
|
|
604
|
+
return target;
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
return options.default;
|
|
608
|
+
};
|
|
609
|
+
|
|
610
|
+
function join(segs, joinChar, options) {
|
|
611
|
+
if (typeof options.join === 'function') {
|
|
612
|
+
return options.join(segs);
|
|
613
|
+
}
|
|
614
|
+
return segs[0] + joinChar + segs[1];
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
function split(path, splitChar, options) {
|
|
618
|
+
if (typeof options.split === 'function') {
|
|
619
|
+
return options.split(path);
|
|
620
|
+
}
|
|
621
|
+
return path.split(splitChar);
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
function isValid(key, target, options) {
|
|
625
|
+
if (typeof options.isValid === 'function') {
|
|
626
|
+
return options.isValid(key, target);
|
|
627
|
+
}
|
|
628
|
+
return true;
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
function isValidObject(val) {
|
|
632
|
+
return isObject(val) || Array.isArray(val) || typeof val === 'function';
|
|
201
633
|
}
|
|
202
634
|
|
|
635
|
+
const get = /*@__PURE__*/getDefaultExportFromCjs(getValue);
|
|
636
|
+
|
|
203
637
|
function createConfigLoader(root) {
|
|
204
638
|
const explorer = cosmiconfig.cosmiconfigSync("weapp-tw");
|
|
205
639
|
function search(searchFrom = root) {
|
|
@@ -234,10 +668,10 @@ function updateProjectConfig(options) {
|
|
|
234
668
|
if (fs__default.existsSync(projectConfigPath)) {
|
|
235
669
|
try {
|
|
236
670
|
const projectConfig = fs__default.readJSONSync(projectConfigPath);
|
|
237
|
-
projectConfig
|
|
238
|
-
projectConfig
|
|
239
|
-
projectConfig
|
|
240
|
-
if (Array.isArray(projectConfig
|
|
671
|
+
set(projectConfig, "miniprogramRoot", "dist/");
|
|
672
|
+
set(projectConfig, "srcMiniprogramRoot", "dist/");
|
|
673
|
+
set(projectConfig, "setting.packNpmManually", true);
|
|
674
|
+
if (Array.isArray(get(projectConfig, "setting.packNpmRelationList"))) {
|
|
241
675
|
const x = projectConfig.setting.packNpmRelationList.find((x2) => x2.packageJsonPath === "./package.json" && x2.miniprogramNpmDistDir === "./dist");
|
|
242
676
|
if (!x) {
|
|
243
677
|
projectConfig.setting.packNpmRelationList.push({
|
|
@@ -246,12 +680,12 @@ function updateProjectConfig(options) {
|
|
|
246
680
|
});
|
|
247
681
|
}
|
|
248
682
|
} else {
|
|
249
|
-
projectConfig
|
|
683
|
+
set(projectConfig, "setting.packNpmRelationList", [
|
|
250
684
|
{
|
|
251
685
|
packageJsonPath: "./package.json",
|
|
252
686
|
miniprogramNpmDistDir: "./dist"
|
|
253
687
|
}
|
|
254
|
-
];
|
|
688
|
+
]);
|
|
255
689
|
}
|
|
256
690
|
fs__default.outputJSONSync(dest ?? projectConfigPath, projectConfig, {
|
|
257
691
|
spaces: 2
|
|
@@ -264,6 +698,22 @@ function updateProjectConfig(options) {
|
|
|
264
698
|
console.warn(`\u2728 \u6CA1\u6709\u627E\u5230 ${projectConfigFilename} \u6587\u4EF6!`);
|
|
265
699
|
}
|
|
266
700
|
}
|
|
701
|
+
function updatePackageJson(options) {
|
|
702
|
+
const { root, dest } = options;
|
|
703
|
+
const packageJsonFilename = "package.json";
|
|
704
|
+
const packageJsonPath = path__default.resolve(root, packageJsonFilename);
|
|
705
|
+
if (fs__default.existsSync(packageJsonPath)) {
|
|
706
|
+
try {
|
|
707
|
+
const packageJson = fs__default.readJSONSync(packageJsonPath);
|
|
708
|
+
set(packageJson, "scripts.dev", "weapp-tw dev");
|
|
709
|
+
set(packageJson, "scripts.build", "weapp-tw build");
|
|
710
|
+
fs__default.outputJSONSync(dest ?? packageJsonPath, packageJson, {
|
|
711
|
+
spaces: 2
|
|
712
|
+
});
|
|
713
|
+
} catch {
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
}
|
|
267
717
|
function initConfig(options) {
|
|
268
718
|
const { lang, root } = defu(options, { lang: "js", root: process.cwd() });
|
|
269
719
|
const configFilename = `weapp-tw.config.${lang ?? "js"}`;
|
|
@@ -289,6 +739,7 @@ module.exports = {}
|
|
|
289
739
|
}
|
|
290
740
|
console.log(`\u2728 ${configFilename} \u914D\u7F6E\u6587\u4EF6\uFF0C\u521D\u59CB\u5316\u6210\u529F!`);
|
|
291
741
|
updateProjectConfig({ root });
|
|
742
|
+
updatePackageJson({ root });
|
|
292
743
|
return configPath;
|
|
293
744
|
}
|
|
294
745
|
|
|
@@ -298,6 +749,17 @@ function createCli() {
|
|
|
298
749
|
const configLoader = createConfigLoader(cwd);
|
|
299
750
|
const userDefinedConfig = configLoader.search(cwd);
|
|
300
751
|
program.command("dev").alias("serve").action(async () => {
|
|
752
|
+
const postcssOptions = await loadPostcssConfig__default({
|
|
753
|
+
cwd
|
|
754
|
+
});
|
|
755
|
+
await watch(
|
|
756
|
+
defu(userDefinedConfig?.config, {
|
|
757
|
+
root: cwd,
|
|
758
|
+
weappTailwindcssOptions: {
|
|
759
|
+
postcssOptions
|
|
760
|
+
}
|
|
761
|
+
})
|
|
762
|
+
);
|
|
301
763
|
});
|
|
302
764
|
program.command("build").action(async () => {
|
|
303
765
|
const postcssOptions = await loadPostcssConfig__default({
|
|
@@ -320,10 +782,9 @@ function createCli() {
|
|
|
320
782
|
return program;
|
|
321
783
|
}
|
|
322
784
|
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
785
|
+
exports.build = build;
|
|
786
|
+
exports.createBuilder = createBuilder;
|
|
326
787
|
exports.createCli = createCli;
|
|
327
788
|
exports.createConfigLoader = createConfigLoader;
|
|
328
|
-
exports.createWatcher = createWatcher;
|
|
329
789
|
exports.defineConfig = defineConfig;
|
|
790
|
+
exports.watch = watch;
|