@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 +21 -0
- package/dist/index.cjs +328 -254
- package/dist/index.d.cts +31 -15
- package/dist/index.d.mts +31 -15
- package/dist/index.d.ts +31 -15
- package/dist/index.mjs +322 -254
- package/package.json +35 -24
package/dist/index.mjs
CHANGED
|
@@ -3,10 +3,16 @@ import path from 'node:path';
|
|
|
3
3
|
import fs, { ensureDirSync } from 'fs-extra';
|
|
4
4
|
import gulp from 'gulp';
|
|
5
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';
|
|
7
9
|
import postcssrc from 'gulp-postcss';
|
|
8
10
|
import plumber from 'gulp-plumber';
|
|
9
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';
|
|
10
16
|
import { cosmiconfigSync } from 'cosmiconfig';
|
|
11
17
|
|
|
12
18
|
function isPlainObject$2(value) {
|
|
@@ -65,6 +71,8 @@ function createDefu(merger) {
|
|
|
65
71
|
}
|
|
66
72
|
const defu = createDefu();
|
|
67
73
|
|
|
74
|
+
const debug = createDebug("weapp-tw-cli");
|
|
75
|
+
|
|
68
76
|
var AssetType = /* @__PURE__ */ ((AssetType2) => {
|
|
69
77
|
AssetType2["JavaScript"] = "javascript";
|
|
70
78
|
AssetType2["Json"] = "json";
|
|
@@ -73,249 +81,6 @@ var AssetType = /* @__PURE__ */ ((AssetType2) => {
|
|
|
73
81
|
return AssetType2;
|
|
74
82
|
})(AssetType || {});
|
|
75
83
|
|
|
76
|
-
function getTasks(options) {
|
|
77
|
-
const { root: cwd, weappTailwindcssOptions, outDir, src: srcBase, extensions, exclude, include, postcssOptions } = options;
|
|
78
|
-
const globsSet = /* @__PURE__ */ new Set();
|
|
79
|
-
const base = srcBase ? srcBase + "/" : "";
|
|
80
|
-
function globsSetAdd(...value) {
|
|
81
|
-
for (const v of value) {
|
|
82
|
-
if (Array.isArray(v)) {
|
|
83
|
-
for (const vv of v) {
|
|
84
|
-
globsSet.add(vv);
|
|
85
|
-
}
|
|
86
|
-
} else {
|
|
87
|
-
globsSet.add(v);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
function getGlobs(type) {
|
|
92
|
-
const globs = [];
|
|
93
|
-
if (typeof include === "function") {
|
|
94
|
-
globs.push(...include(type).map((x) => x));
|
|
95
|
-
}
|
|
96
|
-
if (typeof exclude === "function") {
|
|
97
|
-
globs.push(...exclude(type).map((x) => "!" + x));
|
|
98
|
-
} else if (Array.isArray(exclude)) {
|
|
99
|
-
globs.push(...exclude.map((x) => "!" + x));
|
|
100
|
-
}
|
|
101
|
-
globs.push(`!${outDir}/**/*`);
|
|
102
|
-
return globs;
|
|
103
|
-
}
|
|
104
|
-
const { transformJs, transformWxml, transformWxss } = createPlugins(weappTailwindcssOptions);
|
|
105
|
-
function getJsTasks() {
|
|
106
|
-
const assetType = AssetType.JavaScript;
|
|
107
|
-
const globs = getGlobs(assetType);
|
|
108
|
-
globsSetAdd(globs);
|
|
109
|
-
return extensions[assetType].map((x) => {
|
|
110
|
-
const src = `${base}**/*.${x}`;
|
|
111
|
-
globsSetAdd(src);
|
|
112
|
-
return function JsTask() {
|
|
113
|
-
return gulp.src([src, ...globs], { cwd, since: gulp.lastRun(JsTask) }).pipe(plumber()).pipe(
|
|
114
|
-
transformJs({
|
|
115
|
-
babelParserOptions: x === "ts" ? {
|
|
116
|
-
plugins: ["typescript"]
|
|
117
|
-
} : void 0
|
|
118
|
-
})
|
|
119
|
-
).pipe(
|
|
120
|
-
gulp.dest(outDir, {
|
|
121
|
-
cwd
|
|
122
|
-
})
|
|
123
|
-
);
|
|
124
|
-
};
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
function getJsonTasks() {
|
|
128
|
-
const assetType = AssetType.Json;
|
|
129
|
-
const globs = getGlobs(assetType);
|
|
130
|
-
globsSetAdd(globs);
|
|
131
|
-
return extensions[assetType].map((x) => {
|
|
132
|
-
const src = `${base}**/*.${x}`;
|
|
133
|
-
globsSetAdd(src);
|
|
134
|
-
return function JsonTask() {
|
|
135
|
-
return gulp.src([src, ...globs], { cwd, since: gulp.lastRun(JsonTask) }).pipe(plumber()).pipe(
|
|
136
|
-
gulp.dest(outDir, {
|
|
137
|
-
cwd
|
|
138
|
-
})
|
|
139
|
-
);
|
|
140
|
-
};
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
function getCssTasks() {
|
|
144
|
-
const assetType = AssetType.Css;
|
|
145
|
-
const globs = getGlobs(assetType);
|
|
146
|
-
globsSetAdd(globs);
|
|
147
|
-
return extensions[assetType].map((x) => {
|
|
148
|
-
const src = `${base}**/*.${x}`;
|
|
149
|
-
globsSetAdd(src);
|
|
150
|
-
return function CssTask() {
|
|
151
|
-
return gulp.src([src, ...globs], { cwd, since: gulp.lastRun(CssTask) }).pipe(plumber()).pipe(gulpif(Boolean(postcssOptions), postcssrc(postcssOptions?.plugins, postcssOptions?.options))).pipe(transformWxss()).pipe(
|
|
152
|
-
gulp.dest(outDir, {
|
|
153
|
-
cwd
|
|
154
|
-
})
|
|
155
|
-
);
|
|
156
|
-
};
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
function getHtmlTasks() {
|
|
160
|
-
const assetType = AssetType.Html;
|
|
161
|
-
const globs = getGlobs(assetType);
|
|
162
|
-
globsSetAdd(globs);
|
|
163
|
-
return extensions[assetType].map((x) => {
|
|
164
|
-
const src = `${base}**/*.${x}`;
|
|
165
|
-
globsSetAdd(src);
|
|
166
|
-
return function HtmlTask() {
|
|
167
|
-
return gulp.src([src, ...globs], { cwd, since: gulp.lastRun(HtmlTask) }).pipe(plumber()).pipe(transformWxml()).pipe(
|
|
168
|
-
gulp.dest(outDir, {
|
|
169
|
-
cwd
|
|
170
|
-
})
|
|
171
|
-
);
|
|
172
|
-
};
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
function copyOthers() {
|
|
176
|
-
if (Array.isArray(include)) {
|
|
177
|
-
const globs = include.map((x) => {
|
|
178
|
-
return `${base}${x}`;
|
|
179
|
-
});
|
|
180
|
-
globsSetAdd(globs);
|
|
181
|
-
return gulp.src(globs, { cwd, since: gulp.lastRun(copyOthers) }).pipe(plumber()).pipe(
|
|
182
|
-
gulp.dest(outDir, {
|
|
183
|
-
cwd
|
|
184
|
-
})
|
|
185
|
-
);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
return {
|
|
189
|
-
getGlobs,
|
|
190
|
-
getJsTasks,
|
|
191
|
-
getJsonTasks,
|
|
192
|
-
getCssTasks,
|
|
193
|
-
getHtmlTasks,
|
|
194
|
-
copyOthers,
|
|
195
|
-
globsSet
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
const defaultJavascriptExtensions = ["js"];
|
|
200
|
-
const defaultTypescriptExtensions = ["ts"];
|
|
201
|
-
const defaultWxsExtensions = ["wxs"];
|
|
202
|
-
const defaultNodeModulesDirs = [
|
|
203
|
-
"**/node_modules/**",
|
|
204
|
-
"**/miniprogram_npm/**",
|
|
205
|
-
"**/project.config.json/**",
|
|
206
|
-
"**/project.private.config.json/**",
|
|
207
|
-
"**/package.json/**",
|
|
208
|
-
"postcss.config.js",
|
|
209
|
-
"tailwind.config.js"
|
|
210
|
-
];
|
|
211
|
-
function createBuilder(options) {
|
|
212
|
-
const {
|
|
213
|
-
root: cwd,
|
|
214
|
-
weappTailwindcssOptions,
|
|
215
|
-
outDir,
|
|
216
|
-
src: srcBase,
|
|
217
|
-
clean,
|
|
218
|
-
extensions,
|
|
219
|
-
exclude,
|
|
220
|
-
include,
|
|
221
|
-
watchOptions,
|
|
222
|
-
postcssOptions
|
|
223
|
-
} = defu(options, {
|
|
224
|
-
outDir: "dist",
|
|
225
|
-
weappTailwindcssOptions: {},
|
|
226
|
-
clean: true,
|
|
227
|
-
src: "",
|
|
228
|
-
exclude: [...defaultNodeModulesDirs],
|
|
229
|
-
extensions: {
|
|
230
|
-
javascript: [...defaultJavascriptExtensions, ...defaultTypescriptExtensions, ...defaultWxsExtensions],
|
|
231
|
-
html: ["wxml"],
|
|
232
|
-
css: ["wxss", "less", "sass", "scss"],
|
|
233
|
-
json: ["json"]
|
|
234
|
-
},
|
|
235
|
-
watchOptions: {
|
|
236
|
-
events: ["add", "change", "unlink", "ready"]
|
|
237
|
-
}
|
|
238
|
-
});
|
|
239
|
-
const { copyOthers, getCssTasks, getHtmlTasks, getJsTasks, getJsonTasks, globsSet } = getTasks({
|
|
240
|
-
root: cwd,
|
|
241
|
-
weappTailwindcssOptions,
|
|
242
|
-
outDir,
|
|
243
|
-
src: srcBase,
|
|
244
|
-
clean,
|
|
245
|
-
extensions,
|
|
246
|
-
exclude,
|
|
247
|
-
include,
|
|
248
|
-
watchOptions,
|
|
249
|
-
postcssOptions
|
|
250
|
-
});
|
|
251
|
-
const tasks = [...getJsTasks(), ...getJsonTasks(), ...getCssTasks(), ...getHtmlTasks(), copyOthers];
|
|
252
|
-
async function runTasks() {
|
|
253
|
-
for (const task of tasks) {
|
|
254
|
-
const s = task();
|
|
255
|
-
if (s) {
|
|
256
|
-
await new Promise((resolve, reject) => s.on("finish", resolve).on("error", reject));
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
return {
|
|
261
|
-
watcher: void 0,
|
|
262
|
-
async build() {
|
|
263
|
-
if (clean) {
|
|
264
|
-
const { deleteAsync } = await import('del');
|
|
265
|
-
const patterns = [outDir + "/**"];
|
|
266
|
-
await deleteAsync(patterns, { cwd, ignore: defaultNodeModulesDirs });
|
|
267
|
-
}
|
|
268
|
-
ensureDirSync(path.resolve(cwd, outDir));
|
|
269
|
-
await runTasks();
|
|
270
|
-
return this;
|
|
271
|
-
},
|
|
272
|
-
watch() {
|
|
273
|
-
ensureDirSync(path.resolve(cwd, outDir));
|
|
274
|
-
const watcher = gulp.watch([...globsSet], watchOptions, async (cb) => {
|
|
275
|
-
try {
|
|
276
|
-
await runTasks();
|
|
277
|
-
cb();
|
|
278
|
-
} catch (error) {
|
|
279
|
-
cb(error);
|
|
280
|
-
}
|
|
281
|
-
});
|
|
282
|
-
watcher.on("change", function(path2) {
|
|
283
|
-
console.log(`File ${path2} was changed`);
|
|
284
|
-
});
|
|
285
|
-
watcher.on("add", function(path2) {
|
|
286
|
-
console.log(`File ${path2} was added`);
|
|
287
|
-
});
|
|
288
|
-
watcher.on("unlink", function(path2) {
|
|
289
|
-
console.log(`File ${path2} was removed`);
|
|
290
|
-
});
|
|
291
|
-
watcher.on("ready", function() {
|
|
292
|
-
console.log(`Weapp-tailwindcss is Ready!`);
|
|
293
|
-
});
|
|
294
|
-
this.watcher = watcher;
|
|
295
|
-
return this;
|
|
296
|
-
},
|
|
297
|
-
globsSet
|
|
298
|
-
};
|
|
299
|
-
}
|
|
300
|
-
async function build(options) {
|
|
301
|
-
let postcssOptions;
|
|
302
|
-
try {
|
|
303
|
-
postcssOptions = await loadPostcssConfig({ cwd: options?.root });
|
|
304
|
-
} catch {
|
|
305
|
-
}
|
|
306
|
-
const builder = createBuilder(defu(options, { postcssOptions }));
|
|
307
|
-
return await builder.build();
|
|
308
|
-
}
|
|
309
|
-
async function watch(options) {
|
|
310
|
-
let postcssOptions;
|
|
311
|
-
try {
|
|
312
|
-
postcssOptions = await loadPostcssConfig({ cwd: options?.root });
|
|
313
|
-
} catch {
|
|
314
|
-
}
|
|
315
|
-
const builder = createBuilder(defu(options, { postcssOptions }));
|
|
316
|
-
return await builder.watch();
|
|
317
|
-
}
|
|
318
|
-
|
|
319
84
|
function getDefaultExportFromCjs (x) {
|
|
320
85
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
321
86
|
}
|
|
@@ -352,10 +117,10 @@ var isobject = function isObject(val) {
|
|
|
352
117
|
* Released under the MIT License.
|
|
353
118
|
*/
|
|
354
119
|
|
|
355
|
-
var isObject$
|
|
120
|
+
var isObject$3 = isobject;
|
|
356
121
|
|
|
357
122
|
function isObjectObject(o) {
|
|
358
|
-
return isObject$
|
|
123
|
+
return isObject$3(o) === true
|
|
359
124
|
&& Object.prototype.toString.call(o) === '[object Object]';
|
|
360
125
|
}
|
|
361
126
|
|
|
@@ -392,7 +157,7 @@ const { deleteProperty } = Reflect;
|
|
|
392
157
|
const isPrimitive = isPrimitive$1;
|
|
393
158
|
const isPlainObject = isPlainObject$1;
|
|
394
159
|
|
|
395
|
-
const isObject$
|
|
160
|
+
const isObject$2 = value => {
|
|
396
161
|
return (typeof value === 'object' && value !== null) || typeof value === 'function';
|
|
397
162
|
};
|
|
398
163
|
|
|
@@ -510,7 +275,7 @@ const assignProp = (obj, prop, value, options) => {
|
|
|
510
275
|
};
|
|
511
276
|
|
|
512
277
|
const setValue = (target, path, value, options) => {
|
|
513
|
-
if (!path || !isObject$
|
|
278
|
+
if (!path || !isObject$2(target)) return target;
|
|
514
279
|
|
|
515
280
|
const keys = split$1(path, options);
|
|
516
281
|
let obj = target;
|
|
@@ -531,7 +296,7 @@ const setValue = (target, path, value, options) => {
|
|
|
531
296
|
continue;
|
|
532
297
|
}
|
|
533
298
|
|
|
534
|
-
if (!isObject$
|
|
299
|
+
if (!isObject$2(obj[key])) {
|
|
535
300
|
obj[key] = {};
|
|
536
301
|
}
|
|
537
302
|
|
|
@@ -558,10 +323,10 @@ const set = /*@__PURE__*/getDefaultExportFromCjs(setValue_1);
|
|
|
558
323
|
* Released under the MIT License.
|
|
559
324
|
*/
|
|
560
325
|
|
|
561
|
-
const isObject = isobject;
|
|
326
|
+
const isObject$1 = isobject;
|
|
562
327
|
|
|
563
328
|
var getValue = function(target, path, options) {
|
|
564
|
-
if (!isObject(options)) {
|
|
329
|
+
if (!isObject$1(options)) {
|
|
565
330
|
options = { default: options };
|
|
566
331
|
}
|
|
567
332
|
|
|
@@ -659,11 +424,309 @@ function isValid(key, target, options) {
|
|
|
659
424
|
}
|
|
660
425
|
|
|
661
426
|
function isValidObject(val) {
|
|
662
|
-
return isObject(val) || Array.isArray(val) || typeof val === 'function';
|
|
427
|
+
return isObject$1(val) || Array.isArray(val) || typeof val === 'function';
|
|
663
428
|
}
|
|
664
429
|
|
|
665
430
|
const get = /*@__PURE__*/getDefaultExportFromCjs(getValue);
|
|
666
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
|
+
|
|
667
730
|
function createConfigLoader(root) {
|
|
668
731
|
const explorer = cosmiconfigSync("weapp-tw");
|
|
669
732
|
function search(searchFrom = root) {
|
|
@@ -685,7 +748,7 @@ function getDefaultConfig(root) {
|
|
|
685
748
|
return {
|
|
686
749
|
outDir: "dist",
|
|
687
750
|
root,
|
|
688
|
-
|
|
751
|
+
src: "."
|
|
689
752
|
};
|
|
690
753
|
}
|
|
691
754
|
function defineConfig(options) {
|
|
@@ -748,13 +811,18 @@ function initConfig(options) {
|
|
|
748
811
|
const { lang, root } = defu(options, { lang: "js", root: process.cwd() });
|
|
749
812
|
const configFilename = `weapp-tw.config.${lang ?? "js"}`;
|
|
750
813
|
const configPath = path.resolve(root, configFilename);
|
|
814
|
+
const tsconfigPath = path.resolve(root, "tsconfig.json");
|
|
815
|
+
const isTsconfigExisted = fs.existsSync(tsconfigPath);
|
|
751
816
|
fs.ensureDirSync(root);
|
|
817
|
+
const configOptionsStr = isTsconfigExisted ? `{
|
|
818
|
+
src: './miniprogram'
|
|
819
|
+
}` : "{}";
|
|
752
820
|
if (lang === "ts") {
|
|
753
821
|
fs.writeFileSync(
|
|
754
822
|
configPath,
|
|
755
823
|
`import { defineConfig } from '@weapp-tailwindcss/cli'
|
|
756
824
|
|
|
757
|
-
export default defineConfig({})
|
|
825
|
+
export default defineConfig(${configOptionsStr})
|
|
758
826
|
`,
|
|
759
827
|
"utf8"
|
|
760
828
|
);
|
|
@@ -762,7 +830,7 @@ export default defineConfig({})
|
|
|
762
830
|
fs.writeFileSync(
|
|
763
831
|
configPath,
|
|
764
832
|
`/** @type {import('@weapp-tailwindcss/cli').UserConfig} */
|
|
765
|
-
module.exports = {}
|
|
833
|
+
module.exports = ${configOptionsStr}
|
|
766
834
|
`,
|
|
767
835
|
"utf8"
|
|
768
836
|
);
|