@weapp-tailwindcss/cli 0.0.0-alpha.0 → 0.0.0-alpha.1
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 +492 -61
- package/dist/index.d.cts +31 -3
- package/dist/index.d.mts +31 -3
- package/dist/index.d.ts +31 -3
- package/dist/index.mjs +490 -60
- 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 fs, { ensureDir } from 'fs-extra';
|
|
4
5
|
import { createPlugins } from 'weapp-tailwindcss/gulp';
|
|
5
6
|
import gulp from 'gulp';
|
|
6
|
-
import fs, { ensureDir } from 'fs-extra';
|
|
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,450 @@ 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
|
+
} = defu(options, {
|
|
211
|
+
outDir: "dist",
|
|
212
|
+
weappTailwindcssOptions: {},
|
|
213
|
+
clean: true,
|
|
214
|
+
src: "",
|
|
215
|
+
exclude: [...defaultNodeModulesDirs],
|
|
216
|
+
extensions: {
|
|
217
|
+
javascript: [...defaultJavascriptExtensions, ...defaultTypescriptExtensions, ...defaultWxsExtensions],
|
|
218
|
+
html: ["wxml"],
|
|
219
|
+
css: ["wxss", "less", "sass", "scss"],
|
|
220
|
+
json: ["json"]
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
const { copyOthers, getCssTasks, getHtmlTasks, getJsTasks, getJsonTasks, globsSet } = getTasks({
|
|
224
|
+
root: cwd,
|
|
225
|
+
weappTailwindcssOptions,
|
|
226
|
+
outDir,
|
|
227
|
+
src: srcBase,
|
|
228
|
+
clean,
|
|
229
|
+
extensions,
|
|
230
|
+
exclude,
|
|
231
|
+
include
|
|
232
|
+
});
|
|
185
233
|
const tasks = [...getJsTasks(), ...getJsonTasks(), ...getCssTasks(), ...getHtmlTasks(), copyOthers];
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
234
|
+
return {
|
|
235
|
+
async build() {
|
|
236
|
+
if (clean) {
|
|
237
|
+
const { deleteAsync } = await import('del');
|
|
238
|
+
const patterns = [outDir + "/**"];
|
|
239
|
+
await deleteAsync(patterns, { cwd, ignore: defaultNodeModulesDirs });
|
|
240
|
+
}
|
|
241
|
+
await ensureDir(path.resolve(cwd, outDir));
|
|
242
|
+
for (const task of tasks) {
|
|
243
|
+
const s = task();
|
|
244
|
+
if (s) {
|
|
245
|
+
await new Promise((resolve, reject) => s.on("finish", resolve).on("error", reject));
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
return this;
|
|
249
|
+
},
|
|
250
|
+
async watch() {
|
|
251
|
+
await ensureDir(path.resolve(cwd, outDir));
|
|
252
|
+
return this;
|
|
253
|
+
},
|
|
254
|
+
globsSet
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
function build(options) {
|
|
258
|
+
const builder = createBuilder(options);
|
|
259
|
+
return builder.build();
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function getDefaultExportFromCjs (x) {
|
|
263
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/*!
|
|
267
|
+
* is-primitive <https://github.com/jonschlinkert/is-primitive>
|
|
268
|
+
*
|
|
269
|
+
* Copyright (c) 2014-present, Jon Schlinkert.
|
|
270
|
+
* Released under the MIT License.
|
|
271
|
+
*/
|
|
272
|
+
|
|
273
|
+
var isPrimitive$1 = function isPrimitive(val) {
|
|
274
|
+
if (typeof val === 'object') {
|
|
275
|
+
return val === null;
|
|
276
|
+
}
|
|
277
|
+
return typeof val !== 'function';
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
/*!
|
|
281
|
+
* isobject <https://github.com/jonschlinkert/isobject>
|
|
282
|
+
*
|
|
283
|
+
* Copyright (c) 2014-2017, Jon Schlinkert.
|
|
284
|
+
* Released under the MIT License.
|
|
285
|
+
*/
|
|
286
|
+
|
|
287
|
+
var isobject = function isObject(val) {
|
|
288
|
+
return val != null && typeof val === 'object' && Array.isArray(val) === false;
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
/*!
|
|
292
|
+
* is-plain-object <https://github.com/jonschlinkert/is-plain-object>
|
|
293
|
+
*
|
|
294
|
+
* Copyright (c) 2014-2017, Jon Schlinkert.
|
|
295
|
+
* Released under the MIT License.
|
|
296
|
+
*/
|
|
297
|
+
|
|
298
|
+
var isObject$2 = isobject;
|
|
299
|
+
|
|
300
|
+
function isObjectObject(o) {
|
|
301
|
+
return isObject$2(o) === true
|
|
302
|
+
&& Object.prototype.toString.call(o) === '[object Object]';
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
var isPlainObject$1 = function isPlainObject(o) {
|
|
306
|
+
var ctor,prot;
|
|
307
|
+
|
|
308
|
+
if (isObjectObject(o) === false) return false;
|
|
309
|
+
|
|
310
|
+
// If has modified constructor
|
|
311
|
+
ctor = o.constructor;
|
|
312
|
+
if (typeof ctor !== 'function') return false;
|
|
313
|
+
|
|
314
|
+
// If has modified prototype
|
|
315
|
+
prot = ctor.prototype;
|
|
316
|
+
if (isObjectObject(prot) === false) return false;
|
|
317
|
+
|
|
318
|
+
// If constructor does not have an Object-specific method
|
|
319
|
+
if (prot.hasOwnProperty('isPrototypeOf') === false) {
|
|
320
|
+
return false;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// Most likely a plain Object
|
|
324
|
+
return true;
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
/*!
|
|
328
|
+
* set-value <https://github.com/jonschlinkert/set-value>
|
|
329
|
+
*
|
|
330
|
+
* Copyright (c) Jon Schlinkert (https://github.com/jonschlinkert).
|
|
331
|
+
* Released under the MIT License.
|
|
332
|
+
*/
|
|
333
|
+
|
|
334
|
+
const { deleteProperty } = Reflect;
|
|
335
|
+
const isPrimitive = isPrimitive$1;
|
|
336
|
+
const isPlainObject = isPlainObject$1;
|
|
337
|
+
|
|
338
|
+
const isObject$1 = value => {
|
|
339
|
+
return (typeof value === 'object' && value !== null) || typeof value === 'function';
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
const isUnsafeKey = key => {
|
|
343
|
+
return key === '__proto__' || key === 'constructor' || key === 'prototype';
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
const validateKey = key => {
|
|
347
|
+
if (!isPrimitive(key)) {
|
|
348
|
+
throw new TypeError('Object keys must be strings or symbols');
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
if (isUnsafeKey(key)) {
|
|
352
|
+
throw new Error(`Cannot set unsafe key: "${key}"`);
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
const toStringKey = input => {
|
|
357
|
+
return Array.isArray(input) ? input.flat().map(String).join(',') : input;
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
const createMemoKey = (input, options) => {
|
|
361
|
+
if (typeof input !== 'string' || !options) return input;
|
|
362
|
+
let key = input + ';';
|
|
363
|
+
if (options.arrays !== undefined) key += `arrays=${options.arrays};`;
|
|
364
|
+
if (options.separator !== undefined) key += `separator=${options.separator};`;
|
|
365
|
+
if (options.split !== undefined) key += `split=${options.split};`;
|
|
366
|
+
if (options.merge !== undefined) key += `merge=${options.merge};`;
|
|
367
|
+
if (options.preservePaths !== undefined) key += `preservePaths=${options.preservePaths};`;
|
|
368
|
+
return key;
|
|
369
|
+
};
|
|
370
|
+
|
|
371
|
+
const memoize = (input, options, fn) => {
|
|
372
|
+
const key = toStringKey(options ? createMemoKey(input, options) : input);
|
|
373
|
+
validateKey(key);
|
|
374
|
+
|
|
375
|
+
const value = setValue.cache.get(key) || fn();
|
|
376
|
+
setValue.cache.set(key, value);
|
|
377
|
+
return value;
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
const splitString = (input, options = {}) => {
|
|
381
|
+
const sep = options.separator || '.';
|
|
382
|
+
const preserve = sep === '/' ? false : options.preservePaths;
|
|
383
|
+
|
|
384
|
+
if (typeof input === 'string' && preserve !== false && /\//.test(input)) {
|
|
385
|
+
return [input];
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
const parts = [];
|
|
389
|
+
let part = '';
|
|
390
|
+
|
|
391
|
+
const push = part => {
|
|
392
|
+
let number;
|
|
393
|
+
if (part.trim() !== '' && Number.isInteger((number = Number(part)))) {
|
|
394
|
+
parts.push(number);
|
|
395
|
+
} else {
|
|
396
|
+
parts.push(part);
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
|
|
400
|
+
for (let i = 0; i < input.length; i++) {
|
|
401
|
+
const value = input[i];
|
|
402
|
+
|
|
403
|
+
if (value === '\\') {
|
|
404
|
+
part += input[++i];
|
|
405
|
+
continue;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
if (value === sep) {
|
|
409
|
+
push(part);
|
|
410
|
+
part = '';
|
|
411
|
+
continue;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
part += value;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
if (part) {
|
|
418
|
+
push(part);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
return parts;
|
|
422
|
+
};
|
|
423
|
+
|
|
424
|
+
const split$1 = (input, options) => {
|
|
425
|
+
if (options && typeof options.split === 'function') return options.split(input);
|
|
426
|
+
if (typeof input === 'symbol') return [input];
|
|
427
|
+
if (Array.isArray(input)) return input;
|
|
428
|
+
return memoize(input, options, () => splitString(input, options));
|
|
429
|
+
};
|
|
430
|
+
|
|
431
|
+
const assignProp = (obj, prop, value, options) => {
|
|
432
|
+
validateKey(prop);
|
|
433
|
+
|
|
434
|
+
// Delete property when "value" is undefined
|
|
435
|
+
if (value === undefined) {
|
|
436
|
+
deleteProperty(obj, prop);
|
|
437
|
+
|
|
438
|
+
} else if (options && options.merge) {
|
|
439
|
+
const merge = options.merge === 'function' ? options.merge : Object.assign;
|
|
440
|
+
|
|
441
|
+
// Only merge plain objects
|
|
442
|
+
if (merge && isPlainObject(obj[prop]) && isPlainObject(value)) {
|
|
443
|
+
obj[prop] = merge(obj[prop], value);
|
|
444
|
+
} else {
|
|
445
|
+
obj[prop] = value;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
} else {
|
|
449
|
+
obj[prop] = value;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
return obj;
|
|
453
|
+
};
|
|
454
|
+
|
|
455
|
+
const setValue = (target, path, value, options) => {
|
|
456
|
+
if (!path || !isObject$1(target)) return target;
|
|
457
|
+
|
|
458
|
+
const keys = split$1(path, options);
|
|
459
|
+
let obj = target;
|
|
460
|
+
|
|
461
|
+
for (let i = 0; i < keys.length; i++) {
|
|
462
|
+
const key = keys[i];
|
|
463
|
+
const next = keys[i + 1];
|
|
464
|
+
|
|
465
|
+
validateKey(key);
|
|
466
|
+
|
|
467
|
+
if (next === undefined) {
|
|
468
|
+
assignProp(obj, key, value, options);
|
|
469
|
+
break;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
if (typeof next === 'number' && !Array.isArray(obj[key])) {
|
|
473
|
+
obj = obj[key] = [];
|
|
474
|
+
continue;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
if (!isObject$1(obj[key])) {
|
|
478
|
+
obj[key] = {};
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
obj = obj[key];
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
return target;
|
|
485
|
+
};
|
|
486
|
+
|
|
487
|
+
setValue.split = split$1;
|
|
488
|
+
setValue.cache = new Map();
|
|
489
|
+
setValue.clear = () => {
|
|
490
|
+
setValue.cache = new Map();
|
|
491
|
+
};
|
|
492
|
+
|
|
493
|
+
var setValue_1 = setValue;
|
|
494
|
+
|
|
495
|
+
const set = /*@__PURE__*/getDefaultExportFromCjs(setValue_1);
|
|
496
|
+
|
|
497
|
+
/*!
|
|
498
|
+
* get-value <https://github.com/jonschlinkert/get-value>
|
|
499
|
+
*
|
|
500
|
+
* Copyright (c) 2014-2018, Jon Schlinkert.
|
|
501
|
+
* Released under the MIT License.
|
|
502
|
+
*/
|
|
503
|
+
|
|
504
|
+
const isObject = isobject;
|
|
505
|
+
|
|
506
|
+
var getValue = function(target, path, options) {
|
|
507
|
+
if (!isObject(options)) {
|
|
508
|
+
options = { default: options };
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
if (!isValidObject(target)) {
|
|
512
|
+
return typeof options.default !== 'undefined' ? options.default : target;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
if (typeof path === 'number') {
|
|
516
|
+
path = String(path);
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
const isArray = Array.isArray(path);
|
|
520
|
+
const isString = typeof path === 'string';
|
|
521
|
+
const splitChar = options.separator || '.';
|
|
522
|
+
const joinChar = options.joinChar || (typeof splitChar === 'string' ? splitChar : '.');
|
|
523
|
+
|
|
524
|
+
if (!isString && !isArray) {
|
|
525
|
+
return target;
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
if (isString && path in target) {
|
|
529
|
+
return isValid(path, target, options) ? target[path] : options.default;
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
let segs = isArray ? path : split(path, splitChar, options);
|
|
533
|
+
let len = segs.length;
|
|
534
|
+
let idx = 0;
|
|
535
|
+
|
|
536
|
+
do {
|
|
537
|
+
let prop = segs[idx];
|
|
538
|
+
if (typeof prop === 'number') {
|
|
539
|
+
prop = String(prop);
|
|
190
540
|
}
|
|
541
|
+
|
|
542
|
+
while (prop && prop.slice(-1) === '\\') {
|
|
543
|
+
prop = join([prop.slice(0, -1), segs[++idx] || ''], joinChar, options);
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
if (prop in target) {
|
|
547
|
+
if (!isValid(prop, target, options)) {
|
|
548
|
+
return options.default;
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
target = target[prop];
|
|
552
|
+
} else {
|
|
553
|
+
let hasProp = false;
|
|
554
|
+
let n = idx + 1;
|
|
555
|
+
|
|
556
|
+
while (n < len) {
|
|
557
|
+
prop = join([prop, segs[n++]], joinChar, options);
|
|
558
|
+
|
|
559
|
+
if ((hasProp = prop in target)) {
|
|
560
|
+
if (!isValid(prop, target, options)) {
|
|
561
|
+
return options.default;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
target = target[prop];
|
|
565
|
+
idx = n - 1;
|
|
566
|
+
break;
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
if (!hasProp) {
|
|
571
|
+
return options.default;
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
} while (++idx < len && isValidObject(target));
|
|
575
|
+
|
|
576
|
+
if (idx === len) {
|
|
577
|
+
return target;
|
|
191
578
|
}
|
|
579
|
+
|
|
580
|
+
return options.default;
|
|
581
|
+
};
|
|
582
|
+
|
|
583
|
+
function join(segs, joinChar, options) {
|
|
584
|
+
if (typeof options.join === 'function') {
|
|
585
|
+
return options.join(segs);
|
|
586
|
+
}
|
|
587
|
+
return segs[0] + joinChar + segs[1];
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
function split(path, splitChar, options) {
|
|
591
|
+
if (typeof options.split === 'function') {
|
|
592
|
+
return options.split(path);
|
|
593
|
+
}
|
|
594
|
+
return path.split(splitChar);
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
function isValid(key, target, options) {
|
|
598
|
+
if (typeof options.isValid === 'function') {
|
|
599
|
+
return options.isValid(key, target);
|
|
600
|
+
}
|
|
601
|
+
return true;
|
|
192
602
|
}
|
|
193
603
|
|
|
604
|
+
function isValidObject(val) {
|
|
605
|
+
return isObject(val) || Array.isArray(val) || typeof val === 'function';
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
const get = /*@__PURE__*/getDefaultExportFromCjs(getValue);
|
|
609
|
+
|
|
194
610
|
function createConfigLoader(root) {
|
|
195
611
|
const explorer = cosmiconfigSync("weapp-tw");
|
|
196
612
|
function search(searchFrom = root) {
|
|
@@ -225,10 +641,10 @@ function updateProjectConfig(options) {
|
|
|
225
641
|
if (fs.existsSync(projectConfigPath)) {
|
|
226
642
|
try {
|
|
227
643
|
const projectConfig = fs.readJSONSync(projectConfigPath);
|
|
228
|
-
projectConfig
|
|
229
|
-
projectConfig
|
|
230
|
-
projectConfig
|
|
231
|
-
if (Array.isArray(projectConfig
|
|
644
|
+
set(projectConfig, "miniprogramRoot", "dist/");
|
|
645
|
+
set(projectConfig, "srcMiniprogramRoot", "dist/");
|
|
646
|
+
set(projectConfig, "setting.packNpmManually", true);
|
|
647
|
+
if (Array.isArray(get(projectConfig, "setting.packNpmRelationList"))) {
|
|
232
648
|
const x = projectConfig.setting.packNpmRelationList.find((x2) => x2.packageJsonPath === "./package.json" && x2.miniprogramNpmDistDir === "./dist");
|
|
233
649
|
if (!x) {
|
|
234
650
|
projectConfig.setting.packNpmRelationList.push({
|
|
@@ -237,12 +653,12 @@ function updateProjectConfig(options) {
|
|
|
237
653
|
});
|
|
238
654
|
}
|
|
239
655
|
} else {
|
|
240
|
-
projectConfig
|
|
656
|
+
set(projectConfig, "setting.packNpmRelationList", [
|
|
241
657
|
{
|
|
242
658
|
packageJsonPath: "./package.json",
|
|
243
659
|
miniprogramNpmDistDir: "./dist"
|
|
244
660
|
}
|
|
245
|
-
];
|
|
661
|
+
]);
|
|
246
662
|
}
|
|
247
663
|
fs.outputJSONSync(dest ?? projectConfigPath, projectConfig, {
|
|
248
664
|
spaces: 2
|
|
@@ -255,6 +671,22 @@ function updateProjectConfig(options) {
|
|
|
255
671
|
console.warn(`\u2728 \u6CA1\u6709\u627E\u5230 ${projectConfigFilename} \u6587\u4EF6!`);
|
|
256
672
|
}
|
|
257
673
|
}
|
|
674
|
+
function updatePackageJson(options) {
|
|
675
|
+
const { root, dest } = options;
|
|
676
|
+
const packageJsonFilename = "package.json";
|
|
677
|
+
const packageJsonPath = path.resolve(root, packageJsonFilename);
|
|
678
|
+
if (fs.existsSync(packageJsonPath)) {
|
|
679
|
+
try {
|
|
680
|
+
const packageJson = fs.readJSONSync(packageJsonPath);
|
|
681
|
+
set(packageJson, "scripts.dev", "weapp-tw dev");
|
|
682
|
+
set(packageJson, "scripts.build", "weapp-tw build");
|
|
683
|
+
fs.outputJSONSync(dest ?? packageJsonPath, packageJson, {
|
|
684
|
+
spaces: 2
|
|
685
|
+
});
|
|
686
|
+
} catch {
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
}
|
|
258
690
|
function initConfig(options) {
|
|
259
691
|
const { lang, root } = defu(options, { lang: "js", root: process.cwd() });
|
|
260
692
|
const configFilename = `weapp-tw.config.${lang ?? "js"}`;
|
|
@@ -280,6 +712,7 @@ module.exports = {}
|
|
|
280
712
|
}
|
|
281
713
|
console.log(`\u2728 ${configFilename} \u914D\u7F6E\u6587\u4EF6\uFF0C\u521D\u59CB\u5316\u6210\u529F!`);
|
|
282
714
|
updateProjectConfig({ root });
|
|
715
|
+
updatePackageJson({ root });
|
|
283
716
|
return configPath;
|
|
284
717
|
}
|
|
285
718
|
|
|
@@ -311,7 +744,4 @@ function createCli() {
|
|
|
311
744
|
return program;
|
|
312
745
|
}
|
|
313
746
|
|
|
314
|
-
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
export { createCli, createConfigLoader, createWatcher, defineConfig };
|
|
747
|
+
export { build, createBuilder, createCli, createConfigLoader, defineConfig };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weapp-tailwindcss/cli",
|
|
3
|
-
"version": "0.0.0-alpha.
|
|
3
|
+
"version": "0.0.0-alpha.1",
|
|
4
4
|
"description": "The cli of weapp-tailwindcss",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"author": "",
|
|
@@ -33,12 +33,16 @@
|
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@types/fs-extra": "^11.0.4",
|
|
36
|
+
"@types/get-value": "^3.0.5",
|
|
36
37
|
"@types/gulp": "^4.0.17",
|
|
37
38
|
"@types/gulp-less": "^0.0.36",
|
|
38
39
|
"@types/gulp-sass": "^5.0.4",
|
|
40
|
+
"@types/set-value": "^4.0.3",
|
|
39
41
|
"@types/vinyl-fs": "^3.0.5",
|
|
40
42
|
"chokidar": "^3.6.0",
|
|
41
43
|
"defu": "^6.1.4",
|
|
44
|
+
"get-value": "^3.0.1",
|
|
45
|
+
"set-value": "^4.1.0",
|
|
42
46
|
"ts-morph": "^22.0.0",
|
|
43
47
|
"vinyl-fs": "^4.0.0"
|
|
44
48
|
},
|