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

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
@@ -1,19 +1,29 @@
1
1
  'use strict';
2
2
 
3
3
  const commander = require('commander');
4
- const loadPostcssConfig = require('postcss-load-config');
5
4
  const path = require('node:path');
6
5
  const fs = require('fs-extra');
7
6
  const gulp$1 = require('gulp');
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');
11
+ const postcssrc = require('gulp-postcss');
12
+ const plumber = require('gulp-plumber');
13
+ const gulpif = require('gulp-if');
9
14
  const cosmiconfig = require('cosmiconfig');
10
15
 
11
16
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
12
17
 
13
- const loadPostcssConfig__default = /*#__PURE__*/_interopDefaultCompat(loadPostcssConfig);
14
18
  const path__default = /*#__PURE__*/_interopDefaultCompat(path);
15
19
  const fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
16
20
  const gulp__default = /*#__PURE__*/_interopDefaultCompat(gulp$1);
21
+ const loadPostcssConfig__default = /*#__PURE__*/_interopDefaultCompat(loadPostcssConfig);
22
+ const pc__default = /*#__PURE__*/_interopDefaultCompat(pc);
23
+ const createDebug__default = /*#__PURE__*/_interopDefaultCompat(createDebug);
24
+ const postcssrc__default = /*#__PURE__*/_interopDefaultCompat(postcssrc);
25
+ const plumber__default = /*#__PURE__*/_interopDefaultCompat(plumber);
26
+ const gulpif__default = /*#__PURE__*/_interopDefaultCompat(gulpif);
17
27
 
