@weapp-tailwindcss/cli 0.0.0-alpha.6 → 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/dist/index.cjs +314 -265
- package/dist/index.d.cts +24 -2
- package/dist/index.d.mts +24 -2
- package/dist/index.d.ts +24 -2
- package/dist/index.mjs +310 -265
- package/package.json +16 -19
package/dist/index.mjs
CHANGED
|
@@ -9,6 +9,10 @@ import { createPlugins } from 'weapp-tailwindcss/gulp';
|
|
|
9
9
|
import postcssrc from 'gulp-postcss';
|
|
10
10
|
import plumber from 'gulp-plumber';
|
|
11
11
|
import gulpif from 'gulp-if';
|
|
12
|
+
import createSass from 'gulp-sass';
|
|
13
|
+
import rename from 'gulp-rename';
|
|
14
|
+
import less from 'gulp-less';
|
|
15
|
+
import typescript from 'gulp-typescript';
|
|
12
16
|
import { cosmiconfigSync } from 'cosmiconfig';
|
|
13
17
|
|
|
14
18
|
function isPlainObject$2(value) {
|
|
@@ -77,263 +81,6 @@ var AssetType = /* @__PURE__ */ ((AssetType2) => {
|
|
|
77
81
|
return AssetType2;
|
|
78
82
|
})(AssetType || {});
|
|
79
83
|
|
|
80
|
-
function getTasks(options) {
|
|
81
|
-
const { root: cwd, weappTailwindcssOptions, outDir, src: srcBase, extensions, exclude, include, postcssOptions } = options;
|
|
82
|
-
const globsSet = /* @__PURE__ */ new Set();
|
|
83
|
-
const base = srcBase ? srcBase + "/" : "";
|
|
84
|
-
function globsSetAdd(...value) {
|
|
85
|
-
for (const v of value) {
|
|
86
|
-
if (Array.isArray(v)) {
|
|
87
|
-
for (const vv of v) {
|
|
88
|
-
globsSet.add(vv);
|
|
89
|
-
}
|
|
90
|
-
} else {
|
|
91
|
-
globsSet.add(v);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
function getGlobs(type) {
|
|
96
|
-
const globs = [];
|
|
97
|
-
if (typeof include === "function") {
|
|
98
|
-
globs.push(...include(type).map((x) => x));
|
|
99
|
-
}
|
|
100
|
-
if (typeof exclude === "function") {
|
|
101
|
-
globs.push(...exclude(type).map((x) => "!" + x));
|
|
102
|
-
} else if (Array.isArray(exclude)) {
|
|
103
|
-
globs.push(...exclude.map((x) => "!" + x));
|
|
104
|
-
}
|
|
105
|
-
globs.push(`!${outDir}/**/*`);
|
|
106
|
-
return globs;
|
|
107
|
-
}
|
|
108
|
-
const { transformJs, transformWxml, transformWxss } = createPlugins(weappTailwindcssOptions);
|
|
109
|
-
function getJsTasks() {
|
|
110
|
-
const assetType = AssetType.JavaScript;
|
|
111
|
-
const globs = getGlobs(assetType);
|
|
112
|
-
globsSetAdd(globs);
|
|
113
|
-
return extensions[assetType].map((x) => {
|
|
114
|
-
const src = `${base}**/*.${x}`;
|
|
115
|
-
globsSetAdd(src);
|
|
116
|
-
return function JsTask() {
|
|
117
|
-
return gulp.src([src, ...globs], { cwd, since: gulp.lastRun(JsTask) }).pipe(plumber()).pipe(
|
|
118
|
-
transformJs({
|
|
119
|
-
babelParserOptions: x === "ts" ? {
|
|
120
|
-
plugins: ["typescript"]
|
|
121
|
-
} : void 0
|
|
122
|
-
})
|
|
123
|
-
).pipe(
|
|
124
|
-
gulp.dest(outDir, {
|
|
125
|
-
cwd
|
|
126
|
-
})
|
|
127
|
-
);
|
|
128
|
-
};
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
function getJsonTasks() {
|
|
132
|
-
const assetType = AssetType.Json;
|
|
133
|
-
const globs = getGlobs(assetType);
|
|
134
|
-
globsSetAdd(globs);
|
|
135
|
-
return extensions[assetType].map((x) => {
|
|
136
|
-
const src = `${base}**/*.${x}`;
|
|
137
|
-
globsSetAdd(src);
|
|
138
|
-
return function JsonTask() {
|
|
139
|
-
return gulp.src([src, ...globs], { cwd, since: gulp.lastRun(JsonTask) }).pipe(plumber()).pipe(
|
|
140
|
-
gulp.dest(outDir, {
|
|
141
|
-
cwd
|
|
142
|
-
})
|
|
143
|
-
);
|
|
144
|
-
};
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
function getCssTasks() {
|
|
148
|
-
const assetType = AssetType.Css;
|
|
149
|
-
const globs = getGlobs(assetType);
|
|
150
|
-
globsSetAdd(globs);
|
|
151
|
-
return extensions[assetType].map((x) => {
|
|
152
|
-
const src = `${base}**/*.${x}`;
|
|
153
|
-
globsSetAdd(src);
|
|
154
|
-
return function CssTask() {
|
|
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(
|
|
156
|
-
gulp.dest(outDir, {
|
|
157
|
-
cwd
|
|
158
|
-
})
|
|
159
|
-
);
|
|
160
|
-
};
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
function getHtmlTasks() {
|
|
164
|
-
const assetType = AssetType.Html;
|
|
165
|
-
const globs = getGlobs(assetType);
|
|
166
|
-
globsSetAdd(globs);
|
|
167
|
-
return extensions[assetType].map((x) => {
|
|
168
|
-
const src = `${base}**/*.${x}`;
|
|
169
|
-
globsSetAdd(src);
|
|
170
|
-
return function HtmlTask() {
|
|
171
|
-
return gulp.src([src, ...globs], { cwd, since: gulp.lastRun(HtmlTask) }).pipe(plumber()).pipe(transformWxml()).pipe(
|
|
172
|
-
gulp.dest(outDir, {
|
|
173
|
-
cwd
|
|
174
|
-
})
|
|
175
|
-
);
|
|
176
|
-
};
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
function copyOthers() {
|
|
180
|
-
if (Array.isArray(include)) {
|
|
181
|
-
const globs = include.map((x) => {
|
|
182
|
-
return `${base}${x}`;
|
|
183
|
-
});
|
|
184
|
-
globsSetAdd(globs);
|
|
185
|
-
return gulp.src(globs, { cwd, since: gulp.lastRun(copyOthers) }).pipe(plumber()).pipe(
|
|
186
|
-
gulp.dest(outDir, {
|
|
187
|
-
cwd
|
|
188
|
-
})
|
|
189
|
-
);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
return {
|
|
193
|
-
getGlobs,
|
|
194
|
-
getJsTasks,
|
|
195
|
-
getJsonTasks,
|
|
196
|
-
getCssTasks,
|
|
197
|
-
getHtmlTasks,
|
|
198
|
-
copyOthers,
|
|
199
|
-
globsSet
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
const defaultJavascriptExtensions = ["js"];
|
|
204
|
-
const defaultTypescriptExtensions = ["ts"];
|
|
205
|
-
const defaultWxsExtensions = ["wxs"];
|
|
206
|
-
const defaultNodeModulesDirs = [
|
|
207
|
-
"**/node_modules/**",
|
|
208
|
-
"**/miniprogram_npm/**",
|
|
209
|
-
"**/project.config.json/**",
|
|
210
|
-
"**/project.private.config.json/**",
|
|
211
|
-
"**/package.json/**",
|
|
212
|
-
"postcss.config.js",
|
|
213
|
-
"tailwind.config.js"
|
|
214
|
-
];
|
|
215
|
-
function createBuilder(options) {
|
|
216
|
-
const {
|
|
217
|
-
root: cwd,
|
|
218
|
-
weappTailwindcssOptions,
|
|
219
|
-
outDir,
|
|
220
|
-
src: srcBase,
|
|
221
|
-
clean,
|
|
222
|
-
extensions,
|
|
223
|
-
exclude,
|
|
224
|
-
include,
|
|
225
|
-
watchOptions,
|
|
226
|
-
postcssOptions
|
|
227
|
-
} = defu(options, {
|
|
228
|
-
outDir: "dist",
|
|
229
|
-
weappTailwindcssOptions: {},
|
|
230
|
-
clean: true,
|
|
231
|
-
src: "",
|
|
232
|
-
exclude: [...defaultNodeModulesDirs],
|
|
233
|
-
extensions: {
|
|
234
|
-
javascript: [...defaultJavascriptExtensions, ...defaultTypescriptExtensions, ...defaultWxsExtensions],
|
|
235
|
-
html: ["wxml"],
|
|
236
|
-
css: ["wxss", "less", "sass", "scss"],
|
|
237
|
-
json: ["json"]
|
|
238
|
-
},
|
|
239
|
-
watchOptions: {
|
|
240
|
-
events: ["add", "change", "unlink", "ready"]
|
|
241
|
-
}
|
|
242
|
-
});
|
|
243
|
-
const { copyOthers, getCssTasks, getHtmlTasks, getJsTasks, getJsonTasks, globsSet } = getTasks({
|
|
244
|
-
root: cwd,
|
|
245
|
-
weappTailwindcssOptions,
|
|
246
|
-
outDir,
|
|
247
|
-
src: srcBase,
|
|
248
|
-
clean,
|
|
249
|
-
extensions,
|
|
250
|
-
exclude,
|
|
251
|
-
include,
|
|
252
|
-
watchOptions,
|
|
253
|
-
postcssOptions
|
|
254
|
-
});
|
|
255
|
-
const tasks = {
|
|
256
|
-
css: getCssTasks(),
|
|
257
|
-
html: getHtmlTasks(),
|
|
258
|
-
json: getJsonTasks(),
|
|
259
|
-
js: getJsTasks(),
|
|
260
|
-
extra: [copyOthers]
|
|
261
|
-
};
|
|
262
|
-
async function runTasks() {
|
|
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
|
-
}
|
|
271
|
-
}
|
|
272
|
-
debug(`run task ${pc.bold(pc.green(key))} end`);
|
|
273
|
-
}
|
|
274
|
-
debug("run tasks end");
|
|
275
|
-
}
|
|
276
|
-
return {
|
|
277
|
-
watcher: void 0,
|
|
278
|
-
async build() {
|
|
279
|
-
if (clean) {
|
|
280
|
-
debug("del start");
|
|
281
|
-
const { deleteAsync } = await import('del');
|
|
282
|
-
const patterns = [outDir + "/**"];
|
|
283
|
-
await deleteAsync(patterns, { cwd, ignore: defaultNodeModulesDirs });
|
|
284
|
-
debug("del end");
|
|
285
|
-
}
|
|
286
|
-
ensureDirSync(path.resolve(cwd, outDir));
|
|
287
|
-
await runTasks();
|
|
288
|
-
return this;
|
|
289
|
-
},
|
|
290
|
-
watch() {
|
|
291
|
-
ensureDirSync(path.resolve(cwd, outDir));
|
|
292
|
-
const watcher = gulp.watch([...globsSet], watchOptions, async (cb) => {
|
|
293
|
-
try {
|
|
294
|
-
await runTasks();
|
|
295
|
-
cb();
|
|
296
|
-
} catch (error) {
|
|
297
|
-
cb(error);
|
|
298
|
-
}
|
|
299
|
-
});
|
|
300
|
-
watcher.on("change", function(path2) {
|
|
301
|
-
console.log(`${pc.green("changed")} ${path2}`);
|
|
302
|
-
});
|
|
303
|
-
watcher.on("add", function(path2) {
|
|
304
|
-
console.log(`${pc.green("add")} ${path2}`);
|
|
305
|
-
});
|
|
306
|
-
watcher.on("unlink", function(path2) {
|
|
307
|
-
console.log(`${pc.green("remove")} ${path2}`);
|
|
308
|
-
});
|
|
309
|
-
watcher.on("ready", function() {
|
|
310
|
-
console.log(`${pc.green("weapp")}-${pc.blue("tailwindcss")} is ready!`);
|
|
311
|
-
});
|
|
312
|
-
this.watcher = watcher;
|
|
313
|
-
return this;
|
|
314
|
-
},
|
|
315
|
-
globsSet
|
|
316
|
-
};
|
|
317
|
-
}
|
|
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();
|
|
326
|
-
}
|
|
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();
|
|
335
|
-
}
|
|
336
|
-
|
|
337
84
|
function getDefaultExportFromCjs (x) {
|
|
338
85
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
339
86
|
}
|
|
@@ -370,10 +117,10 @@ var isobject = function isObject(val) {
|
|
|
370
117
|
* Released under the MIT License.
|
|
371
118
|
*/
|
|
372
119
|
|
|
373
|
-
var isObject$
|
|
120
|
+
var isObject$3 = isobject;
|
|
374
121
|
|
|
375
122
|
function isObjectObject(o) {
|
|
376
|
-
return isObject$
|
|
123
|
+
return isObject$3(o) === true
|
|
377
124
|
&& Object.prototype.toString.call(o) === '[object Object]';
|
|
378
125
|
}
|
|
379
126
|
|
|
@@ -410,7 +157,7 @@ const { deleteProperty } = Reflect;
|
|
|
410
157
|
const isPrimitive = isPrimitive$1;
|
|
411
158
|
const isPlainObject = isPlainObject$1;
|
|
412
159
|
|
|
413
|
-
const isObject$
|
|
160
|
+
const isObject$2 = value => {
|
|
414
161
|
return (typeof value === 'object' && value !== null) || typeof value === 'function';
|
|
415
162
|
};
|
|
416
163
|
|
|
@@ -528,7 +275,7 @@ const assignProp = (obj, prop, value, options) => {
|
|
|
528
275
|
};
|
|
529
276
|
|
|
530
277
|
const setValue = (target, path, value, options) => {
|
|
531
|
-
if (!path || !isObject$
|
|
278
|
+
if (!path || !isObject$2(target)) return target;
|
|
532
279
|
|
|
533
280
|
const keys = split$1(path, options);
|
|
534
281
|
let obj = target;
|
|
@@ -549,7 +296,7 @@ const setValue = (target, path, value, options) => {
|
|
|
549
296
|
continue;
|
|
550
297
|
}
|
|
551
298
|
|
|
552
|
-
if (!isObject$
|
|
299
|
+
if (!isObject$2(obj[key])) {
|
|
553
300
|
obj[key] = {};
|
|
554
301
|
}
|
|
555
302
|
|
|
@@ -576,10 +323,10 @@ const set = /*@__PURE__*/getDefaultExportFromCjs(setValue_1);
|
|
|
576
323
|
* Released under the MIT License.
|
|
577
324
|
*/
|
|
578
325
|
|
|
579
|
-
const isObject = isobject;
|
|
326
|
+
const isObject$1 = isobject;
|
|
580
327
|
|
|
581
328
|
var getValue = function(target, path, options) {
|
|
582
|
-
if (!isObject(options)) {
|
|
329
|
+
if (!isObject$1(options)) {
|
|
583
330
|
options = { default: options };
|
|
584
331
|
}
|
|
585
332
|
|
|
@@ -677,11 +424,309 @@ function isValid(key, target, options) {
|
|
|
677
424
|
}
|
|
678
425
|
|
|
679
426
|
function isValidObject(val) {
|
|
680
|
-
return isObject(val) || Array.isArray(val) || typeof val === 'function';
|
|
427
|
+
return isObject$1(val) || Array.isArray(val) || typeof val === 'function';
|
|
681
428
|
}
|
|
682
429
|
|
|
683
430
|
const get = /*@__PURE__*/getDefaultExportFromCjs(getValue);
|
|
684
431
|
|
|
432
|
+
function isObject(x) {
|
|
433
|
+
return typeof x === "object" && x !== null;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
function isSassLang(lang) {
|
|
437
|
+
return lang === "scss" || lang === "sass";
|
|
438
|
+
}
|
|
439
|
+
function isLessLang(lang) {
|
|
440
|
+
return lang === "less";
|
|
441
|
+
}
|
|
442
|
+
function isTsLang(lang) {
|
|
443
|
+
return lang === "ts";
|
|
444
|
+
}
|
|
445
|
+
async function getTasks(options) {
|
|
446
|
+
let { typescriptOptions } = options;
|
|
447
|
+
const { root: cwd, weappTailwindcssOptions, outDir, src: srcBase, extensions, exclude, include, postcssOptions, preprocessorOptions } = options;
|
|
448
|
+
const globsSet = /* @__PURE__ */ new Set();
|
|
449
|
+
const base = srcBase ? srcBase + "/" : "";
|
|
450
|
+
const enableSass = Boolean(preprocessorOptions?.sass);
|
|
451
|
+
const enableLess = Boolean(preprocessorOptions?.less);
|
|
452
|
+
if (typescriptOptions === true) {
|
|
453
|
+
typescriptOptions = {
|
|
454
|
+
tsConfigFileName: "tsconfig.json"
|
|
455
|
+
};
|
|
456
|
+
} else if (isObject(typescriptOptions) && typescriptOptions.tsConfigFileName === void 0) {
|
|
457
|
+
typescriptOptions.tsConfigFileName = "tsconfig.json";
|
|
458
|
+
}
|
|
459
|
+
const enableTs = Boolean(typescriptOptions);
|
|
460
|
+
let sass;
|
|
461
|
+
if (enableSass) {
|
|
462
|
+
const sassLib = await import('sass');
|
|
463
|
+
sass = createSass(sassLib);
|
|
464
|
+
}
|
|
465
|
+
const { transformJs, transformWxml, transformWxss } = createPlugins(weappTailwindcssOptions);
|
|
466
|
+
function globsSetAdd(...value) {
|
|
467
|
+
for (const v of value) {
|
|
468
|
+
if (Array.isArray(v)) {
|
|
469
|
+
for (const vv of v) {
|
|
470
|
+
globsSet.add(vv);
|
|
471
|
+
}
|
|
472
|
+
} else {
|
|
473
|
+
globsSet.add(v);
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
function getGlobs(type) {
|
|
478
|
+
const globs = [];
|
|
479
|
+
if (typeof include === "function") {
|
|
480
|
+
globs.push(...include(type).map((x) => x));
|
|
481
|
+
}
|
|
482
|
+
if (typeof exclude === "function") {
|
|
483
|
+
globs.push(...exclude(type).map((x) => "!" + x));
|
|
484
|
+
} else if (Array.isArray(exclude)) {
|
|
485
|
+
globs.push(...exclude.map((x) => "!" + x));
|
|
486
|
+
}
|
|
487
|
+
globs.push(`!${outDir}/**/*`);
|
|
488
|
+
return globs;
|
|
489
|
+
}
|
|
490
|
+
function getJsTasks() {
|
|
491
|
+
const assetType = AssetType.JavaScript;
|
|
492
|
+
const globs = getGlobs(assetType);
|
|
493
|
+
globsSetAdd(globs);
|
|
494
|
+
return extensions[assetType]?.map((x) => {
|
|
495
|
+
const src = `${base}**/*.${x}`;
|
|
496
|
+
globsSetAdd(src);
|
|
497
|
+
const isTs = isTsLang(x);
|
|
498
|
+
const loadTs = enableTs && isTs;
|
|
499
|
+
let gulpTs;
|
|
500
|
+
if (enableTs && typeof typescriptOptions !== "boolean") {
|
|
501
|
+
gulpTs = typescript.createProject(typescriptOptions.tsConfigFileName ?? "tsconfig.json", typeof typescriptOptions === "boolean" ? {} : typescriptOptions);
|
|
502
|
+
}
|
|
503
|
+
return function JsTask() {
|
|
504
|
+
let chain = gulp.src([src, ...globs], { cwd, since: gulp.lastRun(JsTask) }).pipe(plumber());
|
|
505
|
+
if (loadTs) {
|
|
506
|
+
chain = chain.pipe(gulpTs());
|
|
507
|
+
}
|
|
508
|
+
return chain.pipe(
|
|
509
|
+
transformJs({
|
|
510
|
+
babelParserOptions: !enableTs && isTs ? {
|
|
511
|
+
plugins: ["typescript"]
|
|
512
|
+
} : void 0
|
|
513
|
+
})
|
|
514
|
+
).pipe(
|
|
515
|
+
gulpif(
|
|
516
|
+
loadTs,
|
|
517
|
+
rename({
|
|
518
|
+
extname: ".js"
|
|
519
|
+
})
|
|
520
|
+
)
|
|
521
|
+
).pipe(
|
|
522
|
+
gulp.dest(outDir, {
|
|
523
|
+
cwd
|
|
524
|
+
})
|
|
525
|
+
);
|
|
526
|
+
};
|
|
527
|
+
});
|
|
528
|
+
}
|
|
529
|
+
function getJsonTasks() {
|
|
530
|
+
const assetType = AssetType.Json;
|
|
531
|
+
const globs = getGlobs(assetType);
|
|
532
|
+
globsSetAdd(globs);
|
|
533
|
+
return extensions[assetType]?.map((x) => {
|
|
534
|
+
const src = `${base}**/*.${x}`;
|
|
535
|
+
globsSetAdd(src);
|
|
536
|
+
return function JsonTask() {
|
|
537
|
+
return gulp.src([src, ...globs], { cwd, since: gulp.lastRun(JsonTask) }).pipe(plumber()).pipe(
|
|
538
|
+
gulp.dest(outDir, {
|
|
539
|
+
cwd
|
|
540
|
+
})
|
|
541
|
+
);
|
|
542
|
+
};
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
function getCssTasks() {
|
|
546
|
+
const assetType = AssetType.Css;
|
|
547
|
+
const globs = getGlobs(assetType);
|
|
548
|
+
globsSetAdd(globs);
|
|
549
|
+
return extensions[assetType]?.map((x) => {
|
|
550
|
+
const src = `${base}**/*.${x}`;
|
|
551
|
+
globsSetAdd(src);
|
|
552
|
+
const loadSass = enableSass && isSassLang(x);
|
|
553
|
+
const loadLess = enableLess && isLessLang(x);
|
|
554
|
+
return function CssTask() {
|
|
555
|
+
let chain = gulp.src([src, ...globs], { cwd, since: gulp.lastRun(CssTask) }).pipe(plumber());
|
|
556
|
+
if (loadSass) {
|
|
557
|
+
chain = chain.pipe(
|
|
558
|
+
sass.sync(
|
|
559
|
+
// @ts-ignore
|
|
560
|
+
typeof preprocessorOptions?.sass === "boolean" ? void 0 : preprocessorOptions?.sass
|
|
561
|
+
).on("error", sass.logError)
|
|
562
|
+
);
|
|
563
|
+
}
|
|
564
|
+
return chain.pipe(gulpif(loadLess, less(typeof preprocessorOptions?.less === "boolean" ? void 0 : preprocessorOptions?.less))).pipe(gulpif(Boolean(postcssOptions), postcssrc(postcssOptions?.plugins, postcssOptions?.options))).pipe(transformWxss()).pipe(
|
|
565
|
+
gulpif(
|
|
566
|
+
loadSass || loadLess,
|
|
567
|
+
rename({
|
|
568
|
+
extname: ".wxss"
|
|
569
|
+
})
|
|
570
|
+
)
|
|
571
|
+
).pipe(
|
|
572
|
+
gulp.dest(outDir, {
|
|
573
|
+
cwd
|
|
574
|
+
})
|
|
575
|
+
);
|
|
576
|
+
};
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
function getHtmlTasks() {
|
|
580
|
+
const assetType = AssetType.Html;
|
|
581
|
+
const globs = getGlobs(assetType);
|
|
582
|
+
globsSetAdd(globs);
|
|
583
|
+
return extensions[assetType]?.map((x) => {
|
|
584
|
+
const src = `${base}**/*.${x}`;
|
|
585
|
+
globsSetAdd(src);
|
|
586
|
+
return function HtmlTask() {
|
|
587
|
+
return gulp.src([src, ...globs], { cwd, since: gulp.lastRun(HtmlTask) }).pipe(plumber()).pipe(transformWxml()).pipe(
|
|
588
|
+
gulp.dest(outDir, {
|
|
589
|
+
cwd
|
|
590
|
+
})
|
|
591
|
+
);
|
|
592
|
+
};
|
|
593
|
+
});
|
|
594
|
+
}
|
|
595
|
+
function copyOthers() {
|
|
596
|
+
if (Array.isArray(include)) {
|
|
597
|
+
const globs = include.map((x) => {
|
|
598
|
+
return `${base}${x}`;
|
|
599
|
+
});
|
|
600
|
+
globsSetAdd(globs);
|
|
601
|
+
return gulp.src(globs, { cwd, since: gulp.lastRun(copyOthers) }).pipe(plumber()).pipe(
|
|
602
|
+
gulp.dest(outDir, {
|
|
603
|
+
cwd
|
|
604
|
+
})
|
|
605
|
+
);
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
return {
|
|
609
|
+
getGlobs,
|
|
610
|
+
getJsTasks,
|
|
611
|
+
getJsonTasks,
|
|
612
|
+
getCssTasks,
|
|
613
|
+
getHtmlTasks,
|
|
614
|
+
copyOthers,
|
|
615
|
+
globsSet
|
|
616
|
+
};
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
const defaultJavascriptExtensions = ["js"];
|
|
620
|
+
const defaultTypescriptExtensions = ["ts"];
|
|
621
|
+
const defaultWxsExtensions = ["wxs"];
|
|
622
|
+
const defaultNodeModulesDirs = [
|
|
623
|
+
"**/node_modules/**",
|
|
624
|
+
"**/miniprogram_npm/**",
|
|
625
|
+
"**/project.config.json/**",
|
|
626
|
+
"**/project.private.config.json/**",
|
|
627
|
+
"**/package.json/**",
|
|
628
|
+
"postcss.config.js",
|
|
629
|
+
"tailwind.config.js"
|
|
630
|
+
];
|
|
631
|
+
async function createBuilder(options) {
|
|
632
|
+
let postcssOptionsFromConfig;
|
|
633
|
+
try {
|
|
634
|
+
postcssOptionsFromConfig = await loadPostcssConfig({ cwd: options?.root });
|
|
635
|
+
} catch {
|
|
636
|
+
}
|
|
637
|
+
const opt = defu(options, {
|
|
638
|
+
outDir: "dist",
|
|
639
|
+
weappTailwindcssOptions: {},
|
|
640
|
+
clean: true,
|
|
641
|
+
src: "",
|
|
642
|
+
exclude: [...defaultNodeModulesDirs],
|
|
643
|
+
extensions: {
|
|
644
|
+
javascript: [...defaultJavascriptExtensions, ...defaultTypescriptExtensions, ...defaultWxsExtensions],
|
|
645
|
+
html: ["wxml"],
|
|
646
|
+
css: ["wxss", "less", "sass", "scss"],
|
|
647
|
+
json: ["json"]
|
|
648
|
+
},
|
|
649
|
+
watchOptions: {
|
|
650
|
+
events: ["add", "change", "unlink", "ready"]
|
|
651
|
+
},
|
|
652
|
+
postcssOptions: postcssOptionsFromConfig
|
|
653
|
+
});
|
|
654
|
+
const { copyOthers, getCssTasks, getHtmlTasks, getJsTasks, getJsonTasks, globsSet } = await getTasks(opt);
|
|
655
|
+
const tasks = {
|
|
656
|
+
css: getCssTasks(),
|
|
657
|
+
html: getHtmlTasks(),
|
|
658
|
+
json: getJsonTasks(),
|
|
659
|
+
js: getJsTasks(),
|
|
660
|
+
extra: [copyOthers]
|
|
661
|
+
};
|
|
662
|
+
async function runTasks() {
|
|
663
|
+
debug("run tasks start");
|
|
664
|
+
for (const [key, value] of Object.entries(tasks)) {
|
|
665
|
+
if (value) {
|
|
666
|
+
debug(`run task ${pc.bold(pc.green(key))} start`);
|
|
667
|
+
for (const task of value) {
|
|
668
|
+
const s = task();
|
|
669
|
+
if (s) {
|
|
670
|
+
await new Promise((resolve, reject) => s.on("finish", resolve).on("error", reject));
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
debug(`run task ${pc.bold(pc.green(key))} end`);
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
debug("run tasks end");
|
|
677
|
+
}
|
|
678
|
+
const { clean, outDir, root: cwd, watchOptions } = opt;
|
|
679
|
+
return {
|
|
680
|
+
watcher: void 0,
|
|
681
|
+
async build() {
|
|
682
|
+
if (clean) {
|
|
683
|
+
debug("del start");
|
|
684
|
+
const { deleteAsync } = await import('del');
|
|
685
|
+
const patterns = [outDir + "/**"];
|
|
686
|
+
await deleteAsync(patterns, { cwd, ignore: defaultNodeModulesDirs });
|
|
687
|
+
debug("del end");
|
|
688
|
+
}
|
|
689
|
+
ensureDirSync(path.resolve(cwd, outDir));
|
|
690
|
+
await runTasks();
|
|
691
|
+
return this;
|
|
692
|
+
},
|
|
693
|
+
watch() {
|
|
694
|
+
ensureDirSync(path.resolve(cwd, outDir));
|
|
695
|
+
const watcher = gulp.watch([...globsSet], watchOptions, async (cb) => {
|
|
696
|
+
try {
|
|
697
|
+
await runTasks();
|
|
698
|
+
cb();
|
|
699
|
+
} catch (error) {
|
|
700
|
+
cb(error);
|
|
701
|
+
}
|
|
702
|
+
});
|
|
703
|
+
watcher.on("change", function(path2) {
|
|
704
|
+
console.log(`${pc.green("changed")} ${path2}`);
|
|
705
|
+
});
|
|
706
|
+
watcher.on("add", function(path2) {
|
|
707
|
+
console.log(`${pc.green("add")} ${path2}`);
|
|
708
|
+
});
|
|
709
|
+
watcher.on("unlink", function(path2) {
|
|
710
|
+
console.log(`${pc.green("remove")} ${path2}`);
|
|
711
|
+
});
|
|
712
|
+
watcher.on("ready", function() {
|
|
713
|
+
console.log(`${pc.green("weapp")}-${pc.blue("tailwindcss")} is ready!`);
|
|
714
|
+
});
|
|
715
|
+
this.watcher = watcher;
|
|
716
|
+
return this;
|
|
717
|
+
},
|
|
718
|
+
globsSet
|
|
719
|
+
};
|
|
720
|
+
}
|
|
721
|
+
async function build(options) {
|
|
722
|
+
const builder = await createBuilder(options);
|
|
723
|
+
return await builder.build();
|
|
724
|
+
}
|
|
725
|
+
async function watch(options) {
|
|
726
|
+
const builder = await createBuilder(options);
|
|
727
|
+
return await builder.watch();
|
|
728
|
+
}
|
|
729
|
+
|
|
685
730
|
function createConfigLoader(root) {
|
|
686
731
|
const explorer = cosmiconfigSync("weapp-tw");
|
|
687
732
|
function search(searchFrom = root) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weapp-tailwindcss/cli",
|
|
3
|
-
"version": "0.0.0-alpha.
|
|
3
|
+
"version": "0.0.0-alpha.7",
|
|
4
4
|
"description": "The cli of weapp-tailwindcss",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"weapp",
|
|
@@ -40,32 +40,29 @@
|
|
|
40
40
|
"gulp-less": "^5.0.0",
|
|
41
41
|
"gulp-plumber": "^1.2.1",
|
|
42
42
|
"gulp-postcss": "^10.0.0",
|
|
43
|
+
"gulp-rename": "^2.0.0",
|
|
43
44
|
"gulp-sass": "^5.1.0",
|
|
45
|
+
"gulp-typescript": "6.0.0-alpha.1",
|
|
44
46
|
"picocolors": "^1.0.0",
|
|
45
47
|
"postcss": "^8.4.38",
|
|
46
48
|
"postcss-load-config": "^5.0.3"
|
|
47
49
|
},
|
|
48
50
|
"peerDependencies": {
|
|
51
|
+
"less": "*",
|
|
52
|
+
"sass": "*",
|
|
53
|
+
"typescript": "*",
|
|
49
54
|
"weapp-tailwindcss": "3.2.0-alpha.7"
|
|
50
55
|
},
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
"
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
"
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
"@types/set-value": "^4.0.3",
|
|
62
|
-
"@types/vinyl-fs": "^3.0.5",
|
|
63
|
-
"chokidar": "^3.6.0",
|
|
64
|
-
"defu": "^6.1.4",
|
|
65
|
-
"get-value": "^3.0.1",
|
|
66
|
-
"set-value": "^4.1.0",
|
|
67
|
-
"ts-morph": "^22.0.0",
|
|
68
|
-
"vinyl-fs": "^4.0.0"
|
|
56
|
+
"peerDependenciesMeta": {
|
|
57
|
+
"less": {
|
|
58
|
+
"optional": true
|
|
59
|
+
},
|
|
60
|
+
"sass": {
|
|
61
|
+
"optional": true
|
|
62
|
+
},
|
|
63
|
+
"typescript": {
|
|
64
|
+
"optional": true
|
|
65
|
+
}
|
|
69
66
|
},
|
|
70
67
|
"publishConfig": {
|
|
71
68
|
"access": "public",
|