@weapp-tailwindcss/cli 0.0.0-alpha.5 → 0.0.0-alpha.7

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 ice breaker
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.cjs CHANGED
@@ -5,10 +5,16 @@ const path = require('node:path');
5
5
  const fs = require('fs-extra');
6
6
  const gulp$1 = require('gulp');
7
7
  const loadPostcssConfig = require('postcss-load-config');
8
+ const pc = require('picocolors');
9
+ const createDebug = require('debug');
8
10
  const gulp = require('weapp-tailwindcss/gulp');
9
11
  const postcssrc = require('gulp-postcss');
10
12
  const plumber = require('gulp-plumber');
11
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');
12
18
  const cosmiconfig = require('cosmiconfig');
13
19
 
14
20
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
@@ -17,9 +23,15 @@ const path__default = /*#__PURE__*/_interopDefaultCompat(path);
17
23
  const fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
18
24
  const gulp__default = /*#__PURE__*/_interopDefaultCompat(gulp$1);
19
25
  const loadPostcssConfig__default = /*#__PURE__*/_interopDefaultCompat(loadPostcssConfig);
26
+ const pc__default = /*#__PURE__*/_interopDefaultCompat(pc);
27
+ const createDebug__default = /*#__PURE__*/_interopDefaultCompat(createDebug);
20
28
  const postcssrc__default = /*#__PURE__*/_interopDefaultCompat(postcssrc);
21
29
  const plumber__default = /*#__PURE__*/_interopDefaultCompat(plumber);
22
30
  const gulpif__default = /*#__PURE__*/_interopDefaultCompat(gulpif);
31
+ const createSass__default = /*#__PURE__*/_interopDefaultCompat(createSass);
32
+ const rename__default = /*#__PURE__*/_interopDefaultCompat(rename);
33
+ const less__default = /*#__PURE__*/_interopDefaultCompat(less);
34
+ const typescript__default = /*#__PURE__*/_interopDefaultCompat(typescript);
23
35
 