18
28
  function isPlainObject$2(value) {
19
29
  if (value === null || typeof value !== "object") {
@@ -71,6 +81,8 @@ function createDefu(merger) {
71
81
  }
72
82
  const defu = createDefu();
73
83
 
84
+ const debug = createDebug__default("weapp-tw-cli");
85
+
74
86
  var AssetType = /* @__PURE__ */ ((AssetType2) => {
75
87
  AssetType2["JavaScript"] = "javascript";
76
88
  AssetType2["Json"] = "json";
@@ -80,7 +92,7 @@ var AssetType = /* @__PURE__ */ ((AssetType2) => {
80
92
  })(AssetType || {});
81
93
 
82
94
  function getTasks(options) {
83
- const { root: cwd, weappTailwindcssOptions, outDir, src: srcBase, extensions, exclude, include } = options;
95
+ const { root: cwd, weappTailwindcssOptions, outDir, src: srcBase, extensions, exclude, include, postcssOptions } = options;
84
96
  const globsSet = /* @__PURE__ */ new Set();
85
97
  const base = srcBase ? srcBase + "/" : "";
86
98
  function globsSetAdd(...value) {
@@ -116,7 +128,7 @@ function getTasks(options) {
116
128
  const src = `${base}**/*.${x}`;
117
129
  globsSetAdd(src);
118
130
  return function JsTask() {
119
- return gulp__default.src([src, ...globs], { cwd, since: gulp__default.lastRun(JsTask) }).pipe(
131
+ return gulp__default.src([src, ...globs], { cwd, since: gulp__default.lastRun(JsTask) }).pipe(plumber__default()).pipe(
120
132
  transformJs({
121
133
  babelParserOptions: x === "ts" ? {
122
134
  plugins: ["typescript"]
@@ -138,7 +150,7 @@ function getTasks(options) {
138
150
  const src = `${base}**/*.${x}`;
139
151
  globsSetAdd(src);
140
152
  return function JsonTask() {
141
- return gulp__default.src([src, ...globs], { cwd, since: gulp__default.lastRun(JsonTask) }).pipe(
153
+ return gulp__default.src([src, ...globs], { cwd, since: gulp__default.lastRun(JsonTask) }).pipe(plumber__default()).pipe(
142
154
  gulp__default.dest(outDir, {
143
155
  cwd
144
156
  })
@@ -154,7 +166,7 @@ function getTasks(options) {
154
166
  const src = `${base}**/*.${x}`;
155
167
  globsSetAdd(src);
156
168
  return function CssTask() {
157
- return gulp__default.src([src, ...globs], { cwd, since: gulp__default.lastRun(CssTask) }).pipe(transformWxss()).pipe(
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(
158
170
  gulp__default.dest(outDir, {
159
171
  cwd
160
172
  })
@@ -170,7 +182,7 @@ function getTasks(options) {
170
182
  const src = `${base}**/*.${x}`;
171
183
  globsSetAdd(src);
172
184
  return function HtmlTask() {
173
- return gulp__default.src([src, ...globs], { cwd, since: gulp__default.lastRun(HtmlTask) }).pipe(transformWxml()).pipe(
185
+ return gulp__default.src([src, ...globs], { cwd, since: gulp__default.lastRun(HtmlTask) }).pipe(plumber__default()).pipe(transformWxml()).pipe(
174
186
  gulp__default.dest(outDir, {
175
187
  cwd
176
188
  })
@@ -184,7 +196,7 @@ function getTasks(options) {
184
196
  return `${base}${x}`;
185
197
  });
186
198
  globsSetAdd(globs);
187
- return gulp__default.src(globs, { cwd, since: gulp__default.lastRun(copyOthers) }).pipe(
199
+ return gulp__default.src(globs, { cwd, since: gulp__default.lastRun(copyOthers) }).pipe(plumber__default()).pipe(
188
200
  gulp__default.dest(outDir, {
189
201
  cwd
190
202
  })
@@ -224,7 +236,8 @@ function createBuilder(options) {
224
236
  extensions,
225
237
  exclude,
226
238
  include,
227
- watchOptions
239
+ watchOptions,
240
+ postcssOptions
228
241
  } = defu(options, {
229
242
  outDir: "dist",
230
243
  weappTailwindcssOptions: {},
@@ -250,24 +263,39 @@ function createBuilder(options) {
250
263
  extensions,
251
264
  exclude,
252
265
  include,
253
- watchOptions
266
+ watchOptions,
267
+ postcssOptions
254
268
  });
255
- const tasks = [...getJsTasks(), ...getJsonTasks(), ...getCssTasks(), ...getHtmlTasks(), copyOthers];
269
+ const tasks = {
270
+ css: getCssTasks(),
271
+ html: getHtmlTasks(),
272
+ json: getJsonTasks(),
273
+ js: getJsTasks(),
274
+ extra: [copyOthers]
275
+ };
256
276
  async function runTasks() {
257
- for (const task of tasks) {
258
- const s = task();
259
- if (s) {
260
- await new Promise((resolve, reject) => s.on("finish", resolve).on("error", reject));
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
+ }
261
285
  }
286
+ debug(`run task ${pc__default.bold(pc__default.green(key))} end`);
262
287
  }
288
+ debug("run tasks end");
263
289
  }
264
290
  return {
265
291
  watcher: void 0,
266
292
  async build() {
267
293
  if (clean) {
294
+ debug("del start");
268
295
  const { deleteAsync } = await import('del');
269
296
  const patterns = [outDir + "/**"];
270
297
  await deleteAsync(patterns, { cwd, ignore: defaultNodeModulesDirs });
298
+ debug("del end");
271
299
  }
272
300
  fs.ensureDirSync(path__default.resolve(cwd, outDir));
273
301
  await runTasks();
@@ -284,16 +312,16 @@ function createBuilder(options) {
284
312
  }
285
313
  });
286
314
  watcher.on("change", function(path2) {
287
- console.log(`File ${path2} was changed`);
315
+ console.log(`${pc__default.green("changed")} ${path2}`);
288
316
  });
289
317
  watcher.on("add", function(path2) {
290
- console.log(`File ${path2} was added`);
318
+ console.log(`${pc__default.green("add")} ${path2}`);
291
319
  });
292
320
  watcher.on("unlink", function(path2) {
293
- console.log(`File ${path2} was removed`);
321
+ console.log(`${pc__default.green("remove")} ${path2}`);
294
322
  });
295
323
  watcher.on("ready", function() {
296
- console.log(`Weapp-tailwindcss is Ready!`);
324
+ console.log(`${pc__default.green("weapp")}-${pc__default.blue("tailwindcss")} is ready!`);
297
325
  });
298
326
  this.watcher = watcher;
299
327
  return this;
@@ -301,13 +329,23 @@ function createBuilder(options) {
301
329
  globsSet
302
330
  };
303
331
  }
304
- function build(options) {
305
- const builder = createBuilder(options);
306
- return builder.build();
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();
307
340
  }
308
- function watch(options) {
309
- const builder = createBuilder(options);
310
- return builder.watch();
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();
311
349
  }
312
350
 
313
351
  function getDefaultExportFromCjs (x) {
@@ -679,7 +717,7 @@ function getDefaultConfig(root) {
679
717
  return {
680
718
  outDir: "dist",
681
719
  root,
682
- srcDir: "."
720
+ src: "."
683
721
  };
684
722
  }
685
723
  function defineConfig(options) {
@@ -742,13 +780,18 @@ function initConfig(options) {
742
780
  const { lang, root } = defu(options, { lang: "js", root: process.cwd() });
743
781
  const configFilename = `weapp-tw.config.${lang ?? "js"}`;
744
782
  const configPath = path__default.resolve(root, configFilename);
783
+ const tsconfigPath = path__default.resolve(root, "tsconfig.json");
784
+ const isTsconfigExisted = fs__default.existsSync(tsconfigPath);
745
785
  fs__default.ensureDirSync(root);
786
+ const configOptionsStr = isTsconfigExisted ? `{
787
+ src: './miniprogram'
788
+ }` : "{}";
746
789
  if (lang === "ts") {
747
790
  fs__default.writeFileSync(
748
791
  configPath,
749
792
  `import { defineConfig } from '@weapp-tailwindcss/cli'
750
793
 
751
- export default defineConfig({})
794
+ export default defineConfig(${configOptionsStr})
752
795
  `,
753
796
  "utf8"
754
797
  );
@@ -756,7 +799,7 @@ export default defineConfig({})
756
799
  fs__default.writeFileSync(
757
800
  configPath,
758
801
  `/** @type {import('@weapp-tailwindcss/cli').UserConfig} */
759
- module.exports = {}
802
+ module.exports = ${configOptionsStr}
760
803
  `,
761
804
  "utf8"
762
805
  );
@@ -773,28 +816,16 @@ function createCli() {
773
816
  const configLoader = createConfigLoader(cwd);
774
817
  const userDefinedConfig = configLoader.search(cwd);
775
818
  program.command("dev").alias("serve").action(async () => {
776
- const postcssOptions = await loadPostcssConfig__default({
777
- cwd
778
- });
779
819
  await watch(
780
820
  defu(userDefinedConfig?.config, {
781
- root: cwd,
782
- weappTailwindcssOptions: {
783
- postcssOptions
784
- }
821
+ root: cwd
785
822
  })
786
823
  );
787
824
  });
788
825
  program.command("build").action(async () => {
789
- const postcssOptions = await loadPostcssConfig__default({
790
- cwd
791
- });
792
826
  await build(
793
827
  defu(userDefinedConfig?.config, {
794
- root: cwd,
795
- weappTailwindcssOptions: {
796
- postcssOptions
797
- }
828
+ root: cwd
798
829
  })
799
830
  );
800
831
  });
package/dist/index.d.cts CHANGED
@@ -2,6 +2,7 @@ import { Command } from 'commander';
2
2
  import { FSWatcher } from 'fs-extra';
3
3
  import { UserDefinedOptions } from 'weapp-tailwindcss';
4
4
  import { WatchOptions } from 'gulp';
5
+ import { Result } from 'postcss-load-config';
5
6
  import * as cosmiconfig from 'cosmiconfig';
6
7
 
7
8
  declare function createCli(): Command;
@@ -22,13 +23,15 @@ interface BuildOptions {
22
23
  exclude: string[] | ((type: AssetType) => string[]);
23
24
  include: string[] | ((type: AssetType) => string[]);
24
25
  extensions: {
25
- javascript: string[];
26
- html: string[];
27
- css: string[];
28
- json: string[];
26
+ javascript?: string[];
27
+ html?: string[];
28
+ css?: string[];
29
+ json?: string[];
29
30
  };
31
+ postcssOptions?: Partial<Omit<Result, 'file'>>;
30
32
  watchOptions: WatchOptions;
31
33
  }
34
+ type UserConfig = Partial<BuildOptions>;
32
35
 
33
36
  declare function createBuilder(options?: Partial<BuildOptions>): {
34
37
  watcher: FSWatcher | undefined;
@@ -42,15 +45,15 @@ declare function build(options?: Partial<BuildOptions>): Promise<{
42
45
  watch(): any;
43
46
  globsSet: Set<string>;
44
47
  }>;
45
- declare function watch(options?: Partial<BuildOptions>): {
48
+ declare function watch(options?: Partial<BuildOptions>): Promise<{
46
49
  watcher: FSWatcher | undefined;
47
50
  build(): Promise<any>;
48
51
  watch(): any;
49
52
  globsSet: Set<string>;
50
- };
53
+ }>;
51
54
 
52
55
  type WeappTwCosmiconfigResult = {
53
- config: UserConfig;
56
+ config: BuildOptions;
54
57
  filepath: string;
55
58
  isEmpty?: boolean;
56
59
  };
@@ -58,13 +61,6 @@ declare function createConfigLoader(root: string): {
58
61
  search: (searchFrom?: string) => WeappTwCosmiconfigResult | undefined;
59
62
  load: (filepath: string) => cosmiconfig.CosmiconfigResult;
60
63
  };
61
- type UserConfig = {
62
- outDir?: string;
63
- root?: string;
64
- srcDir?: string;
65
- weappTailwindcssOptions?: UserDefinedOptions;
66
- clean?: boolean;
67
- };
68
- declare function defineConfig(options: UserConfig): UserConfig;
64
+ declare function defineConfig(options: Partial<BuildOptions>): Partial<BuildOptions>;
69
65
 
70
66
  export { type UserConfig, build, createBuilder, createCli, createConfigLoader, defineConfig, watch };
package/dist/index.d.mts CHANGED
@@ -2,6 +2,7 @@ import { Command } from 'commander';
2
2
  import { FSWatcher } from 'fs-extra';
3
3
  import { UserDefinedOptions } from 'weapp-tailwindcss';
4
4
  import { WatchOptions } from 'gulp';
5
+ import { Result } from 'postcss-load-config';
5
6
  import * as cosmiconfig from 'cosmiconfig';
6
7
 
7
8
  declare function createCli(): Command;
@@ -22,13 +23,15 @@ interface BuildOptions {
22
23
  exclude: string[] | ((type: AssetType) => string[]);
23
24
  include: string[] | ((type: AssetType) => string[]);
24
25
  extensions: {
25
- javascript: string[];
26
- html: string[];
27
- css: string[];
28
- json: string[];
26
+ javascript?: string[];
27
+ html?: string[];
28
+ css?: string[];
29
+ json?: string[];
29
30
  };
31
+ postcssOptions?: Partial<Omit<Result, 'file'>>;
30
32
  watchOptions: WatchOptions;
31
33
  }
34
+ type UserConfig = Partial<BuildOptions>;
32
35
 
33
36
  declare function createBuilder(options?: Partial<BuildOptions>): {
34
37
  watcher: FSWatcher | undefined;
@@ -42,15 +45,15 @@ declare function build(options?: Partial<BuildOptions>): Promise<{
42
45
  watch(): any;
43
46
  globsSet: Set<string>;
44
47
  }>;
45
- declare function watch(options?: Partial<BuildOptions>): {
48
+ declare function watch(options?: Partial<BuildOptions>): Promise<{
46
49
  watcher: FSWatcher | undefined;
47
50
  build(): Promise<any>;
48
51
  watch(): any;
49
52
  globsSet: Set<string>;
50
- };
53
+ }>;
51
54
 
52
55
  type WeappTwCosmiconfigResult = {
53
- config: UserConfig;
56
+ config: BuildOptions;
54
57
  filepath: string;
55
58
  isEmpty?: boolean;
56
59
  };
@@ -58,13 +61,6 @@ declare function createConfigLoader(root: string): {
58
61
  search: (searchFrom?: string) => WeappTwCosmiconfigResult | undefined;
59
62
  load: (filepath: string) => cosmiconfig.CosmiconfigResult;
60
63
  };
61
- type UserConfig = {
62
- outDir?: string;
63
- root?: string;
64
- srcDir?: string;
65
- weappTailwindcssOptions?: UserDefinedOptions;
66
- clean?: boolean;
67
- };
68
- declare function defineConfig(options: UserConfig): UserConfig;
64
+ declare function defineConfig(options: Partial<BuildOptions>): Partial<BuildOptions>;
69
65
 
70
66
  export { type UserConfig, build, createBuilder, createCli, createConfigLoader, defineConfig, watch };
package/dist/index.d.ts CHANGED
@@ -2,6 +2,7 @@ import { Command } from 'commander';
2
2
  import { FSWatcher } from 'fs-extra';
3
3
  import { UserDefinedOptions } from 'weapp-tailwindcss';
4
4
  import { WatchOptions } from 'gulp';
5
+ import { Result } from 'postcss-load-config';
5
6
  import * as cosmiconfig from 'cosmiconfig';
6
7
 
7
8
  declare function createCli(): Command;
@@ -22,13 +23,15 @@ interface BuildOptions {
22
23
  exclude: string[] | ((type: AssetType) => string[]);
23
24
  include: string[] | ((type: AssetType) => string[]);
24
25
  extensions: {
25
- javascript: string[];
26
- html: string[];
27
- css: string[];
28
- json: string[];
26
+ javascript?: string[];
27
+ html?: string[];
28
+ css?: string[];
29
+ json?: string[];
29
30
  };
31
+ postcssOptions?: Partial<Omit<Result, 'file'>>;
30
32
  watchOptions: WatchOptions;
31
33
  }
34
+ type UserConfig = Partial<BuildOptions>;
32
35
 
33
36
  declare function createBuilder(options?: Partial<BuildOptions>): {
34
37
  watcher: FSWatcher | undefined;
@@ -42,15 +45,15 @@ declare function build(options?: Partial<BuildOptions>): Promise<{
42
45
  watch(): any;
43
46
  globsSet: Set<string>;
44
47
  }>;
45
- declare function watch(options?: Partial<BuildOptions>): {
48
+ declare function watch(options?: Partial<BuildOptions>): Promise<{
46
49
  watcher: FSWatcher | undefined;
47
50
  build(): Promise<any>;
48
51
  watch(): any;
49
52
  globsSet: Set<string>;
50
- };
53
+ }>;
51
54
 
52
55
  type WeappTwCosmiconfigResult = {
53
- config: UserConfig;
56
+ config: BuildOptions;
54
57
  filepath: string;
55
58
  isEmpty?: boolean;
56
59
  };
@@ -58,13 +61,6 @@ declare function createConfigLoader(root: string): {
58
61
  search: (searchFrom?: string) => WeappTwCosmiconfigResult | undefined;
59
62
  load: (filepath: string) => cosmiconfig.CosmiconfigResult;
60
63
  };
61
- type UserConfig = {
62
- outDir?: string;
63
- root?: string;
64
- srcDir?: string;
65
- weappTailwindcssOptions?: UserDefinedOptions;
66
- clean?: boolean;
67
- };
68
- declare function defineConfig(options: UserConfig): UserConfig;
64
+ declare function defineConfig(options: Partial<BuildOptions>): Partial<BuildOptions>;
69
65
 
70
66
  export { type UserConfig, build, createBuilder, createCli, createConfigLoader, defineConfig, watch };
package/dist/index.mjs CHANGED
@@ -1,9 +1,14 @@
1
1
  import { Command } from 'commander';
2
- import loadPostcssConfig from 'postcss-load-config';
3
2
  import path from 'node:path';
4
3
  import fs, { ensureDirSync } from 'fs-extra';
5
4
  import gulp from 'gulp';
5
+ import loadPostcssConfig from 'postcss-load-config';
6
+ import pc from 'picocolors';
7
+ import createDebug from 'debug';
6
8
  import { createPlugins } from 'weapp-tailwindcss/gulp';
9
+ import postcssrc from 'gulp-postcss';
10
+ import plumber from 'gulp-plumber';
11
+ import gulpif from 'gulp-if';
7
12
  import { cosmiconfigSync } from 'cosmiconfig';
8
13
 
9
14
  function isPlainObject$2(value) {
@@ -62,6 +67,8 @@ function createDefu(merger) {
62
67
  }
63
68
  const defu = createDefu();
64
69
 
70
+ const debug = createDebug("weapp-tw-cli");
71
+
65
72
  var AssetType = /* @__PURE__ */ ((AssetType2) => {
66
73
  AssetType2["JavaScript"] = "javascript";
67
74
  AssetType2["Json"] = "json";
@@ -71,7 +78,7 @@ var AssetType = /* @__PURE__ */ ((AssetType2) => {
71
78
  })(AssetType || {});
72
79
 
73
80
  function getTasks(options) {
74
- const { root: cwd, weappTailwindcssOptions, outDir, src: srcBase, extensions, exclude, include } = options;
81
+ const { root: cwd, weappTailwindcssOptions, outDir, src: srcBase, extensions, exclude, include, postcssOptions } = options;
75
82
  const globsSet = /* @__PURE__ */ new Set();
76
83
  const base = srcBase ? srcBase + "/" : "";
77
84
  function globsSetAdd(...value) {
@@ -107,7 +114,7 @@ function getTasks(options) {
107
114
  const src = `${base}**/*.${x}`;
108
115
  globsSetAdd(src);
109
116
  return function JsTask() {
110
- return gulp.src([src, ...globs], { cwd, since: gulp.lastRun(JsTask) }).pipe(
117
+ return gulp.src([src, ...globs], { cwd, since: gulp.lastRun(JsTask) }).pipe(plumber()).pipe(
111
118
  transformJs({
112
119
  babelParserOptions: x === "ts" ? {
113
120
  plugins: ["typescript"]
@@ -129,7 +136,7 @@ function getTasks(options) {
129
136
  const src = `${base}**/*.${x}`;
130
137
  globsSetAdd(src);
131
138
  return function JsonTask() {
132
- return gulp.src([src, ...globs], { cwd, since: gulp.lastRun(JsonTask) }).pipe(
139
+ return gulp.src([src, ...globs], { cwd, since: gulp.lastRun(JsonTask) }).pipe(plumber()).pipe(
133
140
  gulp.dest(outDir, {
134
141
  cwd
135
142
  })
@@ -145,7 +152,7 @@ function getTasks(options) {
145
152
  const src = `${base}**/*.${x}`;
146
153
  globsSetAdd(src);
147
154
  return function CssTask() {
148
- return gulp.src([src, ...globs], { cwd, since: gulp.lastRun(CssTask) }).pipe(transformWxss()).pipe(
155
+ return gulp.src([src, ...globs], { cwd, since: gulp.lastRun(CssTask) }).pipe(plumber()).pipe(gulpif(Boolean(postcssOptions), postcssrc(postcssOptions?.plugins, postcssOptions?.options))).pipe(transformWxss()).pipe(
149
156
  gulp.dest(outDir, {
150
157
  cwd
151
158
  })
@@ -161,7 +168,7 @@ function getTasks(options) {
161
168
  const src = `${base}**/*.${x}`;
162
169
  globsSetAdd(src);
163
170
  return function HtmlTask() {
164
- return gulp.src([src, ...globs], { cwd, since: gulp.lastRun(HtmlTask) }).pipe(transformWxml()).pipe(
171
+ return gulp.src([src, ...globs], { cwd, since: gulp.lastRun(HtmlTask) }).pipe(plumber()).pipe(transformWxml()).pipe(
165
172
  gulp.dest(outDir, {
166
173
  cwd
167
174
  })
@@ -175,7 +182,7 @@ function getTasks(options) {
175
182
  return `${base}${x}`;
176
183
  });
177
184
  globsSetAdd(globs);
178
- return gulp.src(globs, { cwd, since: gulp.lastRun(copyOthers) }).pipe(
185
+ return gulp.src(globs, { cwd, since: gulp.lastRun(copyOthers) }).pipe(plumber()).pipe(
179
186
  gulp.dest(outDir, {
180
187
  cwd
181
188
  })
@@ -215,7 +222,8 @@ function createBuilder(options) {
215
222
  extensions,
216
223
  exclude,
217
224
  include,
218
- watchOptions
225
+ watchOptions,
226
+ postcssOptions
219
227
  } = defu(options, {
220
228
  outDir: "dist",
221
229
  weappTailwindcssOptions: {},
@@ -241,24 +249,39 @@ function createBuilder(options) {
241
249
  extensions,
242
250
  exclude,
243
251
  include,
244
- watchOptions
252
+ watchOptions,
253
+ postcssOptions
245
254
  });
246
- const tasks = [...getJsTasks(), ...getJsonTasks(), ...getCssTasks(), ...getHtmlTasks(), copyOthers];
255
+ const tasks = {
256
+ css: getCssTasks(),
257
+ html: getHtmlTasks(),
258
+ json: getJsonTasks(),
259
+ js: getJsTasks(),
260
+ extra: [copyOthers]
261
+ };
247
262
  async function runTasks() {
248
- for (const task of tasks) {
249
- const s = task();
250
- if (s) {
251
- await new Promise((resolve, reject) => s.on("finish", resolve).on("error", reject));
263
+ debug("run tasks start");
264
+ for (const [key, value] of Object.entries(tasks)) {
265
+ debug(`run task ${pc.bold(pc.green(key))} start`);
266
+ for (const task of value) {
267
+ const s = task();
268
+ if (s) {
269
+ await new Promise((resolve, reject) => s.on("finish", resolve).on("error", reject));
270
+ }
252
271
  }
272
+ debug(`run task ${pc.bold(pc.green(key))} end`);
253
273
  }
274
+ debug("run tasks end");
254
275
  }
255
276
  return {
256
277
  watcher: void 0,
257
278
  async build() {
258
279
  if (clean) {
280
+ debug("del start");
259
281
  const { deleteAsync } = await import('del');
260
282
  const patterns = [outDir + "/**"];
261
283
  await deleteAsync(patterns, { cwd, ignore: defaultNodeModulesDirs });
284
+ debug("del end");
262
285
  }
263
286
  ensureDirSync(path.resolve(cwd, outDir));
264
287
  await runTasks();
@@ -275,16 +298,16 @@ function createBuilder(options) {
275
298
  }
276
299
  });
277
300
  watcher.on("change", function(path2) {
278
- console.log(`File ${path2} was changed`);
301
+ console.log(`${pc.green("changed")} ${path2}`);
279
302
  });
280
303
  watcher.on("add", function(path2) {
281
- console.log(`File ${path2} was added`);
304
+ console.log(`${pc.green("add")} ${path2}`);
282
305
  });
283
306
  watcher.on("unlink", function(path2) {
284
- console.log(`File ${path2} was removed`);
307
+ console.log(`${pc.green("remove")} ${path2}`);
285
308
  });
286
309
  watcher.on("ready", function() {
287
- console.log(`Weapp-tailwindcss is Ready!`);
310
+ console.log(`${pc.green("weapp")}-${pc.blue("tailwindcss")} is ready!`);
288
311
  });
289
312
  this.watcher = watcher;
290
313
  return this;
@@ -292,13 +315,23 @@ function createBuilder(options) {
292
315
  globsSet
293
316
  };
294
317
  }
295
- function build(options) {
296
- const builder = createBuilder(options);
297
- return builder.build();
318
+ async function build(options) {
319
+ let postcssOptions;
320
+ try {
321
+ postcssOptions = await loadPostcssConfig({ cwd: options?.root });
322
+ } catch {
323
+ }
324
+ const builder = createBuilder(defu(options, { postcssOptions }));
325
+ return await builder.build();
298
326
  }
299
- function watch(options) {
300
- const builder = createBuilder(options);
301
- return builder.watch();
327
+ async function watch(options) {
328
+ let postcssOptions;
329
+ try {
330
+ postcssOptions = await loadPostcssConfig({ cwd: options?.root });
331
+ } catch {
332
+ }
333
+ const builder = createBuilder(defu(options, { postcssOptions }));
334
+ return await builder.watch();
302
335
  }
303
336
 
304
337
  function getDefaultExportFromCjs (x) {
@@ -670,7 +703,7 @@ function getDefaultConfig(root) {
670
703
  return {
671
704
  outDir: "dist",
672
705
  root,
673
- srcDir: "."
706
+ src: "."
674
707
  };
675
708
  }
676
709
  function defineConfig(options) {
@@ -733,13 +766,18 @@ function initConfig(options) {
733
766
  const { lang, root } = defu(options, { lang: "js", root: process.cwd() });
734
767
  const configFilename = `weapp-tw.config.${lang ?? "js"}`;
735
768
  const configPath = path.resolve(root, configFilename);
769
+ const tsconfigPath = path.resolve(root, "tsconfig.json");
770
+ const isTsconfigExisted = fs.existsSync(tsconfigPath);
736
771
  fs.ensureDirSync(root);
772
+ const configOptionsStr = isTsconfigExisted ? `{
773
+ src: './miniprogram'
774
+ }` : "{}";
737
775
  if (lang === "ts") {
738
776
  fs.writeFileSync(
739
777
  configPath,
740
778
  `import { defineConfig } from '@weapp-tailwindcss/cli'
741
779
 
742
- export default defineConfig({})
780
+ export default defineConfig(${configOptionsStr})
743
781
  `,
744
782
  "utf8"
745
783
  );
@@ -747,7 +785,7 @@ export default defineConfig({})
747
785
  fs.writeFileSync(
748
786
  configPath,
749
787
  `/** @type {import('@weapp-tailwindcss/cli').UserConfig} */
750
- module.exports = {}
788
+ module.exports = ${configOptionsStr}
751
789
  `,
752
790
  "utf8"
753
791
  );
@@ -764,28 +802,16 @@ function createCli() {
764
802
  const configLoader = createConfigLoader(cwd);
765
803
  const userDefinedConfig = configLoader.search(cwd);
766
804
  program.command("dev").alias("serve").action(async () => {
767
- const postcssOptions = await loadPostcssConfig({
768
- cwd
769
- });
770
805
  await watch(
771
806
  defu(userDefinedConfig?.config, {
772
- root: cwd,
773
- weappTailwindcssOptions: {
774
- postcssOptions
775
- }
807
+ root: cwd
776
808
  })
777
809
  );
778
810
  });
779
811
  program.command("build").action(async () => {
780
- const postcssOptions = await loadPostcssConfig({
781
- cwd
782
- });
783
812
  await build(
784
813
  defu(userDefinedConfig?.config, {
785
- root: cwd,
786
- weappTailwindcssOptions: {
787
- postcssOptions
788
- }
814
+ root: cwd
789
815
  })
790
816
  );
791
817
  });
package/package.json CHANGED
@@ -1,10 +1,19 @@
1
1
  {
2
2
  "name": "@weapp-tailwindcss/cli",
3
- "version": "0.0.0-alpha.4",
3
+ "version": "0.0.0-alpha.6",
4
4
  "description": "The cli of weapp-tailwindcss",
5
- "keywords": [],
6
- "author": "",
7
- "license": "ISC",
5
+ "keywords": [
6
+ "weapp",
7
+ "tailwindcss",
8
+ "cli",
9
+ "plugin"
10
+ ],
11
+ "author": "SonOfMagic <qq1324318532@gmail.com>",
12
+ "license": "MIT",
13
+ "bugs": {
14
+ "url": "https://github.com/sonofmagic/weapp-tailwindcss-webpack-plugin/issues"
15
+ },
16
+ "homepage": "https://weapp-tw.icebreaker.top",
8
17
  "sideEffects": false,
9
18
  "type": "commonjs",
10
19
  "exports": {
@@ -23,19 +32,31 @@
23
32
  "dependencies": {
24
33
  "commander": "^12.0.0",
25
34
  "cosmiconfig": "^9.0.0",
35
+ "debug": "4.3.4",
26
36
  "del": "^7.1.0",
27
37
  "fs-extra": "^11.2.0",
28
38
  "gulp": "^5.0.0",
39
+ "gulp-if": "^3.0.0",
29
40
  "gulp-less": "^5.0.0",
41
+ "gulp-plumber": "^1.2.1",
42
+ "gulp-postcss": "^10.0.0",
30
43
  "gulp-sass": "^5.1.0",
31
- "postcss-load-config": "^5.0.3",
32
- "weapp-tailwindcss": "3.2.0-alpha.3"
44
+ "picocolors": "^1.0.0",
45
+ "postcss": "^8.4.38",
46
+ "postcss-load-config": "^5.0.3"
47
+ },
48
+ "peerDependencies": {
49
+ "weapp-tailwindcss": "3.2.0-alpha.7"
33
50
  },
34
51
  "devDependencies": {
52
+ "@types/debug": "^4.1.12",
35
53
  "@types/fs-extra": "^11.0.4",
36
54
  "@types/get-value": "^3.0.5",
37
55
  "@types/gulp": "^4.0.17",
56
+ "@types/gulp-if": "^3.0.4",
38
57
  "@types/gulp-less": "^0.0.36",
58
+ "@types/gulp-plumber": "^0.0.37",
59
+ "@types/gulp-postcss": "^8.0.6",
39
60
  "@types/gulp-sass": "^5.0.4",
40
61
  "@types/set-value": "^4.0.3",
41
62
  "@types/vinyl-fs": "^3.0.5",