@weapp-tailwindcss/cli 0.0.0-alpha.1 → 0.0.0-alpha.3

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
@@ -4,8 +4,8 @@ const commander = require('commander');
4
4
  const loadPostcssConfig = require('postcss-load-config');
5
5
  const path = require('node:path');
6
6
  const fs = require('fs-extra');
7
- const gulp = require('weapp-tailwindcss/gulp');
8
7
  const gulp$1 = require('gulp');
8
+ const gulp = require('weapp-tailwindcss/gulp');
9
9
  const cosmiconfig = require('cosmiconfig');
10
10
 
11
11
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
@@ -215,7 +215,8 @@ function createBuilder(options) {
215
215
  clean,
216
216
  extensions,
217
217
  exclude,
218
- include
218
+ include,
219
+ watchOptions
219
220
  } = defu(options, {
220
221
  outDir: "dist",
221
222
  weappTailwindcssOptions: {},
@@ -237,27 +238,50 @@ function createBuilder(options) {
237
238
  clean,
238
239
  extensions,
239
240
  exclude,
240
- include
241
+ include,
242
+ watchOptions
241
243
  });
242
244
  const tasks = [...getJsTasks(), ...getJsonTasks(), ...getCssTasks(), ...getHtmlTasks(), copyOthers];
245
+ async function runTasks() {
246
+ for (const task of tasks) {
247
+ const s = task();
248
+ if (s) {
249
+ await new Promise((resolve, reject) => s.on("finish", resolve).on("error", reject));
250
+ }
251
+ }
252
+ }
243
253
  return {
254
+ watcher: void 0,
244
255
  async build() {
245
256
  if (clean) {
246
257
  const { deleteAsync } = await import('del');
247
258
  const patterns = [outDir + "/**"];
248
259
  await deleteAsync(patterns, { cwd, ignore: defaultNodeModulesDirs });
249
260
  }
250
- await fs.ensureDir(path__default.resolve(cwd, outDir));
251
- for (const task of tasks) {
252
- const s = task();
253
- if (s) {
254
- await new Promise((resolve, reject) => s.on("finish", resolve).on("error", reject));
255
- }
256
- }
261
+ fs.ensureDirSync(path__default.resolve(cwd, outDir));
262
+ await runTasks();
257
263
  return this;
258
264
  },
259
- async watch() {
260
- await fs.ensureDir(path__default.resolve(cwd, outDir));
265
+ watch() {
266
+ fs.ensureDirSync(path__default.resolve(cwd, outDir));
267
+ const watcher = gulp__default.watch([...globsSet], watchOptions, async (cb) => {
268
+ try {
269
+ await runTasks();
270
+ cb();
271
+ } catch (error) {
272
+ cb(error);
273
+ }
274
+ });
275
+ watcher.on("change", function(path2) {
276
+ console.log(`File ${path2} was changed`);
277
+ });
278
+ watcher.on("add", function(path2) {
279
+ console.log(`File ${path2} was added`);
280
+ });
281
+ watcher.on("unlink", function(path2) {
282
+ console.log(`File ${path2} was removed`);
283
+ });
284
+ this.watcher = watcher;
261
285
  return this;
262
286
  },
263
287
  globsSet
@@ -267,6 +291,10 @@ function build(options) {
267
291
  const builder = createBuilder(options);
268
292
  return builder.build();
269
293
  }
294
+ function watch(options) {
295
+ const builder = createBuilder(options);
296
+ return builder.watch();
297
+ }
270
298
 
271
299
  function getDefaultExportFromCjs (x) {
272
300
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
@@ -731,6 +759,17 @@ function createCli() {
731
759
  const configLoader = createConfigLoader(cwd);
732
760
  const userDefinedConfig = configLoader.search(cwd);
733
761
  program.command("dev").alias("serve").action(async () => {
762
+ const postcssOptions = await loadPostcssConfig__default({
763
+ cwd
764
+ });
765
+ await watch(
766
+ defu(userDefinedConfig?.config, {
767
+ root: cwd,
768
+ weappTailwindcssOptions: {
769
+ postcssOptions
770
+ }
771
+ })
772
+ );
734
773
  });
735
774
  program.command("build").action(async () => {
736
775
  const postcssOptions = await loadPostcssConfig__default({
@@ -758,3 +797,4 @@ exports.createBuilder = createBuilder;
758
797
  exports.createCli = createCli;
759
798
  exports.createConfigLoader = createConfigLoader;
760
799
  exports.defineConfig = defineConfig;
800
+ exports.watch = watch;
package/dist/index.d.cts CHANGED
@@ -1,5 +1,7 @@
1
1
  import { Command } from 'commander';
2
+ import { FSWatcher } from 'fs-extra';
2
3
  import { UserDefinedOptions } from 'weapp-tailwindcss';
4
+ import { WatchOptions } from 'gulp';
3
5
  import * as cosmiconfig from 'cosmiconfig';
4
6
 
5
7
  declare function createCli(): Command;
@@ -25,18 +27,27 @@ interface BuildOptions {
25
27
  css: string[];
26
28
  json: string[];
27
29
  };
30
+ watchOptions: WatchOptions;
28
31
  }
29
32
 
30
33
  declare function createBuilder(options?: Partial<BuildOptions>): {
34
+ watcher: FSWatcher | undefined;
31
35
  build(): Promise<any>;
32
- watch(): Promise<any>;
36
+ watch(): any;
33
37
  globsSet: Set<string>;
34
38
  };
35
39
  declare function build(options?: Partial<BuildOptions>): Promise<{
40
+ watcher: FSWatcher | undefined;
36
41
  build(): Promise<any>;
37
- watch(): Promise<any>;
42
+ watch(): any;
38
43
  globsSet: Set<string>;
39
44
  }>;
45
+ declare function watch(options?: Partial<BuildOptions>): {
46
+ watcher: FSWatcher | undefined;
47
+ build(): Promise<any>;
48
+ watch(): any;
49
+ globsSet: Set<string>;
50
+ };
40
51
 
41
52
  type WeappTwCosmiconfigResult = {
42
53
  config: UserConfig;
@@ -56,4 +67,4 @@ type UserConfig = {
56
67
  };
57
68
  declare function defineConfig(options: UserConfig): UserConfig;
58
69
 
59
- export { type UserConfig, build, createBuilder, createCli, createConfigLoader, defineConfig };
70
+ export { type UserConfig, build, createBuilder, createCli, createConfigLoader, defineConfig, watch };
package/dist/index.d.mts CHANGED
@@ -1,5 +1,7 @@
1
1
  import { Command } from 'commander';
2
+ import { FSWatcher } from 'fs-extra';
2
3
  import { UserDefinedOptions } from 'weapp-tailwindcss';
4
+ import { WatchOptions } from 'gulp';
3
5
  import * as cosmiconfig from 'cosmiconfig';
4
6
 
5
7
  declare function createCli(): Command;
@@ -25,18 +27,27 @@ interface BuildOptions {
25
27
  css: string[];
26
28
  json: string[];
27
29
  };
30
+ watchOptions: WatchOptions;
28
31
  }
29
32
 
30
33
  declare function createBuilder(options?: Partial<BuildOptions>): {
34
+ watcher: FSWatcher | undefined;
31
35
  build(): Promise<any>;
32
- watch(): Promise<any>;
36
+ watch(): any;
33
37
  globsSet: Set<string>;
34
38
  };
35
39
  declare function build(options?: Partial<BuildOptions>): Promise<{
40
+ watcher: FSWatcher | undefined;
36
41
  build(): Promise<any>;
37
- watch(): Promise<any>;
42
+ watch(): any;
38
43
  globsSet: Set<string>;
39
44
  }>;
45
+ declare function watch(options?: Partial<BuildOptions>): {
46
+ watcher: FSWatcher | undefined;
47
+ build(): Promise<any>;
48
+ watch(): any;
49
+ globsSet: Set<string>;
50
+ };
40
51
 
41
52
  type WeappTwCosmiconfigResult = {
42
53
  config: UserConfig;
@@ -56,4 +67,4 @@ type UserConfig = {
56
67
  };
57
68
  declare function defineConfig(options: UserConfig): UserConfig;
58
69
 
59
- export { type UserConfig, build, createBuilder, createCli, createConfigLoader, defineConfig };
70
+ export { type UserConfig, build, createBuilder, createCli, createConfigLoader, defineConfig, watch };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import { Command } from 'commander';
2
+ import { FSWatcher } from 'fs-extra';
2
3
  import { UserDefinedOptions } from 'weapp-tailwindcss';
4
+ import { WatchOptions } from 'gulp';
3
5
  import * as cosmiconfig from 'cosmiconfig';
4
6
 
5
7
  declare function createCli(): Command;
@@ -25,18 +27,27 @@ interface BuildOptions {
25
27
  css: string[];
26
28
  json: string[];
27
29
  };
30
+ watchOptions: WatchOptions;
28
31
  }
29
32
 
30
33
  declare function createBuilder(options?: Partial<BuildOptions>): {
34
+ watcher: FSWatcher | undefined;
31
35
  build(): Promise<any>;
32
- watch(): Promise<any>;
36
+ watch(): any;
33
37
  globsSet: Set<string>;
34
38
  };
35
39
  declare function build(options?: Partial<BuildOptions>): Promise<{
40
+ watcher: FSWatcher | undefined;
36
41
  build(): Promise<any>;
37
- watch(): Promise<any>;
42
+ watch(): any;
38
43
  globsSet: Set<string>;
39
44
  }>;
45
+ declare function watch(options?: Partial<BuildOptions>): {
46
+ watcher: FSWatcher | undefined;
47
+ build(): Promise<any>;
48
+ watch(): any;
49
+ globsSet: Set<string>;
50
+ };
40
51
 
41
52
  type WeappTwCosmiconfigResult = {
42
53
  config: UserConfig;
@@ -56,4 +67,4 @@ type UserConfig = {
56
67
  };
57
68
  declare function defineConfig(options: UserConfig): UserConfig;
58
69
 
59
- export { type UserConfig, build, createBuilder, createCli, createConfigLoader, defineConfig };
70
+ export { type UserConfig, build, createBuilder, createCli, createConfigLoader, defineConfig, watch };
package/dist/index.mjs CHANGED
@@ -1,9 +1,9 @@
1
1
  import { Command } from 'commander';
2
2
  import loadPostcssConfig from 'postcss-load-config';
3
3
  import path from 'node:path';
4
- import fs, { ensureDir } from 'fs-extra';
5
- import { createPlugins } from 'weapp-tailwindcss/gulp';
4
+ import fs, { ensureDirSync } from 'fs-extra';
6
5
  import gulp from 'gulp';
6
+ import { createPlugins } from 'weapp-tailwindcss/gulp';
7
7
  import { cosmiconfigSync } from 'cosmiconfig';
8
8
 
9
9
  function isPlainObject$2(value) {
@@ -206,7 +206,8 @@ function createBuilder(options) {
206
206
  clean,
207
207
  extensions,
208
208
  exclude,
209
- include
209
+ include,
210
+ watchOptions
210
211
  } = defu(options, {
211
212
  outDir: "dist",
212
213
  weappTailwindcssOptions: {},
@@ -228,27 +229,50 @@ function createBuilder(options) {
228
229
  clean,
229
230
  extensions,
230
231
  exclude,
231
- include
232
+ include,
233
+ watchOptions
232
234
  });
233
235
  const tasks = [...getJsTasks(), ...getJsonTasks(), ...getCssTasks(), ...getHtmlTasks(), copyOthers];
236
+ async function runTasks() {
237
+ for (const task of tasks) {
238
+ const s = task();
239
+ if (s) {
240
+ await new Promise((resolve, reject) => s.on("finish", resolve).on("error", reject));
241
+ }
242
+ }
243
+ }
234
244
  return {
245
+ watcher: void 0,
235
246
  async build() {
236
247
  if (clean) {
237
248
  const { deleteAsync } = await import('del');
238
249
  const patterns = [outDir + "/**"];
239
250
  await deleteAsync(patterns, { cwd, ignore: defaultNodeModulesDirs });
240
251
  }
241
- await ensureDir(path.resolve(cwd, outDir));
242
- for (const task of tasks) {
243
- const s = task();
244
- if (s) {
245
- await new Promise((resolve, reject) => s.on("finish", resolve).on("error", reject));
246
- }
247
- }
252
+ ensureDirSync(path.resolve(cwd, outDir));
253
+ await runTasks();
248
254
  return this;
249
255
  },
250
- async watch() {
251
- await ensureDir(path.resolve(cwd, outDir));
256
+ watch() {
257
+ ensureDirSync(path.resolve(cwd, outDir));
258
+ const watcher = gulp.watch([...globsSet], watchOptions, async (cb) => {
259
+ try {
260
+ await runTasks();
261
+ cb();
262
+ } catch (error) {
263
+ cb(error);
264
+ }
265
+ });
266
+ watcher.on("change", function(path2) {
267
+ console.log(`File ${path2} was changed`);
268
+ });
269
+ watcher.on("add", function(path2) {
270
+ console.log(`File ${path2} was added`);
271
+ });
272
+ watcher.on("unlink", function(path2) {
273
+ console.log(`File ${path2} was removed`);
274
+ });
275
+ this.watcher = watcher;
252
276
  return this;
253
277
  },
254
278
  globsSet
@@ -258,6 +282,10 @@ function build(options) {
258
282
  const builder = createBuilder(options);
259
283
  return builder.build();
260
284
  }
285
+ function watch(options) {
286
+ const builder = createBuilder(options);
287
+ return builder.watch();
288
+ }
261
289
 
262
290
  function getDefaultExportFromCjs (x) {
263
291
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
@@ -722,6 +750,17 @@ function createCli() {
722
750
  const configLoader = createConfigLoader(cwd);
723
751
  const userDefinedConfig = configLoader.search(cwd);
724
752
  program.command("dev").alias("serve").action(async () => {
753
+ const postcssOptions = await loadPostcssConfig({
754
+ cwd
755
+ });
756
+ await watch(
757
+ defu(userDefinedConfig?.config, {
758
+ root: cwd,
759
+ weappTailwindcssOptions: {
760
+ postcssOptions
761
+ }
762
+ })
763
+ );
725
764
  });
726
765
  program.command("build").action(async () => {
727
766
  const postcssOptions = await loadPostcssConfig({
@@ -744,4 +783,4 @@ function createCli() {
744
783
  return program;
745
784
  }
746
785
 
747
- export { build, createBuilder, createCli, createConfigLoader, defineConfig };
786
+ export { build, createBuilder, createCli, createConfigLoader, defineConfig, watch };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weapp-tailwindcss/cli",
3
- "version": "0.0.0-alpha.1",
3
+ "version": "0.0.0-alpha.3",
4
4
  "description": "The cli of weapp-tailwindcss",
5
5
  "keywords": [],
6
6
  "author": "",
@@ -29,7 +29,7 @@
29
29
  "gulp-less": "^5.0.0",
30
30
  "gulp-sass": "^5.1.0",
31
31
  "postcss-load-config": "^5.0.3",
32
- "weapp-tailwindcss": "3.2.0-alpha.1"
32
+ "weapp-tailwindcss": "3.2.0-alpha.3"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@types/fs-extra": "^11.0.4",