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