@weapp-tailwindcss/cli 0.0.0-alpha.6 → 0.0.0-alpha.8

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
@@ -6,11 +6,15 @@ const fs = require('fs-extra');
6
6
  const gulp$1 = require('gulp');
7
7
  const loadPostcssConfig = require('postcss-load-config');
8
8
  const pc = require('picocolors');
9
+ const localPkg = require('local-pkg');
9
10
  const createDebug = require('debug');
10
11
  const gulp = require('weapp-tailwindcss/gulp');
11
12
  const postcssrc = require('gulp-postcss');
12
- const plumber = require('gulp-plumber');
13
13
  const gulpif = require('gulp-if');
14
+ const createSass = require('gulp-sass');
15
+ const rename = require('gulp-rename');
16
+ const less = require('gulp-less');
17
+ const typescript = require('gulp-typescript');
14
18
  const cosmiconfig = require('cosmiconfig');
15
19
 
16
20
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
@@ -22,8 +26,11 @@ const loadPostcssConfig__default = /*#__PURE__*/_interopDefaultCompat(loadPostcs
22
26
  const pc__default = /*#__PURE__*/_interopDefaultCompat(pc);
23
27
  const createDebug__default = /*#__PURE__*/_interopDefaultCompat(createDebug);
24
28
  const postcssrc__default = /*#__PURE__*/_interopDefaultCompat(postcssrc);
25
- const plumber__default = /*#__PURE__*/_interopDefaultCompat(plumber);
26
29
  const gulpif__default = /*#__PURE__*/_interopDefaultCompat(gulpif);
30
+ const createSass__default = /*#__PURE__*/_interopDefaultCompat(createSass);
31
+ const rename__default = /*#__PURE__*/_interopDefaultCompat(rename);
32
+ const less__default = /*#__PURE__*/_interopDefaultCompat(less);
33
+ const typescript__default = /*#__PURE__*/_interopDefaultCompat(typescript);
27
34
 
28
35
  function isPlainObject$2(value) {
29
36
  if (value === null || typeof value !== "object") {
@@ -81,272 +88,55 @@ function createDefu(merger) {
81
88
  }
82
89
  const defu = createDefu();
83
90
 
84
- const debug = createDebug__default("weapp-tw-cli");
91
+ const version = "0.0.0-alpha.7";
85
92
 
86
- var AssetType = /* @__PURE__ */ ((AssetType2) => {
87
- AssetType2["JavaScript"] = "javascript";
88
- AssetType2["Json"] = "json";
89
- AssetType2["Css"] = "css";
90
- AssetType2["Html"] = "html";
91
- return AssetType2;
92
- })(AssetType || {});
93
+ const debug = createDebug__default("weapp-tw-cli");
93
94
 
94
- function getTasks(options) {
95
- const { root: cwd, weappTailwindcssOptions, outDir, src: srcBase, extensions, exclude, include, postcssOptions } = options;
96
- const globsSet = /* @__PURE__ */ new Set();
97
- const base = srcBase ? srcBase + "/" : "";
98
- function globsSetAdd(...value) {
95
+ var __defProp = Object.defineProperty;
96
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
97
+ var __publicField = (obj, key, value) => {
98
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
99
+ return value;
100
+ };
101
+ class GlobsSet {
102
+ constructor() {
103
+ __publicField(this, "includeSet");
104
+ __publicField(this, "excludeSet");
105
+ this.includeSet = /* @__PURE__ */ new Set();
106
+ this.excludeSet = /* @__PURE__ */ new Set();
107
+ }
108
+ isExcludeGlob(value) {
109
+ return value[0] === "!";
110
+ }
111
+ addSingle(value) {
112
+ return this.isExcludeGlob(value) ? this.excludeSet.add(value) : this.includeSet.add(value);
113
+ }
114
+ add(...value) {
99
115
  for (const v of value) {
100
116
  if (Array.isArray(v)) {
101
117
  for (const vv of v) {
102
- globsSet.add(vv);
118
+ this.addSingle(vv);
103
119
  }
104
120
  } else {
105
- globsSet.add(v);
121
+ this.addSingle(v);
106
122
  }
107
123
  }
108
124
  }
109
- function getGlobs(type) {
110
- const globs = [];
111
- if (typeof include === "function") {
112
- globs.push(...include(type).map((x) => x));
113
- }
114
- if (typeof exclude === "function") {
115
- globs.push(...exclude(type).map((x) => "!" + x));
116
- } else if (Array.isArray(exclude)) {
117
- globs.push(...exclude.map((x) => "!" + x));
118
- }
119
- globs.push(`!${outDir}/**/*`);
120
- return globs;
121
- }
122
- const { transformJs, transformWxml, transformWxss } = gulp.createPlugins(weappTailwindcssOptions);
123
- function getJsTasks() {
124
- const assetType = AssetType.JavaScript;
125
- const globs = getGlobs(assetType);
126
- globsSetAdd(globs);
127
- return extensions[assetType].map((x) => {
128
- const src = `${base}**/*.${x}`;
129
- globsSetAdd(src);
130
- return function JsTask() {
131
- return gulp__default.src([src, ...globs], { cwd, since: gulp__default.lastRun(JsTask) }).pipe(plumber__default()).pipe(
132
- transformJs({
133
- babelParserOptions: x === "ts" ? {
134
- plugins: ["typescript"]
135
- } : void 0
136
- })
137
- ).pipe(
138
- gulp__default.dest(outDir, {
139
- cwd
140
- })
141
- );
142
- };
143
- });
144
- }
145
- function getJsonTasks() {
146
- const assetType = AssetType.Json;
147
- const globs = getGlobs(assetType);
148
- globsSetAdd(globs);
149
- return extensions[assetType].map((x) => {
150
- const src = `${base}**/*.${x}`;
151
- globsSetAdd(src);
152
- return function JsonTask() {
153
- return gulp__default.src([src, ...globs], { cwd, since: gulp__default.lastRun(JsonTask) }).pipe(plumber__default()).pipe(
154
- gulp__default.dest(outDir, {
155
- cwd
156
- })
157
- );
158
- };
159
- });
160
- }
161
- function getCssTasks() {
162
- const assetType = AssetType.Css;
163
- const globs = getGlobs(assetType);
164
- globsSetAdd(globs);
165
- return extensions[assetType].map((x) => {
166
- const src = `${base}**/*.${x}`;
167
- globsSetAdd(src);
168
- return function CssTask() {
169
- return gulp__default.src([src, ...globs], { cwd, since: gulp__default.lastRun(CssTask) }).pipe(plumber__default()).pipe(gulpif__default(Boolean(postcssOptions), postcssrc__default(postcssOptions?.plugins, postcssOptions?.options))).pipe(transformWxss()).pipe(
170
- gulp__default.dest(outDir, {
171
- cwd
172
- })
173
- );
174
- };
175
- });
125
+ dump() {
126
+ return [...this.includeSet, ...this.excludeSet];
176
127
  }
177
- function getHtmlTasks() {
178
- const assetType = AssetType.Html;
179
- const globs = getGlobs(assetType);
180
- globsSetAdd(globs);
181
- return extensions[assetType].map((x) => {
182
- const src = `${base}**/*.${x}`;
183
- globsSetAdd(src);
184
- return function HtmlTask() {
185
- return gulp__default.src([src, ...globs], { cwd, since: gulp__default.lastRun(HtmlTask) }).pipe(plumber__default()).pipe(transformWxml()).pipe(
186
- gulp__default.dest(outDir, {
187
- cwd
188
- })
189
- );
190
- };
191
- });
128
+ dumpIgnored() {
129
+ return [...this.excludeSet].map((x) => x.slice(1));
192
130
  }
193
- function copyOthers() {
194
- if (Array.isArray(include)) {
195
- const globs = include.map((x) => {
196
- return `${base}${x}`;
197
- });
198
- globsSetAdd(globs);
199
- return gulp__default.src(globs, { cwd, since: gulp__default.lastRun(copyOthers) }).pipe(plumber__default()).pipe(
200
- gulp__default.dest(outDir, {
201
- cwd
202
- })
203
- );
204
- }
205
- }
206
- return {
207
- getGlobs,
208
- getJsTasks,
209
- getJsonTasks,
210
- getCssTasks,
211
- getHtmlTasks,
212
- copyOthers,
213
- globsSet
214
- };
215
131
  }
216
132
 
217
- const defaultJavascriptExtensions = ["js"];
218
- const defaultTypescriptExtensions = ["ts"];
219
- const defaultWxsExtensions = ["wxs"];
220
- const defaultNodeModulesDirs = [
221
- "**/node_modules/**",
222
- "**/miniprogram_npm/**",
223
- "**/project.config.json/**",
224
- "**/project.private.config.json/**",
225
- "**/package.json/**",
226
- "postcss.config.js",
227
- "tailwind.config.js"
228
- ];
229
- function createBuilder(options) {
230
- const {
231
- root: cwd,
232
- weappTailwindcssOptions,
233
- outDir,
234
- src: srcBase,
235
- clean,
236
- extensions,
237
- exclude,
238
- include,
239
- watchOptions,
240
- postcssOptions
241
- } = defu(options, {
242
- outDir: "dist",
243
- weappTailwindcssOptions: {},
244
- clean: true,
245
- src: "",
246
- exclude: [...defaultNodeModulesDirs],
247
- extensions: {
248
- javascript: [...defaultJavascriptExtensions, ...defaultTypescriptExtensions, ...defaultWxsExtensions],
249
- html: ["wxml"],
250
- css: ["wxss", "less", "sass", "scss"],
251
- json: ["json"]
252
- },
253
- watchOptions: {
254
- events: ["add", "change", "unlink", "ready"]
255
- }
256
- });
257
- const { copyOthers, getCssTasks, getHtmlTasks, getJsTasks, getJsonTasks, globsSet } = getTasks({
258
- root: cwd,
259
- weappTailwindcssOptions,
260
- outDir,
261
- src: srcBase,
262
- clean,
263
- extensions,
264
- exclude,
265
- include,
266
- watchOptions,
267
- postcssOptions
268
- });
269
- const tasks = {
270
- css: getCssTasks(),
271
- html: getHtmlTasks(),
272
- json: getJsonTasks(),
273
- js: getJsTasks(),
274
- extra: [copyOthers]
275
- };
276
- async function runTasks() {
277
- debug("run tasks start");
278
- for (const [key, value] of Object.entries(tasks)) {
279
- debug(`run task ${pc__default.bold(pc__default.green(key))} start`);
280
- for (const task of value) {
281
- const s = task();
282
- if (s) {
283
- await new Promise((resolve, reject) => s.on("finish", resolve).on("error", reject));
284
- }
285
- }
286
- debug(`run task ${pc__default.bold(pc__default.green(key))} end`);
287
- }
288
- debug("run tasks end");
289
- }
290
- return {
291
- watcher: void 0,
292
- async build() {
293
- if (clean) {
294
- debug("del start");
295
- const { deleteAsync } = await import('del');
296
- const patterns = [outDir + "/**"];
297
- await deleteAsync(patterns, { cwd, ignore: defaultNodeModulesDirs });
298
- debug("del end");
299
- }
300
- fs.ensureDirSync(path__default.resolve(cwd, outDir));
301
- await runTasks();
302
- return this;
303
- },
304
- watch() {
305
- fs.ensureDirSync(path__default.resolve(cwd, outDir));
306
- const watcher = gulp__default.watch([...globsSet], watchOptions, async (cb) => {
307
- try {
308
- await runTasks();
309
- cb();
310
- } catch (error) {
311
- cb(error);
312
- }
313
- });
314
- watcher.on("change", function(path2) {
315
- console.log(`${pc__default.green("changed")} ${path2}`);
316
- });
317
- watcher.on("add", function(path2) {
318
- console.log(`${pc__default.green("add")} ${path2}`);
319
- });
320
- watcher.on("unlink", function(path2) {
321
- console.log(`${pc__default.green("remove")} ${path2}`);
322
- });
323
- watcher.on("ready", function() {
324
- console.log(`${pc__default.green("weapp")}-${pc__default.blue("tailwindcss")} is ready!`);
325
- });
326
- this.watcher = watcher;
327
- return this;
328
- },
329
- globsSet
330
- };
331
- }
332
- async function build(options) {
333
- let postcssOptions;
334
- try {
335
- postcssOptions = await loadPostcssConfig__default({ cwd: options?.root });
336
- } catch {
337
- }
338
- const builder = createBuilder(defu(options, { postcssOptions }));
339
- return await builder.build();
340
- }
341
- async function watch(options) {
342
- let postcssOptions;
343
- try {
344
- postcssOptions = await loadPostcssConfig__default({ cwd: options?.root });
345
- } catch {
346
- }
347
- const builder = createBuilder(defu(options, { postcssOptions }));
348
- return await builder.watch();
349
- }
133
+ var AssetType = /* @__PURE__ */ ((AssetType2) => {
134
+ AssetType2["JavaScript"] = "javascript";
135
+ AssetType2["Json"] = "json";
136
+ AssetType2["Css"] = "css";
137
+ AssetType2["Html"] = "html";
138
+ return AssetType2;
139
+ })(AssetType || {});
350
140
 
351
141
  function getDefaultExportFromCjs (x) {
352
142
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
@@ -384,10 +174,10 @@ var isobject = function isObject(val) {
384
174
  * Released under the MIT License.
385
175
  */
386
176
 
387
- var isObject$2 = isobject;
177
+ var isObject$3 = isobject;
388
178
 
389
179
  function isObjectObject(o) {
390
- return isObject$2(o) === true
180
+ return isObject$3(o) === true
391
181
  && Object.prototype.toString.call(o) === '[object Object]';
392
182
  }
393
183
 
@@ -424,7 +214,7 @@ const { deleteProperty } = Reflect;
424
214
  const isPrimitive = isPrimitive$1;
425
215
  const isPlainObject = isPlainObject$1;
426
216
 
427
- const isObject$1 = value => {
217
+ const isObject$2 = value => {
428
218
  return (typeof value === 'object' && value !== null) || typeof value === 'function';
429
219
  };
430
220
 
@@ -542,7 +332,7 @@ const assignProp = (obj, prop, value, options) => {
542
332
  };
543
333
 
544
334
  const setValue = (target, path, value, options) => {
545
- if (!path || !isObject$1(target)) return target;
335
+ if (!path || !isObject$2(target)) return target;
546
336
 
547
337
  const keys = split$1(path, options);
548
338
  let obj = target;
@@ -563,7 +353,7 @@ const setValue = (target, path, value, options) => {
563
353
  continue;
564
354
  }
565
355
 
566
- if (!isObject$1(obj[key])) {
356
+ if (!isObject$2(obj[key])) {
567
357
  obj[key] = {};
568
358
  }
569
359
 
@@ -590,10 +380,10 @@ const set = /*@__PURE__*/getDefaultExportFromCjs(setValue_1);
590
380
  * Released under the MIT License.
591
381
  */
592
382
 
593
- const isObject = isobject;
383
+ const isObject$1 = isobject;
594
384
 
595
385
  var getValue = function(target, path, options) {
596
- if (!isObject(options)) {
386
+ if (!isObject$1(options)) {
597
387
  options = { default: options };
598
388
  }
599
389
 
@@ -691,11 +481,333 @@ function isValid(key, target, options) {
691
481
  }
692
482
 
693
483
  function isValidObject(val) {
694
- return isObject(val) || Array.isArray(val) || typeof val === 'function';
484
+ return isObject$1(val) || Array.isArray(val) || typeof val === 'function';
695
485
  }
696
486
 
697
487
  const get = /*@__PURE__*/getDefaultExportFromCjs(getValue);
698
488
 
489
+ function isObject(x) {
490
+ return typeof x === "object" && x !== null;
491
+ }
492
+ function promisify(task) {
493
+ return new Promise((resolve, reject) => {
494
+ if (Array.isArray(task)) {
495
+ return Promise.all(task.map((x) => promisify(x))).then(resolve).catch(reject);
496
+ } else {
497
+ if (task.destroyed) {
498
+ resolve(void 0);
499
+ return;
500
+ }
501
+ task.on("finish", () => {
502
+ resolve(void 0);
503
+ }).on("error", (err) => {
504
+ reject(err);
505
+ });
506
+ }
507
+ });
508
+ }
509
+
510
+ function isSassLang(lang) {
511
+ return lang === "scss" || lang === "sass";
512
+ }
513
+ function isLessLang(lang) {
514
+ return lang === "less";
515
+ }
516
+ function isTsLang(lang) {
517
+ return lang === "ts";
518
+ }
519
+ async function getTasks(options) {
520
+ let { typescriptOptions } = options;
521
+ const { root: cwd, weappTailwindcssOptions, outDir, src: srcBase, extensions, exclude, include, postcssOptions, preprocessorOptions } = options;
522
+ const globsSet = new GlobsSet();
523
+ const base = srcBase ? srcBase + "/" : "";
524
+ const enableSass = Boolean(preprocessorOptions?.sass);
525
+ const enableLess = Boolean(preprocessorOptions?.less);
526
+ if (typescriptOptions === true) {
527
+ typescriptOptions = {
528
+ tsConfigFileName: "tsconfig.json"
529
+ };
530
+ } else if (isObject(typescriptOptions) && typescriptOptions.tsConfigFileName === void 0) {
531
+ typescriptOptions.tsConfigFileName = "tsconfig.json";
532
+ }
533
+ const enableTs = Boolean(typescriptOptions);
534
+ let sass;
535
+ if (enableSass) {
536
+ const sassLib = await import('sass');
537
+ sass = createSass__default(sassLib);
538
+ }
539
+ const { transformJs, transformWxml, transformWxss } = gulp.createPlugins(weappTailwindcssOptions);
540
+ function getGlobs(type) {
541
+ const globs = [];
542
+ if (typeof include === "function") {
543
+ globs.push(...include(type).map((x) => x));
544
+ }
545
+ if (typeof exclude === "function") {
546
+ globs.push(...exclude(type).map((x) => "!" + x));
547
+ } else if (Array.isArray(exclude)) {
548
+ globs.push(...exclude.map((x) => "!" + x));
549
+ }
550
+ globs.push(`!${outDir}/**/*`);
551
+ globs.push(`!./${outDir}/**/*`);
552
+ return globs;
553
+ }
554
+ function getJsTasks() {
555
+ const assetType = AssetType.JavaScript;
556
+ const globs = getGlobs(assetType);
557
+ globsSet.add(globs);
558
+ return extensions[assetType]?.map((x) => {
559
+ const src = `${base}**/*.${x}`;
560
+ globsSet.add(src);
561
+ const isTs = isTsLang(x);
562
+ const loadTs = enableTs && isTs;
563
+ let gulpTs;
564
+ if (enableTs && typeof typescriptOptions !== "boolean") {
565
+ gulpTs = typescript__default.createProject(typescriptOptions.tsConfigFileName ?? "tsconfig.json", typeof typescriptOptions === "boolean" ? {} : typescriptOptions);
566
+ }
567
+ return function JsTask() {
568
+ let chain = gulp__default.src([src, ...globs], { cwd, since: gulp__default.lastRun(JsTask) });
569
+ if (loadTs) {
570
+ chain = chain.pipe(gulpTs());
571
+ }
572
+ return promisify(
573
+ chain.pipe(
574
+ transformJs({
575
+ babelParserOptions: !enableTs && isTs ? {
576
+ plugins: ["typescript"]
577
+ } : void 0
578
+ })
579
+ ).pipe(
580
+ gulpif__default(
581
+ loadTs,
582
+ rename__default({
583
+ extname: ".js"
584
+ })
585
+ )
586
+ ).pipe(
587
+ gulp__default.dest(outDir, {
588
+ cwd
589
+ })
590
+ )
591
+ );
592
+ };
593
+ });
594
+ }
595
+ function getJsonTasks() {
596
+ const assetType = AssetType.Json;
597
+ const globs = getGlobs(assetType);
598
+ globsSet.add(globs);
599
+ return extensions[assetType]?.map((x) => {
600
+ const src = `${base}**/*.${x}`;
601
+ globsSet.add(src);
602
+ return function JsonTask() {
603
+ return promisify(
604
+ gulp__default.src([src, ...globs], { cwd, since: gulp__default.lastRun(JsonTask) }).pipe(
605
+ gulp__default.dest(outDir, {
606
+ cwd
607
+ })
608
+ )
609
+ );
610
+ };
611
+ });
612
+ }
613
+ function getCssTasks() {
614
+ const assetType = AssetType.Css;
615
+ const globs = getGlobs(assetType);
616
+ globsSet.add(globs);
617
+ return extensions[assetType]?.map((x) => {
618
+ const src = `${base}**/*.${x}`;
619
+ globsSet.add(src);
620
+ const loadSass = enableSass && isSassLang(x);
621
+ const loadLess = enableLess && isLessLang(x);
622
+ return function CssTask() {
623
+ let chain = gulp__default.src([src, ...globs], { cwd, since: gulp__default.lastRun(CssTask) });
624
+ if (loadSass) {
625
+ chain = chain.pipe(
626
+ sass.sync(
627
+ // @ts-ignore
628
+ typeof preprocessorOptions?.sass === "boolean" ? void 0 : preprocessorOptions?.sass
629
+ ).on("error", sass.logError)
630
+ );
631
+ }
632
+ return promisify(
633
+ chain.pipe(gulpif__default(loadLess, less__default(typeof preprocessorOptions?.less === "boolean" ? void 0 : preprocessorOptions?.less))).pipe(gulpif__default(Boolean(postcssOptions), postcssrc__default(postcssOptions?.plugins, postcssOptions?.options))).pipe(transformWxss()).pipe(
634
+ gulpif__default(
635
+ loadSass || loadLess,
636
+ rename__default({
637
+ extname: ".wxss"
638
+ })
639
+ )
640
+ ).pipe(
641
+ gulp__default.dest(outDir, {
642
+ cwd
643
+ })
644
+ )
645
+ );
646
+ };
647
+ });
648
+ }
649
+ function getHtmlTasks() {
650
+ const assetType = AssetType.Html;
651
+ const globs = getGlobs(assetType);
652
+ globsSet.add(globs);
653
+ return extensions[assetType]?.map((x) => {
654
+ const src = `${base}**/*.${x}`;
655
+ globsSet.add(src);
656
+ return function HtmlTask() {
657
+ return promisify(
658
+ gulp__default.src([src, ...globs], { cwd, since: gulp__default.lastRun(HtmlTask) }).pipe(transformWxml()).pipe(
659
+ gulp__default.dest(outDir, {
660
+ cwd
661
+ })
662
+ )
663
+ );
664
+ };
665
+ });
666
+ }
667
+ function copyOthers() {
668
+ if (Array.isArray(include)) {
669
+ const globs = include.map((x) => {
670
+ return `${base}${x}`;
671
+ });
672
+ globsSet.add(globs);
673
+ return promisify(
674
+ gulp__default.src(globs, { cwd, since: gulp__default.lastRun(copyOthers) }).pipe(
675
+ gulp__default.dest(outDir, {
676
+ cwd
677
+ })
678
+ )
679
+ );
680
+ }
681
+ }
682
+ return {
683
+ getGlobs,
684
+ getJsTasks,
685
+ getJsonTasks,
686
+ getCssTasks,
687
+ getHtmlTasks,
688
+ copyOthers,
689
+ globsSet
690
+ };
691
+ }
692
+
693
+ const defaultJavascriptExtensions = ["js"];
694
+ const defaultTypescriptExtensions = ["ts"];
695
+ const defaultWxsExtensions = ["wxs"];
696
+ const defaultNodeModulesDirs = [
697
+ "**/node_modules/**",
698
+ "**/miniprogram_npm/**",
699
+ "**/project.config.json/**",
700
+ "**/project.private.config.json/**",
701
+ "**/package.json/**",
702
+ "postcss.config.js",
703
+ "tailwind.config.js",
704
+ "weapp-tw.config.js"
705
+ ];
706
+ async function createBuilder(options) {
707
+ let postcssOptionsFromConfig;
708
+ try {
709
+ postcssOptionsFromConfig = await loadPostcssConfig__default({ cwd: options?.root });
710
+ } catch {
711
+ }
712
+ const opt = defu(options, {
713
+ outDir: "dist",
714
+ weappTailwindcssOptions: {},
715
+ clean: true,
716
+ src: "",
717
+ exclude: [...defaultNodeModulesDirs],
718
+ extensions: {
719
+ javascript: [...defaultJavascriptExtensions, ...defaultTypescriptExtensions, ...defaultWxsExtensions],
720
+ html: ["wxml"],
721
+ css: ["wxss", "less", "sass", "scss"],
722
+ json: ["json"]
723
+ },
724
+ watchOptions: {
725
+ cwd: options?.root,
726
+ events: ["add", "change", "unlink", "ready"]
727
+ },
728
+ postcssOptions: postcssOptionsFromConfig
729
+ });
730
+ const { copyOthers, getCssTasks, getHtmlTasks, getJsTasks, getJsonTasks, globsSet } = await getTasks(opt);
731
+ const tasks = {
732
+ css: getCssTasks(),
733
+ html: getHtmlTasks(),
734
+ json: getJsonTasks(),
735
+ js: getJsTasks(),
736
+ extra: [copyOthers]
737
+ };
738
+ async function runTasks() {
739
+ debug("run tasks start");
740
+ for (const [key, value] of Object.entries(tasks)) {
741
+ if (value) {
742
+ debug(`run task ${pc__default.bold(pc__default.green(key))} start`);
743
+ for (const task of value) {
744
+ await task();
745
+ }
746
+ debug(`run task ${pc__default.bold(pc__default.green(key))} end`);
747
+ }
748
+ }
749
+ debug("run tasks end");
750
+ }
751
+ const { clean, outDir, root: cwd, watchOptions } = opt;
752
+ return {
753
+ watcher: void 0,
754
+ async build() {
755
+ if (clean) {
756
+ debug("del start");
757
+ const { deleteAsync } = await import('del');
758
+ const patterns = [outDir + "/**"];
759
+ await deleteAsync(patterns, { cwd, ignore: defaultNodeModulesDirs });
760
+ debug("del end");
761
+ }
762
+ fs.ensureDirSync(path__default.resolve(cwd, outDir));
763
+ await runTasks();
764
+ return this;
765
+ },
766
+ watch() {
767
+ fs.ensureDirSync(path__default.resolve(cwd, outDir));
768
+ const dumps = globsSet.dump();
769
+ const arr = (Array.isArray(watchOptions.ignored) ? watchOptions.ignored : [watchOptions.ignored]).filter(Boolean);
770
+ watchOptions.ignored = [...globsSet.dumpIgnored(), ...arr];
771
+ const watcher = gulp__default.watch(dumps, watchOptions, async (cb) => {
772
+ try {
773
+ await runTasks();
774
+ cb();
775
+ } catch (error) {
776
+ cb(error);
777
+ }
778
+ });
779
+ watcher.on("change", function(path2) {
780
+ console.log(`${pc__default.green("changed")} ${path2}`);
781
+ });
782
+ watcher.on("add", function(path2) {
783
+ console.log(`${pc__default.green("add")} ${path2}`);
784
+ });
785
+ watcher.on("unlink", function(path2) {
786
+ console.log(`${pc__default.green("remove")} ${path2}`);
787
+ });
788
+ watcher.on("ready", async function() {
789
+ const meta = await localPkg.getPackageInfo("weapp-tailwindcss");
790
+ let weappTwVersionStr = "";
791
+ if (meta) {
792
+ weappTwVersionStr = `(${pc__default.blue(pc__default.underline(meta.version))})`;
793
+ }
794
+ console.log(`${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!`);
795
+ });
796
+ this.watcher = watcher;
797
+ return this;
798
+ },
799
+ globsSet
800
+ };
801
+ }
802
+ async function build(options) {
803
+ const builder = await createBuilder(options);
804
+ return await builder.build();
805
+ }
806
+ async function watch(options) {
807
+ const builder = await createBuilder(options);
808
+ return await builder.watch();
809
+ }
810
+
699
811
  function createConfigLoader(root) {
700
812
  const explorer = cosmiconfig.cosmiconfigSync("weapp-tw");
701
813
  function search(searchFrom = root) {
@@ -769,6 +881,7 @@ function updatePackageJson(options) {
769
881
  const packageJson = fs__default.readJSONSync(packageJsonPath);
770
882
  set(packageJson, "scripts.dev", "weapp-tw dev");
771
883
  set(packageJson, "scripts.build", "weapp-tw build");
884
+ set(packageJson, "scripts.postinstall", "weapp-tw patch");
772
885
  fs__default.outputJSONSync(dest ?? packageJsonPath, packageJson, {
773
886
  spaces: 2
774
887
  });
@@ -799,7 +912,9 @@ export default defineConfig(${configOptionsStr})
799
912
  fs__default.writeFileSync(
800
913
  configPath,
801
914
  `/** @type {import('@weapp-tailwindcss/cli').UserConfig} */
802
- module.exports = ${configOptionsStr}
915
+ const config = ${configOptionsStr}
916
+
917
+ module.exports = config
803
918
  `,
804
919
  "utf8"
805
920
  );