24
36
  function isPlainObject$2(value) {
25
37
  if (value === null || typeof value !== "object") {
@@ -77,6 +89,8 @@ function createDefu(merger) {
77
89
  }
78
90
  const defu = createDefu();
79
91
 
92
+ const debug = createDebug__default("weapp-tw-cli");
93
+
80
94
  var AssetType = /* @__PURE__ */ ((AssetType2) => {
81
95
  AssetType2["JavaScript"] = "javascript";
82
96
  AssetType2["Json"] = "json";
@@ -85,249 +99,6 @@ var AssetType = /* @__PURE__ */ ((AssetType2) => {
85
99
  return AssetType2;
86
100
  })(AssetType || {});
87
101
 
88
- function getTasks(options) {
89
- const { root: cwd, weappTailwindcssOptions, outDir, src: srcBase, extensions, exclude, include, postcssOptions } = options;
90
- const globsSet = /* @__PURE__ */ new Set();
91
- const base = srcBase ? srcBase + "/" : "";
92
- function globsSetAdd(...value) {
93
- for (const v of value) {
94
- if (Array.isArray(v)) {
95
- for (const vv of v) {
96
- globsSet.add(vv);
97
- }
98
- } else {
99
- globsSet.add(v);
100
- }
101
- }
102
- }
103
- function getGlobs(type) {
104
- const globs = [];
105
- if (typeof include === "function") {
106
- globs.push(...include(type).map((x) => x));
107
- }
108
- if (typeof exclude === "function") {
109
- globs.push(...exclude(type).map((x) => "!" + x));
110
- } else if (Array.isArray(exclude)) {
111
- globs.push(...exclude.map((x) => "!" + x));
112
- }
113
- globs.push(`!${outDir}/**/*`);
114
- return globs;
115
- }
116
- const { transformJs, transformWxml, transformWxss } = gulp.createPlugins(weappTailwindcssOptions);
117
- function getJsTasks() {
118
- const assetType = AssetType.JavaScript;
119
- const globs = getGlobs(assetType);
120
- globsSetAdd(globs);
121
- return extensions[assetType].map((x) => {
122
- const src = `${base}**/*.${x}`;
123
- globsSetAdd(src);
124
- return function JsTask() {
125
- return gulp__default.src([src, ...globs], { cwd, since: gulp__default.lastRun(JsTask) }).pipe(plumber__default()).pipe(
126
- transformJs({
127
- babelParserOptions: x === "ts" ? {
128
- plugins: ["typescript"]
129
- } : void 0
130
- })
131
- ).pipe(
132
- gulp__default.dest(outDir, {
133
- cwd
134
- })
135
- );
136
- };
137
- });
138
- }
139
- function getJsonTasks() {
140
- const assetType = AssetType.Json;
141
- const globs = getGlobs(assetType);
142
- globsSetAdd(globs);
143
- return extensions[assetType].map((x) => {
144
- const src = `${base}**/*.${x}`;
145
- globsSetAdd(src);
146
- return function JsonTask() {
147
- return gulp__default.src([src, ...globs], { cwd, since: gulp__default.lastRun(JsonTask) }).pipe(plumber__default()).pipe(
148
- gulp__default.dest(outDir, {
149
- cwd
150
- })
151
- );
152
- };
153
- });
154
- }
155
- function getCssTasks() {
156
- const assetType = AssetType.Css;
157
- const globs = getGlobs(assetType);
158
- globsSetAdd(globs);
159
- return extensions[assetType].map((x) => {
160
- const src = `${base}**/*.${x}`;
161
- globsSetAdd(src);
162
- return function CssTask() {
163
- 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(
164
- gulp__default.dest(outDir, {
165
- cwd
166
- })
167
- );
168
- };
169
- });
170
- }
171
- function getHtmlTasks() {
172
- const assetType = AssetType.Html;
173
- const globs = getGlobs(assetType);
174
- globsSetAdd(globs);
175
- return extensions[assetType].map((x) => {
176
- const src = `${base}**/*.${x}`;
177
- globsSetAdd(src);
178
- return function HtmlTask() {
179
- return gulp__default.src([src, ...globs], { cwd, since: gulp__default.lastRun(HtmlTask) }).pipe(plumber__default()).pipe(transformWxml()).pipe(
180
- gulp__default.dest(outDir, {
181
- cwd
182
- })
183
- );
184
- };
185
- });
186
- }
187
- function copyOthers() {
188
- if (Array.isArray(include)) {
189
- const globs = include.map((x) => {
190
- return `${base}${x}`;
191
- });
192
- globsSetAdd(globs);
193
- return gulp__default.src(globs, { cwd, since: gulp__default.lastRun(copyOthers) }).pipe(plumber__default()).pipe(
194
- gulp__default.dest(outDir, {
195
- cwd
196
- })
197
- );
198
- }
199
- }
200
- return {
201
- getGlobs,
202
- getJsTasks,
203
- getJsonTasks,
204
- getCssTasks,
205
- getHtmlTasks,
206
- copyOthers,
207
- globsSet
208
- };
209
- }
210
-
211
- const defaultJavascriptExtensions = ["js"];
212
- const defaultTypescriptExtensions = ["ts"];
213
- const defaultWxsExtensions = ["wxs"];
214
- const defaultNodeModulesDirs = [
215
- "**/node_modules/**",
216
- "**/miniprogram_npm/**",
217
- "**/project.config.json/**",
218
- "**/project.private.config.json/**",
219
- "**/package.json/**",
220
- "postcss.config.js",
221
- "tailwind.config.js"
222
- ];
223
- function createBuilder(options) {
224
- const {
225
- root: cwd,
226
- weappTailwindcssOptions,
227
- outDir,
228
- src: srcBase,
229
- clean,
230
- extensions,
231
- exclude,
232
- include,
233
- watchOptions,
234
- postcssOptions
235
- } = defu(options, {
236
- outDir: "dist",
237
- weappTailwindcssOptions: {},
238
- clean: true,
239
- src: "",
240
- exclude: [...defaultNodeModulesDirs],
241
- extensions: {
242
- javascript: [...defaultJavascriptExtensions, ...defaultTypescriptExtensions, ...defaultWxsExtensions],
243
- html: ["wxml"],
244
- css: ["wxss", "less", "sass", "scss"],
245
- json: ["json"]
246
- },
247
- watchOptions: {
248
- events: ["add", "change", "unlink", "ready"]
249
- }
250
- });
251
- const { copyOthers, getCssTasks, getHtmlTasks, getJsTasks, getJsonTasks, globsSet } = getTasks({
252
- root: cwd,
253
- weappTailwindcssOptions,
254
- outDir,
255
- src: srcBase,
256
- clean,
257
- extensions,
258
- exclude,
259
- include,
260
- watchOptions,
261
- postcssOptions
262
- });
263
- const tasks = [...getJsTasks(), ...getJsonTasks(), ...getCssTasks(), ...getHtmlTasks(), copyOthers];
264
- async function runTasks() {
265
- for (const task of tasks) {
266
- const s = task();
267
- if (s) {
268
- await new Promise((resolve, reject) => s.on("finish", resolve).on("error", reject));
269
- }
270
- }
271
- }
272
- return {
273
- watcher: void 0,
274
- async build() {
275
- if (clean) {
276
- const { deleteAsync } = await import('del');
277
- const patterns = [outDir + "/**"];
278
- await deleteAsync(patterns, { cwd, ignore: defaultNodeModulesDirs });
279
- }
280
- fs.ensureDirSync(path__default.resolve(cwd, outDir));
281
- await runTasks();
282
- return this;
283
- },
284
- watch() {
285
- fs.ensureDirSync(path__default.resolve(cwd, outDir));
286
- const watcher = gulp__default.watch([...globsSet], watchOptions, async (cb) => {
287
- try {
288
- await runTasks();
289
- cb();
290
- } catch (error) {
291
- cb(error);
292
- }
293
- });
294
- watcher.on("change", function(path2) {
295
- console.log(`File ${path2} was changed`);
296
- });
297
- watcher.on("add", function(path2) {
298
- console.log(`File ${path2} was added`);
299
- });
300
- watcher.on("unlink", function(path2) {
301
- console.log(`File ${path2} was removed`);
302
- });
303
- watcher.on("ready", function() {
304
- console.log(`Weapp-tailwindcss is Ready!`);
305
- });
306
- this.watcher = watcher;
307
- return this;
308
- },
309
- globsSet
310
- };
311
- }
312
- async function build(options) {
313
- let postcssOptions;
314
- try {
315
- postcssOptions = await loadPostcssConfig__default({ cwd: options?.root });
316
- } catch {
317
- }
318
- const builder = createBuilder(defu(options, { postcssOptions }));
319
- return await builder.build();
320
- }
321
- async function watch(options) {
322
- let postcssOptions;
323
- try {
324
- postcssOptions = await loadPostcssConfig__default({ cwd: options?.root });
325
- } catch {
326
- }
327
- const builder = createBuilder(defu(options, { postcssOptions }));
328
- return await builder.watch();
329
- }
330
-
331
102
  function getDefaultExportFromCjs (x) {
332
103
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
333
104
  }
@@ -364,10 +135,10 @@ var isobject = function isObject(val) {
364
135
  * Released under the MIT License.
365
136
  */
366
137
 
367
- var isObject$2 = isobject;
138
+ var isObject$3 = isobject;
368
139
 
369
140
  function isObjectObject(o) {
370
- return isObject$2(o) === true
141
+ return isObject$3(o) === true
371
142
  && Object.prototype.toString.call(o) === '[object Object]';
372
143
  }
373
144
 
@@ -404,7 +175,7 @@ const { deleteProperty } = Reflect;
404
175
  const isPrimitive = isPrimitive$1;
405
176
  const isPlainObject = isPlainObject$1;
406
177
 
407
- const isObject$1 = value => {
178
+ const isObject$2 = value => {
408
179
  return (typeof value === 'object' && value !== null) || typeof value === 'function';
409
180
  };
410
181
 
@@ -522,7 +293,7 @@ const assignProp = (obj, prop, value, options) => {
522
293
  };
523
294
 
524
295
  const setValue = (target, path, value, options) => {
525
- if (!path || !isObject$1(target)) return target;
296
+ if (!path || !isObject$2(target)) return target;
526
297
 
527
298
  const keys = split$1(path, options);
528
299
  let obj = target;
@@ -543,7 +314,7 @@ const setValue = (target, path, value, options) => {
543
314
  continue;
544
315
  }
545
316
 
546
- if (!isObject$1(obj[key])) {
317
+ if (!isObject$2(obj[key])) {
547
318
  obj[key] = {};
548
319
  }
549
320
 
@@ -570,10 +341,10 @@ const set = /*@__PURE__*/getDefaultExportFromCjs(setValue_1);
570
341
  * Released under the MIT License.
571
342
  */
572
343
 
573
- const isObject = isobject;
344
+ const isObject$1 = isobject;
574
345
 
575
346
  var getValue = function(target, path, options) {
576
- if (!isObject(options)) {
347
+ if (!isObject$1(options)) {
577
348
  options = { default: options };
578
349
  }
579
350
 
@@ -671,11 +442,309 @@ function isValid(key, target, options) {
671
442
  }
672
443
 
673
444
  function isValidObject(val) {
674
- return isObject(val) || Array.isArray(val) || typeof val === 'function';
445
+ return isObject$1(val) || Array.isArray(val) || typeof val === 'function';
675
446
  }
676
447
 
677
448
  const get = /*@__PURE__*/getDefaultExportFromCjs(getValue);
678
449
 
450
+ function isObject(x) {
451
+ return typeof x === "object" && x !== null;
452
+ }
453
+
454
+ function isSassLang(lang) {
455
+ return lang === "scss" || lang === "sass";
456
+ }
457
+ function isLessLang(lang) {
458
+ return lang === "less";
459
+ }
460
+ function isTsLang(lang) {
461
+ return lang === "ts";
462
+ }
463
+ async function getTasks(options) {
464
+ let { typescriptOptions } = options;
465
+ const { root: cwd, weappTailwindcssOptions, outDir, src: srcBase, extensions, exclude, include, postcssOptions, preprocessorOptions } = options;
466
+ const globsSet = /* @__PURE__ */ new Set();
467
+ const base = srcBase ? srcBase + "/" : "";
468
+ const enableSass = Boolean(preprocessorOptions?.sass);
469
+ const enableLess = Boolean(preprocessorOptions?.less);
470
+ if (typescriptOptions === true) {
471
+ typescriptOptions = {
472
+ tsConfigFileName: "tsconfig.json"
473
+ };
474
+ } else if (isObject(typescriptOptions) && typescriptOptions.tsConfigFileName === void 0) {
475
+ typescriptOptions.tsConfigFileName = "tsconfig.json";
476
+ }
477
+ const enableTs = Boolean(typescriptOptions);
478
+ let sass;
479
+ if (enableSass) {
480
+ const sassLib = await import('sass');
481
+ sass = createSass__default(sassLib);
482
+ }
483
+ const { transformJs, transformWxml, transformWxss } = gulp.createPlugins(weappTailwindcssOptions);
484
+ function globsSetAdd(...value) {
485
+ for (const v of value) {
486
+ if (Array.isArray(v)) {
487
+ for (const vv of v) {
488
+ globsSet.add(vv);
489
+ }
490
+ } else {
491
+ globsSet.add(v);
492
+ }
493
+ }
494
+ }
495
+ function getGlobs(type) {
496
+ const globs = [];
497
+ if (typeof include === "function") {
498
+ globs.push(...include(type).map((x) => x));
499
+ }
500
+ if (typeof exclude === "function") {
501
+ globs.push(...exclude(type).map((x) => "!" + x));
502
+ } else if (Array.isArray(exclude)) {
503
+ globs.push(...exclude.map((x) => "!" + x));
504
+ }
505
+ globs.push(`!${outDir}/**/*`);
506
+ return globs;
507
+ }
508
+ function getJsTasks() {
509
+ const assetType = AssetType.JavaScript;
510
+ const globs = getGlobs(assetType);
511
+ globsSetAdd(globs);
512
+ return extensions[assetType]?.map((x) => {
513
+ const src = `${base}**/*.${x}`;
514
+ globsSetAdd(src);
515
+ const isTs = isTsLang(x);
516
+ const loadTs = enableTs && isTs;
517
+ let gulpTs;
518
+ if (enableTs && typeof typescriptOptions !== "boolean") {
519
+ gulpTs = typescript__default.createProject(typescriptOptions.tsConfigFileName ?? "tsconfig.json", typeof typescriptOptions === "boolean" ? {} : typescriptOptions);
520
+ }
521
+ return function JsTask() {
522
+ let chain = gulp__default.src([src, ...globs], { cwd, since: gulp__default.lastRun(JsTask) }).pipe(plumber__default());
523
+ if (loadTs) {
524
+ chain = chain.pipe(gulpTs());
525
+ }
526
+ return chain.pipe(
527
+ transformJs({
528
+ babelParserOptions: !enableTs && isTs ? {
529
+ plugins: ["typescript"]
530
+ } : void 0
531
+ })
532
+ ).pipe(
533
+ gulpif__default(
534
+ loadTs,
535
+ rename__default({
536
+ extname: ".js"
537
+ })
538
+ )
539
+ ).pipe(
540
+ gulp__default.dest(outDir, {
541
+ cwd
542
+ })
543
+ );
544
+ };
545
+ });
546
+ }
547
+ function getJsonTasks() {
548
+ const assetType = AssetType.Json;
549
+ const globs = getGlobs(assetType);
550
+ globsSetAdd(globs);
551
+ return extensions[assetType]?.map((x) => {
552
+ const src = `${base}**/*.${x}`;
553
+ globsSetAdd(src);
554
+ return function JsonTask() {
555
+ return gulp__default.src([src, ...globs], { cwd, since: gulp__default.lastRun(JsonTask) }).pipe(plumber__default()).pipe(
556
+ gulp__default.dest(outDir, {
557
+ cwd
558
+ })
559
+ );
560
+ };
561
+ });
562
+ }
563
+ function getCssTasks() {
564
+ const assetType = AssetType.Css;
565
+ const globs = getGlobs(assetType);
566
+ globsSetAdd(globs);
567
+ return extensions[assetType]?.map((x) => {
568
+ const src = `${base}**/*.${x}`;
569
+ globsSetAdd(src);
570
+ const loadSass = enableSass && isSassLang(x);
571
+ const loadLess = enableLess && isLessLang(x);
572
+ return function CssTask() {
573
+ let chain = gulp__default.src([src, ...globs], { cwd, since: gulp__default.lastRun(CssTask) }).pipe(plumber__default());
574
+ if (loadSass) {
575
+ chain = chain.pipe(
576
+ sass.sync(
577
+ // @ts-ignore
578
+ typeof preprocessorOptions?.sass === "boolean" ? void 0 : preprocessorOptions?.sass
579
+ ).on("error", sass.logError)
580
+ );
581
+ }
582
+ return 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(
583
+ gulpif__default(
584
+ loadSass || loadLess,
585
+ rename__default({
586
+ extname: ".wxss"
587
+ })
588
+ )
589
+ ).pipe(
590
+ gulp__default.dest(outDir, {
591
+ cwd
592
+ })
593
+ );
594
+ };
595
+ });
596
+ }
597
+ function getHtmlTasks() {
598
+ const assetType = AssetType.Html;
599
+ const globs = getGlobs(assetType);
600
+ globsSetAdd(globs);
601
+ return extensions[assetType]?.map((x) => {
602
+ const src = `${base}**/*.${x}`;
603
+ globsSetAdd(src);
604
+ return function HtmlTask() {
605
+ return gulp__default.src([src, ...globs], { cwd, since: gulp__default.lastRun(HtmlTask) }).pipe(plumber__default()).pipe(transformWxml()).pipe(
606
+ gulp__default.dest(outDir, {
607
+ cwd
608
+ })
609
+ );
610
+ };
611
+ });
612
+ }
613
+ function copyOthers() {
614
+ if (Array.isArray(include)) {
615
+ const globs = include.map((x) => {
616
+ return `${base}${x}`;
617
+ });
618
+ globsSetAdd(globs);
619
+ return gulp__default.src(globs, { cwd, since: gulp__default.lastRun(copyOthers) }).pipe(plumber__default()).pipe(
620
+ gulp__default.dest(outDir, {
621
+ cwd
622
+ })
623
+ );
624
+ }
625
+ }
626
+ return {
627
+ getGlobs,
628
+ getJsTasks,
629
+ getJsonTasks,
630
+ getCssTasks,
631
+ getHtmlTasks,
632
+ copyOthers,
633
+ globsSet
634
+ };
635
+ }
636
+
637
+ const defaultJavascriptExtensions = ["js"];
638
+ const defaultTypescriptExtensions = ["ts"];
639
+ const defaultWxsExtensions = ["wxs"];
640
+ const defaultNodeModulesDirs = [
641
+ "**/node_modules/**",
642
+ "**/miniprogram_npm/**",
643
+ "**/project.config.json/**",
644
+ "**/project.private.config.json/**",
645
+ "**/package.json/**",
646
+ "postcss.config.js",
647
+ "tailwind.config.js"
648
+ ];
649
+ async function createBuilder(options) {
650
+ let postcssOptionsFromConfig;
651
+ try {
652
+ postcssOptionsFromConfig = await loadPostcssConfig__default({ cwd: options?.root });
653
+ } catch {
654
+ }
655
+ const opt = defu(options, {
656
+ outDir: "dist",
657
+ weappTailwindcssOptions: {},
658
+ clean: true,
659
+ src: "",
660
+ exclude: [...defaultNodeModulesDirs],
661
+ extensions: {
662
+ javascript: [...defaultJavascriptExtensions, ...defaultTypescriptExtensions, ...defaultWxsExtensions],
663
+ html: ["wxml"],
664
+ css: ["wxss", "less", "sass", "scss"],
665
+ json: ["json"]
666
+ },
667
+ watchOptions: {
668
+ events: ["add", "change", "unlink", "ready"]
669
+ },
670
+ postcssOptions: postcssOptionsFromConfig
671
+ });
672
+ const { copyOthers, getCssTasks, getHtmlTasks, getJsTasks, getJsonTasks, globsSet } = await getTasks(opt);
673
+ const tasks = {
674
+ css: getCssTasks(),
675
+ html: getHtmlTasks(),
676
+ json: getJsonTasks(),
677
+ js: getJsTasks(),
678
+ extra: [copyOthers]
679
+ };
680
+ async function runTasks() {
681
+ debug("run tasks start");
682
+ for (const [key, value] of Object.entries(tasks)) {
683
+ if (value) {
684
+ debug(`run task ${pc__default.bold(pc__default.green(key))} start`);
685
+ for (const task of value) {
686
+ const s = task();
687
+ if (s) {
688
+ await new Promise((resolve, reject) => s.on("finish", resolve).on("error", reject));
689
+ }
690
+ }
691
+ debug(`run task ${pc__default.bold(pc__default.green(key))} end`);
692
+ }
693
+ }
694
+ debug("run tasks end");
695
+ }
696
+ const { clean, outDir, root: cwd, watchOptions } = opt;
697
+ return {
698
+ watcher: void 0,
699
+ async build() {
700
+ if (clean) {
701
+ debug("del start");
702
+ const { deleteAsync } = await import('del');
703
+ const patterns = [outDir + "/**"];
704
+ await deleteAsync(patterns, { cwd, ignore: defaultNodeModulesDirs });
705
+ debug("del end");
706
+ }
707
+ fs.ensureDirSync(path__default.resolve(cwd, outDir));
708
+ await runTasks();
709
+ return this;
710
+ },
711
+ watch() {
712
+ fs.ensureDirSync(path__default.resolve(cwd, outDir));
713
+ const watcher = gulp__default.watch([...globsSet], watchOptions, async (cb) => {
714
+ try {
715
+ await runTasks();
716
+ cb();
717
+ } catch (error) {
718
+ cb(error);
719
+ }
720
+ });
721
+ watcher.on("change", function(path2) {
722
+ console.log(`${pc__default.green("changed")} ${path2}`);
723
+ });
724
+ watcher.on("add", function(path2) {
725
+ console.log(`${pc__default.green("add")} ${path2}`);
726
+ });
727
+ watcher.on("unlink", function(path2) {
728
+ console.log(`${pc__default.green("remove")} ${path2}`);
729
+ });
730
+ watcher.on("ready", function() {
731
+ console.log(`${pc__default.green("weapp")}-${pc__default.blue("tailwindcss")} is ready!`);
732
+ });
733
+ this.watcher = watcher;
734
+ return this;
735
+ },
736
+ globsSet
737
+ };
738
+ }
739
+ async function build(options) {
740
+ const builder = await createBuilder(options);
741
+ return await builder.build();
742
+ }
743
+ async function watch(options) {
744
+ const builder = await createBuilder(options);
745
+ return await builder.watch();
746
+ }
747
+
679
748
  function createConfigLoader(root) {
680
749
  const explorer = cosmiconfig.cosmiconfigSync("weapp-tw");
681
750
  function search(searchFrom = root) {
@@ -697,7 +766,7 @@ function getDefaultConfig(root) {
697
766
  return {
698
767
  outDir: "dist",
699
768
  root,
700
- srcDir: "."
769
+ src: "."
701
770
  };
702
771
  }
703
772
  function defineConfig(options) {
@@ -760,13 +829,18 @@ function initConfig(options) {
760
829
  const { lang, root } = defu(options, { lang: "js", root: process.cwd() });
761
830
  const configFilename = `weapp-tw.config.${lang ?? "js"}`;
762
831
  const configPath = path__default.resolve(root, configFilename);
832
+ const tsconfigPath = path__default.resolve(root, "tsconfig.json");
833
+ const isTsconfigExisted = fs__default.existsSync(tsconfigPath);
763
834
  fs__default.ensureDirSync(root);
835
+ const configOptionsStr = isTsconfigExisted ? `{
836
+ src: './miniprogram'
837
+ }` : "{}";
764
838
  if (lang === "ts") {
765
839
  fs__default.writeFileSync(
766
840
  configPath,
767
841
  `import { defineConfig } from '@weapp-tailwindcss/cli'
768
842
 
769
- export default defineConfig({})
843
+ export default defineConfig(${configOptionsStr})
770
844
  `,
771
845
  "utf8"
772
846
  );
@@ -774,7 +848,7 @@ export default defineConfig({})
774
848
  fs__default.writeFileSync(
775
849
  configPath,
776
850
  `/** @type {import('@weapp-tailwindcss/cli').UserConfig} */
777
- module.exports = {}
851
+ module.exports = ${configOptionsStr}
778
852
  `,
779
853
  "utf8"
780
854
  );