@weapp-tailwindcss/cli 4.0.0-alpha.8 → 5.3.0

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 CHANGED
@@ -1,1108 +1,3 @@
1
- 'use strict';
2
-
3
- const path = require('node:path');
4
- const createDebug = require('debug');
5
- const fs = require('fs-extra');
6
- const gulp$1 = require('gulp');
7
- const less = require('gulp-less');
8
- const postcssrc = require('gulp-postcss');
9
- const rename = require('gulp-rename');
10
- const createSass = require('gulp-sass');
11
- const localPkg = require('local-pkg');
12
- const postcssScssParser = require('postcss-scss');
13
- const gulp = require('weapp-tailwindcss/gulp');
14
- const pc = require('picocolors');
15
- const loadPostcssConfig = require('postcss-load-config');
16
- const process = require('node:process');
17
- const cosmiconfig = require('cosmiconfig');
18
- const commander = require('commander');
19
-
20
- function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
21
-
22
- const path__default = /*#__PURE__*/_interopDefaultCompat(path);
23
- const createDebug__default = /*#__PURE__*/_interopDefaultCompat(createDebug);
24
- const fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
25
- const gulp__default = /*#__PURE__*/_interopDefaultCompat(gulp$1);
26
- const less__default = /*#__PURE__*/_interopDefaultCompat(less);
27
- const postcssrc__default = /*#__PURE__*/_interopDefaultCompat(postcssrc);
28
- const rename__default = /*#__PURE__*/_interopDefaultCompat(rename);
29
- const createSass__default = /*#__PURE__*/_interopDefaultCompat(createSass);
30
- const postcssScssParser__default = /*#__PURE__*/_interopDefaultCompat(postcssScssParser);
31
- const pc__default = /*#__PURE__*/_interopDefaultCompat(pc);
32
- const loadPostcssConfig__default = /*#__PURE__*/_interopDefaultCompat(loadPostcssConfig);
33
- const process__default = /*#__PURE__*/_interopDefaultCompat(process);
34
-
35
- const debug = createDebug__default("weapp-tw-cli");
36
-
37
- const defaultJavascriptExtensions = ["js"];
38
- const defaultTypescriptExtensions = ["ts"];
39
- const defaultWxsExtensions = ["wxs"];
40
- const defaultNodeModulesDirs = [
41
- "**/node_modules/**",
42
- "**/miniprogram_npm/**",
43
- "**/project.config.json/**",
44
- "**/project.private.config.json/**",
45
- "**/package.json/**",
46
- "postcss.config.js",
47
- "tailwind.config.js",
48
- "weapp-tw.config.js"
49
- ];
50
- function noop() {
51
- }
52
- function getDefaultOptions(options, postcssOptionsFromConfig) {
53
- return {
54
- outDir: "dist",
55
- weappTailwindcssOptions: {},
56
- clean: true,
57
- src: "",
58
- exclude: [...defaultNodeModulesDirs],
59
- include: ["**/*.{png,jpg,jpeg,gif,svg,webp}"],
60
- extensions: {
61
- javascript: [...defaultJavascriptExtensions, ...defaultTypescriptExtensions, ...defaultWxsExtensions],
62
- html: ["wxml"],
63
- css: ["wxss", "less", "sass", "scss"],
64
- json: ["json"]
65
- },
66
- watchOptions: {
67
- cwd: options?.root,
68
- events: ["add", "change", "unlink", "ready"]
69
- },
70
- postcssOptions: postcssOptionsFromConfig,
71
- gulpChain: noop
72
- };
73
- }
74
-
75
- var AssetType = /* @__PURE__ */ ((AssetType2) => {
76
- AssetType2["JavaScript"] = "javascript";
77
- AssetType2["Json"] = "json";
78
- AssetType2["Css"] = "css";
79
- AssetType2["Html"] = "html";
80
- return AssetType2;
81
- })(AssetType || {});
82
-
83
- function getDefaultExportFromCjs (x) {
84
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
85
- }
86
-
87
- /*!
88
- * isobject <https://github.com/jonschlinkert/isobject>
89
- *
90
- * Copyright (c) 2014-2017, Jon Schlinkert.
91
- * Released under the MIT License.
92
- */
93
-
94
- var isobject;
95
- var hasRequiredIsobject;
96
-
97
- function requireIsobject () {
98
- if (hasRequiredIsobject) return isobject;
99
- hasRequiredIsobject = 1;
100
-
101
- isobject = function isObject(val) {
102
- return val != null && typeof val === 'object' && Array.isArray(val) === false;
103
- };
104
- return isobject;
105
- }
106
-
107
- /*!
108
- * get-value <https://github.com/jonschlinkert/get-value>
109
- *
110
- * Copyright (c) 2014-2018, Jon Schlinkert.
111
- * Released under the MIT License.
112
- */
113
-
114
- var getValue;
115
- var hasRequiredGetValue;
116
-
117
- function requireGetValue () {
118
- if (hasRequiredGetValue) return getValue;
119
- hasRequiredGetValue = 1;
120
- const isObject = requireIsobject();
121
-
122
- getValue = function(target, path, options) {
123
- if (!isObject(options)) {
124
- options = { default: options };
125
- }
126
-
127
- if (!isValidObject(target)) {
128
- return typeof options.default !== 'undefined' ? options.default : target;
129
- }
130
-
131
- if (typeof path === 'number') {
132
- path = String(path);
133
- }
134
-
135
- const isArray = Array.isArray(path);
136
- const isString = typeof path === 'string';
137
- const splitChar = options.separator || '.';
138
- const joinChar = options.joinChar || (typeof splitChar === 'string' ? splitChar : '.');
139
-
140
- if (!isString && !isArray) {
141
- return target;
142
- }
143
-
144
- if (isString && path in target) {
145
- return isValid(path, target, options) ? target[path] : options.default;
146
- }
147
-
148
- let segs = isArray ? path : split(path, splitChar, options);
149
- let len = segs.length;
150
- let idx = 0;
151
-
152
- do {
153
- let prop = segs[idx];
154
- if (typeof prop === 'number') {
155
- prop = String(prop);
156
- }
157
-
158
- while (prop && prop.slice(-1) === '\\') {
159
- prop = join([prop.slice(0, -1), segs[++idx] || ''], joinChar, options);
160
- }
161
-
162
- if (prop in target) {
163
- if (!isValid(prop, target, options)) {
164
- return options.default;
165
- }
166
-
167
- target = target[prop];
168
- } else {
169
- let hasProp = false;
170
- let n = idx + 1;
171
-
172
- while (n < len) {
173
- prop = join([prop, segs[n++]], joinChar, options);
174
-
175
- if ((hasProp = prop in target)) {
176
- if (!isValid(prop, target, options)) {
177
- return options.default;
178
- }
179
-
180
- target = target[prop];
181
- idx = n - 1;
182
- break;
183
- }
184
- }
185
-
186
- if (!hasProp) {
187
- return options.default;
188
- }
189
- }
190
- } while (++idx < len && isValidObject(target));
191
-
192
- if (idx === len) {
193
- return target;
194
- }
195
-
196
- return options.default;
197
- };
198
-
199
- function join(segs, joinChar, options) {
200
- if (typeof options.join === 'function') {
201
- return options.join(segs);
202
- }
203
- return segs[0] + joinChar + segs[1];
204
- }
205
-
206
- function split(path, splitChar, options) {
207
- if (typeof options.split === 'function') {
208
- return options.split(path);
209
- }
210
- return path.split(splitChar);
211
- }
212
-
213
- function isValid(key, target, options) {
214
- if (typeof options.isValid === 'function') {
215
- return options.isValid(key, target);
216
- }
217
- return true;
218
- }
219
-
220
- function isValidObject(val) {
221
- return isObject(val) || Array.isArray(val) || typeof val === 'function';
222
- }
223
- return getValue;
224
- }
225
-
226
- var getValueExports = requireGetValue();
227
- const get = /*@__PURE__*/getDefaultExportFromCjs(getValueExports);
228
-
229
- /*!
230
- * is-primitive <https://github.com/jonschlinkert/is-primitive>
231
- *
232
- * Copyright (c) 2014-present, Jon Schlinkert.
233
- * Released under the MIT License.
234
- */
235
-
236
- var isPrimitive;
237
- var hasRequiredIsPrimitive;
238
-
239
- function requireIsPrimitive () {
240
- if (hasRequiredIsPrimitive) return isPrimitive;
241
- hasRequiredIsPrimitive = 1;
242
-
243
- isPrimitive = function isPrimitive(val) {
244
- if (typeof val === 'object') {
245
- return val === null;
246
- }
247
- return typeof val !== 'function';
248
- };
249
- return isPrimitive;
250
- }
251
-
252
- /*!
253
- * is-plain-object <https://github.com/jonschlinkert/is-plain-object>
254
- *
255
- * Copyright (c) 2014-2017, Jon Schlinkert.
256
- * Released under the MIT License.
257
- */
258
-
259
- var isPlainObject$1;
260
- var hasRequiredIsPlainObject;
261
-
262
- function requireIsPlainObject () {
263
- if (hasRequiredIsPlainObject) return isPlainObject$1;
264
- hasRequiredIsPlainObject = 1;
265
-
266
- var isObject = requireIsobject();
267
-
268
- function isObjectObject(o) {
269
- return isObject(o) === true
270
- && Object.prototype.toString.call(o) === '[object Object]';
271
- }
272
-
273
- isPlainObject$1 = function isPlainObject(o) {
274
- var ctor,prot;
275
-
276
- if (isObjectObject(o) === false) return false;
277
-
278
- // If has modified constructor
279
- ctor = o.constructor;
280
- if (typeof ctor !== 'function') return false;
281
-
282
- // If has modified prototype
283
- prot = ctor.prototype;
284
- if (isObjectObject(prot) === false) return false;
285
-
286
- // If constructor does not have an Object-specific method
287
- if (prot.hasOwnProperty('isPrototypeOf') === false) {
288
- return false;
289
- }
290
-
291
- // Most likely a plain Object
292
- return true;
293
- };
294
- return isPlainObject$1;
295
- }
296
-
297
- /*!
298
- * set-value <https://github.com/jonschlinkert/set-value>
299
- *
300
- * Copyright (c) Jon Schlinkert (https://github.com/jonschlinkert).
301
- * Released under the MIT License.
302
- */
303
-
304
- var setValue_1;
305
- var hasRequiredSetValue;
306
-
307
- function requireSetValue () {
308
- if (hasRequiredSetValue) return setValue_1;
309
- hasRequiredSetValue = 1;
310
-
311
- const { deleteProperty } = Reflect;
312
- const isPrimitive = requireIsPrimitive();
313
- const isPlainObject = requireIsPlainObject();
314
-
315
- const isObject = value => {
316
- return (typeof value === 'object' && value !== null) || typeof value === 'function';
317
- };
318
-
319
- const isUnsafeKey = key => {
320
- return key === '__proto__' || key === 'constructor' || key === 'prototype';
321
- };
322
-
323
- const validateKey = key => {
324
- if (!isPrimitive(key)) {
325
- throw new TypeError('Object keys must be strings or symbols');
326
- }
327
-
328
- if (isUnsafeKey(key)) {
329
- throw new Error(`Cannot set unsafe key: "${key}"`);
330
- }
331
- };
332
-
333
- const toStringKey = input => {
334
- return Array.isArray(input) ? input.flat().map(String).join(',') : input;
335
- };
336
-
337
- const createMemoKey = (input, options) => {
338
- if (typeof input !== 'string' || !options) return input;
339
- let key = input + ';';
340
- if (options.arrays !== undefined) key += `arrays=${options.arrays};`;
341
- if (options.separator !== undefined) key += `separator=${options.separator};`;
342
- if (options.split !== undefined) key += `split=${options.split};`;
343
- if (options.merge !== undefined) key += `merge=${options.merge};`;
344
- if (options.preservePaths !== undefined) key += `preservePaths=${options.preservePaths};`;
345
- return key;
346
- };
347
-
348
- const memoize = (input, options, fn) => {
349
- const key = toStringKey(options ? createMemoKey(input, options) : input);
350
- validateKey(key);
351
-
352
- const value = setValue.cache.get(key) || fn();
353
- setValue.cache.set(key, value);
354
- return value;
355
- };
356
-
357
- const splitString = (input, options = {}) => {
358
- const sep = options.separator || '.';
359
- const preserve = sep === '/' ? false : options.preservePaths;
360
-
361
- if (typeof input === 'string' && preserve !== false && /\//.test(input)) {
362
- return [input];
363
- }
364
-
365
- const parts = [];
366
- let part = '';
367
-
368
- const push = part => {
369
- let number;
370
- if (part.trim() !== '' && Number.isInteger((number = Number(part)))) {
371
- parts.push(number);
372
- } else {
373
- parts.push(part);
374
- }
375
- };
376
-
377
- for (let i = 0; i < input.length; i++) {
378
- const value = input[i];
379
-
380
- if (value === '\\') {
381
- part += input[++i];
382
- continue;
383
- }
384
-
385
- if (value === sep) {
386
- push(part);
387
- part = '';
388
- continue;
389
- }
390
-
391
- part += value;
392
- }
393
-
394
- if (part) {
395
- push(part);
396
- }
397
-
398
- return parts;
399
- };
400
-
401
- const split = (input, options) => {
402
- if (options && typeof options.split === 'function') return options.split(input);
403
- if (typeof input === 'symbol') return [input];
404
- if (Array.isArray(input)) return input;
405
- return memoize(input, options, () => splitString(input, options));
406
- };
407
-
408
- const assignProp = (obj, prop, value, options) => {
409
- validateKey(prop);
410
-
411
- // Delete property when "value" is undefined
412
- if (value === undefined) {
413
- deleteProperty(obj, prop);
414
-
415
- } else if (options && options.merge) {
416
- const merge = options.merge === 'function' ? options.merge : Object.assign;
417
-
418
- // Only merge plain objects
419
- if (merge && isPlainObject(obj[prop]) && isPlainObject(value)) {
420
- obj[prop] = merge(obj[prop], value);
421
- } else {
422
- obj[prop] = value;
423
- }
424
-
425
- } else {
426
- obj[prop] = value;
427
- }
428
-
429
- return obj;
430
- };
431
-
432
- const setValue = (target, path, value, options) => {
433
- if (!path || !isObject(target)) return target;
434
-
435
- const keys = split(path, options);
436
- let obj = target;
437
-
438
- for (let i = 0; i < keys.length; i++) {
439
- const key = keys[i];
440
- const next = keys[i + 1];
441
-
442
- validateKey(key);
443
-
444
- if (next === undefined) {
445
- assignProp(obj, key, value, options);
446
- break;
447
- }
448
-
449
- if (typeof next === 'number' && !Array.isArray(obj[key])) {
450
- obj = obj[key] = [];
451
- continue;
452
- }
453
-
454
- if (!isObject(obj[key])) {
455
- obj[key] = {};
456
- }
457
-
458
- obj = obj[key];
459
- }
460
-
461
- return target;
462
- };
463
-
464
- setValue.split = split;
465
- setValue.cache = new Map();
466
- setValue.clear = () => {
467
- setValue.cache = new Map();
468
- };
469
-
470
- setValue_1 = setValue;
471
- return setValue_1;
472
- }
473
-
474
- var setValueExports = requireSetValue();
475
- const set = /*@__PURE__*/getDefaultExportFromCjs(setValueExports);
476
-
477
- function isObject(x) {
478
- return typeof x === "object" && x !== null;
479
- }
480
- function promisify(task) {
481
- return new Promise((resolve, reject) => {
482
- if (Array.isArray(task)) {
483
- return Promise.all(task.map((x) => promisify(x))).then(resolve).catch(reject);
484
- } else {
485
- if (task.destroyed) {
486
- resolve(undefined);
487
- return;
488
- }
489
- task.on("finish", () => {
490
- resolve(undefined);
491
- }).on("error", (err) => {
492
- reject(err);
493
- });
494
- }
495
- });
496
- }
497
- function isSassLang(lang) {
498
- return lang === "scss" || lang === "sass";
499
- }
500
- function isLessLang(lang) {
501
- return lang === "less";
502
- }
503
- function isTsLang(lang) {
504
- return lang === "ts";
505
- }
506
-
507
- class GlobsSet {
508
- includeSet;
509
- excludeSet;
510
- constructor() {
511
- this.includeSet = /* @__PURE__ */ new Set();
512
- this.excludeSet = /* @__PURE__ */ new Set();
513
- }
514
- isExcludeGlob(value) {
515
- return value[0] === "!";
516
- }
517
- addSingle(value) {
518
- return this.isExcludeGlob(value) ? this.excludeSet.add(value) : this.includeSet.add(value);
519
- }
520
- add(...value) {
521
- for (const v of value) {
522
- if (Array.isArray(v)) {
523
- for (const vv of v) {
524
- this.addSingle(vv);
525
- }
526
- } else {
527
- this.addSingle(v);
528
- }
529
- }
530
- }
531
- dump() {
532
- return [...this.includeSet, ...this.excludeSet];
533
- }
534
- dumpIgnored() {
535
- return [...this.excludeSet].map((x) => x.slice(1));
536
- }
537
- }
538
-
539
- function isStream(stream, { checkOpen = true } = {}) {
540
- return stream !== null && typeof stream === "object" && (stream.writable || stream.readable || !checkOpen || stream.writable === undefined && stream.readable === undefined) && typeof stream.pipe === "function";
541
- }
542
-
543
- function normalizePlugin(plugin) {
544
- if (isStream(plugin)) {
545
- return plugin;
546
- } else if (typeof plugin === "function") {
547
- return plugin.apply(plugin);
548
- } else if (Array.isArray(plugin)) {
549
- const [fn, ...args] = plugin;
550
- return fn.apply(fn, args);
551
- }
552
- }
553
- function resolveTask({ pipes, globs, since, cwd }) {
554
- let chain = gulp__default.src(globs, { cwd, since: gulp__default.lastRun(since) });
555
- for (const p of pipes) {
556
- chain = chain.pipe(p);
557
- }
558
- return promisify(chain);
559
- }
560
- async function getTasks(options) {
561
- let { typescriptOptions } = options;
562
- const {
563
- root: cwd,
564
- weappTailwindcssOptions,
565
- outDir,
566
- src: srcBase,
567
- extensions,
568
- exclude,
569
- include,
570
- postcssOptions,
571
- preprocessorOptions,
572
- gulpChain
573
- } = options;
574
- const globsSet = new GlobsSet();
575
- const base = srcBase ? `${srcBase}/` : "";
576
- const enableSass = Boolean(preprocessorOptions?.sass);
577
- const enableLess = Boolean(preprocessorOptions?.less);
578
- function resolvePipes(plugins, type) {
579
- const newPlugins = gulpChain(plugins, type);
580
- if (newPlugins === undefined) {
581
- return plugins;
582
- }
583
- return newPlugins.map((x) => normalizePlugin(x)).filter((x) => x);
584
- }
585
- if (typescriptOptions === true) {
586
- typescriptOptions = {
587
- tsConfigFileName: "tsconfig.json"
588
- };
589
- } else if (isObject(typescriptOptions) && typescriptOptions.tsConfigFileName === undefined) {
590
- typescriptOptions.tsConfigFileName = "tsconfig.json";
591
- }
592
- const enableTs = Boolean(typescriptOptions);
593
- let sass;
594
- if (enableSass) {
595
- if (!localPkg.isPackageExists("sass")) {
596
- throw new Error("\u8BF7\u5148\u6267\u884C npm / yarn / pnpm \u547D\u4EE4\u5B89\u88C5 `sass` \u540E\u91CD\u8BD5!");
597
- }
598
- const sassLib = await import('sass');
599
- sass = createSass__default(sassLib);
600
- }
601
- let ts;
602
- let gulpTs;
603
- if (enableTs) {
604
- if (!localPkg.isPackageExists("typescript")) {
605
- throw new Error("\u8BF7\u5148\u6267\u884C npm / yarn / pnpm \u547D\u4EE4\u5B89\u88C5 `typescript` \u540E\u91CD\u8BD5!");
606
- }
607
- ts = (await import('gulp-typescript')).default;
608
- if (typeof typescriptOptions !== "boolean") {
609
- gulpTs = ts.createProject(
610
- typescriptOptions.tsConfigFileName ?? "tsconfig.json",
611
- typescriptOptions.settings
612
- );
613
- }
614
- }
615
- const { transformJs, transformWxml, transformWxss } = gulp.createPlugins(weappTailwindcssOptions);
616
- const outDirGlobs = [`!${outDir}/**/*`, `!./${outDir}/**/*`];
617
- function getGlobs(type) {
618
- const globs = [];
619
- if (typeof include === "function") {
620
- globs.push(...include(type).map((x) => x));
621
- }
622
- if (typeof exclude === "function") {
623
- globs.push(...exclude(type).map((x) => `!${x}`));
624
- } else if (Array.isArray(exclude)) {
625
- globs.push(...exclude.map((x) => `!${x}`));
626
- }
627
- globs.push(...outDirGlobs);
628
- return globs;
629
- }
630
- function getJsTasks() {
631
- const assetType = AssetType.JavaScript;
632
- const globs = getGlobs(assetType);
633
- globsSet.add(globs);
634
- return extensions[assetType]?.map((x) => {
635
- const src = `${base}**/*.${x}`;
636
- globsSet.add(src);
637
- const isTs = isTsLang(x);
638
- const loadTs = enableTs && isTs;
639
- return function JsTask() {
640
- const pipes = [];
641
- if (loadTs && gulpTs) {
642
- pipes.push(gulpTs().on("error", () => {
643
- }));
644
- }
645
- pipes.push(transformJs({
646
- babelParserOptions: !enableTs && isTs ? {
647
- plugins: ["typescript"]
648
- } : undefined
649
- }));
650
- if (loadTs) {
651
- pipes.push(rename__default({
652
- extname: ".js"
653
- }));
654
- }
655
- pipes.push(gulp__default.dest(outDir, {
656
- cwd
657
- }));
658
- return resolveTask({
659
- pipes: resolvePipes(pipes, assetType),
660
- cwd,
661
- globs: [src, ...globs],
662
- since: JsTask
663
- });
664
- };
665
- });
666
- }
667
- function getJsonTasks() {
668
- const assetType = AssetType.Json;
669
- const globs = getGlobs(assetType);
670
- globsSet.add(globs);
671
- return extensions[assetType]?.map((x) => {
672
- const src = `${base}**/*.${x}`;
673
- globsSet.add(src);
674
- return function JsonTask() {
675
- const pipes = [gulp__default.dest(outDir, {
676
- cwd
677
- })];
678
- return resolveTask({
679
- cwd,
680
- globs: [src, ...globs],
681
- pipes: resolvePipes(pipes, assetType),
682
- since: JsonTask
683
- });
684
- };
685
- });
686
- }
687
- function getCssTasks() {
688
- const assetType = AssetType.Css;
689
- const globs = getGlobs(assetType);
690
- globsSet.add(globs);
691
- return extensions[assetType]?.map((x) => {
692
- const src = `${base}**/*.${x}`;
693
- globsSet.add(src);
694
- const loadSass = enableSass && isSassLang(x);
695
- const loadLess = enableLess && isLessLang(x);
696
- return function CssTask() {
697
- const pipes = [];
698
- if (loadSass) {
699
- pipes.push(sass.sync(
700
- // @ts-ignore
701
- typeof preprocessorOptions?.sass === "boolean" ? undefined : preprocessorOptions?.sass
702
- ).on("error", sass.logError));
703
- }
704
- if (loadLess) {
705
- pipes.push(less__default(typeof preprocessorOptions?.less === "boolean" ? undefined : preprocessorOptions?.less));
706
- }
707
- if (postcssOptions) {
708
- pipes.push(postcssrc__default(postcssOptions?.plugins, postcssOptions?.options));
709
- }
710
- if (x === "scss" && !enableSass) {
711
- pipes.push(transformWxss({
712
- postcssOptions: {
713
- options: {
714
- parser: postcssScssParser__default
715
- }
716
- }
717
- }));
718
- } else {
719
- pipes.push(transformWxss());
720
- }
721
- if (loadSass || loadLess) {
722
- pipes.push(rename__default({
723
- extname: ".wxss"
724
- }));
725
- }
726
- pipes.push(gulp__default.dest(outDir, {
727
- cwd
728
- }));
729
- return resolveTask({
730
- cwd,
731
- globs: [src, ...globs],
732
- pipes: resolvePipes(pipes, assetType),
733
- since: CssTask
734
- });
735
- };
736
- });
737
- }
738
- function getHtmlTasks() {
739
- const assetType = AssetType.Html;
740
- const globs = getGlobs(assetType);
741
- globsSet.add(globs);
742
- return extensions[assetType]?.map((x) => {
743
- const src = `${base}**/*.${x}`;
744
- globsSet.add(src);
745
- return function HtmlTask() {
746
- const pipes = [transformWxml(), gulp__default.dest(outDir, {
747
- cwd
748
- })];
749
- return resolveTask({
750
- cwd,
751
- globs: [src, ...globs],
752
- pipes: resolvePipes(pipes, assetType),
753
- since: HtmlTask
754
- });
755
- };
756
- });
757
- }
758
- function copyOthers() {
759
- if (Array.isArray(include)) {
760
- const globs = include.map((x) => {
761
- return `${base}${x}`;
762
- });
763
- globsSet.add(globs);
764
- const pipes = [gulp__default.dest(outDir, {
765
- cwd
766
- })];
767
- return resolveTask({
768
- cwd,
769
- globs: [...globs, ...outDirGlobs, ...defaultNodeModulesDirs.map((x) => `!${x}`)],
770
- pipes,
771
- since: copyOthers
772
- });
773
- }
774
- }
775
- return {
776
- getGlobs,
777
- getJsTasks,
778
- getJsonTasks,
779
- getCssTasks,
780
- getHtmlTasks,
781
- copyOthers,
782
- globsSet
783
- };
784
- }
785
-
786
- function isPlainObject(value) {
787
- if (value === null || typeof value !== "object") {
788
- return false;
789
- }
790
- const prototype = Object.getPrototypeOf(value);
791
- if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) {
792
- return false;
793
- }
794
- if (Symbol.iterator in value) {
795
- return false;
796
- }
797
- if (Symbol.toStringTag in value) {
798
- return Object.prototype.toString.call(value) === "[object Module]";
799
- }
800
- return true;
801
- }
802
-
803
- function _defu(baseObject, defaults, namespace = ".", merger) {
804
- if (!isPlainObject(defaults)) {
805
- return _defu(baseObject, {}, namespace, merger);
806
- }
807
- const object = Object.assign({}, defaults);
808
- for (const key in baseObject) {
809
- if (key === "__proto__" || key === "constructor") {
810
- continue;
811
- }
812
- const value = baseObject[key];
813
- if (value === null || value === undefined) {
814
- continue;
815
- }
816
- if (merger && merger(object, key, value, namespace)) {
817
- continue;
818
- }
819
- if (Array.isArray(value) && Array.isArray(object[key])) {
820
- object[key] = [...value, ...object[key]];
821
- } else if (isPlainObject(value) && isPlainObject(object[key])) {
822
- object[key] = _defu(
823
- value,
824
- object[key],
825
- (namespace ? `${namespace}.` : "") + key.toString(),
826
- merger
827
- );
828
- } else {
829
- object[key] = value;
830
- }
831
- }
832
- return object;
833
- }
834
- function createDefu(merger) {
835
- return (...arguments_) => (
836
- // eslint-disable-next-line unicorn/no-array-reduce
837
- arguments_.reduce((p, c) => _defu(p, c, "", merger), {})
838
- );
839
- }
840
- const defu = createDefu();
841
-
842
- const version = "4.0.0-alpha.8";
843
-
844
- async function createBuilder(options) {
845
- let postcssOptionsFromConfig;
846
- try {
847
- postcssOptionsFromConfig = await loadPostcssConfig__default({ cwd: options?.root });
848
- } catch {
849
- }
850
- const opt = defu(options, getDefaultOptions(options, postcssOptionsFromConfig));
851
- const { copyOthers, getCssTasks, getHtmlTasks, getJsTasks, getJsonTasks, globsSet } = await getTasks(opt);
852
- const tasks = {
853
- css: getCssTasks(),
854
- html: getHtmlTasks(),
855
- json: getJsonTasks(),
856
- js: getJsTasks(),
857
- extra: [copyOthers]
858
- };
859
- async function runTasks() {
860
- debug("run tasks start");
861
- for (const [key, value] of Object.entries(tasks)) {
862
- if (value) {
863
- debug(`run task ${pc__default.bold(pc__default.green(key))} start`);
864
- for (const task of value) {
865
- await task();
866
- }
867
- debug(`run task ${pc__default.bold(pc__default.green(key))} end`);
868
- }
869
- }
870
- debug("run tasks end");
871
- }
872
- const { clean: clean2, outDir, root: cwd, watchOptions } = opt;
873
- async function doClean() {
874
- debug("del start");
875
- const { deleteAsync } = await import('del');
876
- const patterns = [`${outDir}/**`];
877
- await deleteAsync(patterns, { cwd, ignore: defaultNodeModulesDirs });
878
- debug("del end");
879
- }
880
- return {
881
- watcher: undefined,
882
- async build() {
883
- if (clean2) {
884
- await doClean();
885
- }
886
- await fs.ensureDir(path__default.resolve(cwd, outDir));
887
- await runTasks();
888
- return this;
889
- },
890
- async watch() {
891
- if (clean2) {
892
- await doClean();
893
- }
894
- await fs.ensureDir(path__default.resolve(cwd, outDir));
895
- const dumps = globsSet.dump();
896
- const arr = (Array.isArray(watchOptions.ignored) ? watchOptions.ignored : [watchOptions.ignored]).filter(
897
- Boolean
898
- );
899
- watchOptions.ignored = [...globsSet.dumpIgnored(), ...arr];
900
- const watcher = gulp__default.watch(dumps, watchOptions, async (cb) => {
901
- try {
902
- await runTasks();
903
- cb();
904
- } catch (error) {
905
- cb(error);
906
- }
907
- });
908
- watcher.on("change", (path2) => {
909
- console.log(`${pc__default.green("changed")} ${path2}`);
910
- });
911
- watcher.on("add", (path2) => {
912
- console.log(`${pc__default.green("add")} ${path2}`);
913
- });
914
- watcher.on("unlink", (path2) => {
915
- console.log(`${pc__default.green("remove")} ${path2}`);
916
- });
917
- watcher.on("ready", async () => {
918
- const meta = await localPkg.getPackageInfo("weapp-tailwindcss");
919
- let weappTwVersionStr = "";
920
- if (meta) {
921
- weappTwVersionStr = `(${pc__default.blue(pc__default.underline(meta.version))})`;
922
- }
923
- console.log(
924
- `${pc__default.bold(`${pc__default.green("weapp")}-${pc__default.blue("tailwindcss")}`)}${weappTwVersionStr} ${pc__default.cyan("cli")}(${pc__default.blue(pc__default.underline(version))}) is ready!`
925
- );
926
- });
927
- this.watcher = watcher;
928
- return this;
929
- },
930
- globsSet,
931
- clean: doClean
932
- };
933
- }
934
- async function build(options) {
935
- const builder = await createBuilder(options);
936
- return await builder.build();
937
- }
938
- async function watch(options) {
939
- const builder = await createBuilder(options);
940
- return await builder.watch();
941
- }
942
- async function clean(options) {
943
- const builder = await createBuilder(options);
944
- return await builder.clean();
945
- }
946
-
947
- function createConfigLoader(root) {
948
- const explorer = cosmiconfig.cosmiconfigSync("weapp-tw");
949
- function search(searchFrom = root) {
950
- const searchFor = explorer.search(searchFrom);
951
- if (searchFor) {
952
- searchFor.config = defu(searchFor.config, getDefaultConfig(root));
953
- return searchFor;
954
- }
955
- }
956
- function load(filepath) {
957
- return explorer.load(filepath);
958
- }
959
- return {
960
- search,
961
- load
962
- };
963
- }
964
- function getDefaultConfig(root) {
965
- return {
966
- outDir: "dist",
967
- root,
968
- src: "."
969
- };
970
- }
971
- function defineConfig(options) {
972
- return options;
973
- }
974
- function updateProjectConfig(options) {
975
- const { root, dest } = options;
976
- const projectConfigFilename = "project.config.json";
977
- const projectConfigPath = path__default.resolve(root, projectConfigFilename);
978
- if (fs__default.existsSync(projectConfigPath)) {
979
- try {
980
- const projectConfig = fs__default.readJSONSync(projectConfigPath);
981
- set(projectConfig, "miniprogramRoot", "dist/");
982
- set(projectConfig, "srcMiniprogramRoot", "dist/");
983
- set(projectConfig, "setting.packNpmManually", true);
984
- if (Array.isArray(get(projectConfig, "setting.packNpmRelationList"))) {
985
- const x = projectConfig.setting.packNpmRelationList.find(
986
- (x2) => x2.packageJsonPath === "./package.json" && x2.miniprogramNpmDistDir === "./dist"
987
- );
988
- if (!x) {
989
- projectConfig.setting.packNpmRelationList.push({
990
- packageJsonPath: "./package.json",
991
- miniprogramNpmDistDir: "./dist"
992
- });
993
- }
994
- } else {
995
- set(projectConfig, "setting.packNpmRelationList", [
996
- {
997
- packageJsonPath: "./package.json",
998
- miniprogramNpmDistDir: "./dist"
999
- }
1000
- ]);
1001
- }
1002
- fs__default.outputJSONSync(dest ?? projectConfigPath, projectConfig, {
1003
- spaces: 2
1004
- });
1005
- console.log(`\u2728 \u8BBE\u7F6E ${projectConfigFilename} \u914D\u7F6E\u6587\u4EF6\u6210\u529F!`);
1006
- } catch {
1007
- console.warn(`\u2728 \u8BBE\u7F6E ${projectConfigFilename} \u914D\u7F6E\u6587\u4EF6\u5931\u8D25!`);
1008
- }
1009
- } else {
1010
- console.warn(`\u2728 \u6CA1\u6709\u627E\u5230 ${projectConfigFilename} \u6587\u4EF6!`);
1011
- }
1012
- }
1013
- function updatePackageJson(options) {
1014
- const { root, dest } = options;
1015
- const packageJsonFilename = "package.json";
1016
- const packageJsonPath = path__default.resolve(root, packageJsonFilename);
1017
- if (fs__default.existsSync(packageJsonPath)) {
1018
- try {
1019
- const packageJson = fs__default.readJSONSync(packageJsonPath);
1020
- set(packageJson, "scripts.dev", "weapp-tw dev");
1021
- set(packageJson, "scripts.build", "weapp-tw build");
1022
- set(packageJson, "scripts.postinstall", "weapp-tw patch");
1023
- fs__default.outputJSONSync(dest ?? packageJsonPath, packageJson, {
1024
- spaces: 2
1025
- });
1026
- } catch {
1027
- }
1028
- }
1029
- }
1030
- function initConfig(options) {
1031
- const { lang, root } = defu(options, {
1032
- lang: "js",
1033
- root: process__default.cwd()
1034
- });
1035
- const configFilename = `weapp-tw.config.${lang ?? "js"}`;
1036
- const configPath = path__default.resolve(root, configFilename);
1037
- const tsconfigPath = path__default.resolve(root, "tsconfig.json");
1038
- const isTsconfigExisted = fs__default.existsSync(tsconfigPath);
1039
- fs__default.ensureDirSync(root);
1040
- const configOptionsStr = isTsconfigExisted ? `{
1041
- src: './miniprogram'
1042
- }` : "{}";
1043
- if (lang === "ts") {
1044
- fs__default.writeFileSync(
1045
- configPath,
1046
- `import { defineConfig } from '@weapp-tailwindcss/cli'
1047
-
1048
- export default defineConfig(${configOptionsStr})
1049
- `,
1050
- "utf8"
1051
- );
1052
- } else {
1053
- fs__default.writeFileSync(
1054
- configPath,
1055
- `/** @type {import('@weapp-tailwindcss/cli').UserConfig} */
1056
- const config = ${configOptionsStr}
1057
-
1058
- module.exports = config
1059
- `,
1060
- "utf8"
1061
- );
1062
- }
1063
- console.log(`\u2728 ${configFilename} \u914D\u7F6E\u6587\u4EF6\uFF0C\u521D\u59CB\u5316\u6210\u529F!`);
1064
- updateProjectConfig({ root });
1065
- updatePackageJson({ root });
1066
- return configPath;
1067
- }
1068
-
1069
- function createCli() {
1070
- const cwd = process__default.cwd();
1071
- const program = new commander.Command();
1072
- const configLoader = createConfigLoader(cwd);
1073
- const userDefinedConfig = configLoader.search(cwd);
1074
- program.command("dev").alias("serve").action(async () => {
1075
- await watch(
1076
- defu(userDefinedConfig?.config, {
1077
- root: cwd
1078
- })
1079
- );
1080
- });
1081
- program.command("build").action(async () => {
1082
- await build(
1083
- defu(userDefinedConfig?.config, {
1084
- root: cwd
1085
- })
1086
- );
1087
- });
1088
- program.command("init").action(() => {
1089
- initConfig({
1090
- root: cwd
1091
- });
1092
- });
1093
- program.command("clean").action(async () => {
1094
- await clean(
1095
- defu(userDefinedConfig?.config, {
1096
- root: cwd
1097
- })
1098
- );
1099
- });
1100
- return program;
1101
- }
1102
-
1103
- exports.build = build;
1104
- exports.createBuilder = createBuilder;
1105
- exports.createCli = createCli;
1106
- exports.createConfigLoader = createConfigLoader;
1107
- exports.defineConfig = defineConfig;
1108
- exports.watch = watch;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_src = require("./src-C97Lmsr-.cjs");
3
+ exports.runCli = require_src.runCli;