@weapp-tailwindcss/cli 0.0.0-alpha.6 → 0.0.0-alpha.8
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 +378 -263
- package/dist/index.d.cts +38 -5
- package/dist/index.d.mts +38 -5
- package/dist/index.d.ts +38 -5
- package/dist/index.mjs +374 -262
- package/package.json +20 -21
package/dist/index.mjs
CHANGED
|
@@ -4,11 +4,15 @@ import fs, { ensureDirSync } from 'fs-extra';
|
|
|
4
4
|
import gulp from 'gulp';
|
|
5
5
|
import loadPostcssConfig from 'postcss-load-config';
|
|
6
6
|
import pc from 'picocolors';
|
|
7
|
+
import { getPackageInfo } from 'local-pkg';
|
|
7
8
|
import createDebug from 'debug';
|
|
8
9
|
import { createPlugins } from 'weapp-tailwindcss/gulp';
|
|
9
10
|
import postcssrc from 'gulp-postcss';
|
|
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) {
|
|
@@ -67,272 +71,55 @@ function createDefu(merger) {
|
|
|
67
71
|
}
|
|
68
72
|
const defu = createDefu();
|
|
69
73
|
|
|
70
|
-
const
|
|
74
|
+
const version = "0.0.0-alpha.7";
|
|
71
75
|
|
|
72
|
-
|
|
73
|
-
AssetType2["JavaScript"] = "javascript";
|
|
74
|
-
AssetType2["Json"] = "json";
|
|
75
|
-
AssetType2["Css"] = "css";
|
|
76
|
-
AssetType2["Html"] = "html";
|
|
77
|
-
return AssetType2;
|
|
78
|
-
})(AssetType || {});
|
|
76
|
+
const debug = createDebug("weapp-tw-cli");
|
|
79
77
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
78
|
+
var __defProp = Object.defineProperty;
|
|
79
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
80
|
+
var __publicField = (obj, key, value) => {
|
|
81
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
82
|
+
return value;
|
|
83
|
+
};
|
|
84
|
+
class GlobsSet {
|
|
85
|
+
constructor() {
|
|
86
|
+
__publicField(this, "includeSet");
|
|
87
|
+
__publicField(this, "excludeSet");
|
|
88
|
+
this.includeSet = /* @__PURE__ */ new Set();
|
|
89
|
+
this.excludeSet = /* @__PURE__ */ new Set();
|
|
90
|
+
}
|
|
91
|
+
isExcludeGlob(value) {
|
|
92
|
+
return value[0] === "!";
|
|
93
|
+
}
|
|
94
|
+
addSingle(value) {
|
|
95
|
+
return this.isExcludeGlob(value) ? this.excludeSet.add(value) : this.includeSet.add(value);
|
|
96
|
+
}
|
|
97
|
+
add(...value) {
|
|
85
98
|
for (const v of value) {
|
|
86
99
|
if (Array.isArray(v)) {
|
|
87
100
|
for (const vv of v) {
|
|
88
|
-
|
|
101
|
+
this.addSingle(vv);
|
|
89
102
|
}
|
|
90
103
|
} else {
|
|
91
|
-
|
|
104
|
+
this.addSingle(v);
|
|
92
105
|
}
|
|
93
106
|
}
|
|
94
107
|
}
|
|
95
|
-
|
|
96
|
-
|
|
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
|
-
});
|
|
108
|
+
dump() {
|
|
109
|
+
return [...this.includeSet, ...this.excludeSet];
|
|
162
110
|
}
|
|
163
|
-
|
|
164
|
-
|
|
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
|
-
});
|
|
111
|
+
dumpIgnored() {
|
|
112
|
+
return [...this.excludeSet].map((x) => x.slice(1));
|
|
178
113
|
}
|
|
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
114
|
}
|
|
202
115
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
"
|
|
208
|
-
|
|
209
|
-
|
|
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
|
-
}
|
|
116
|
+
var AssetType = /* @__PURE__ */ ((AssetType2) => {
|
|
117
|
+
AssetType2["JavaScript"] = "javascript";
|
|
118
|
+
AssetType2["Json"] = "json";
|
|
119
|
+
AssetType2["Css"] = "css";
|
|
120
|
+
AssetType2["Html"] = "html";
|
|
121
|
+
return AssetType2;
|
|
122
|
+
})(AssetType || {});
|
|
336
123
|
|
|
337
124
|
function getDefaultExportFromCjs (x) {
|
|
338
125
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
@@ -370,10 +157,10 @@ var isobject = function isObject(val) {
|
|
|
370
157
|
* Released under the MIT License.
|
|
371
158
|
*/
|
|
372
159
|
|
|
373
|
-
var isObject$
|
|
160
|
+
var isObject$3 = isobject;
|
|
374
161
|
|
|
375
162
|
function isObjectObject(o) {
|
|
376
|
-
return isObject$
|
|
163
|
+
return isObject$3(o) === true
|
|
377
164
|
&& Object.prototype.toString.call(o) === '[object Object]';
|
|
378
165
|
}
|
|
379
166
|
|
|
@@ -410,7 +197,7 @@ const { deleteProperty } = Reflect;
|
|
|
410
197
|
const isPrimitive = isPrimitive$1;
|
|
411
198
|
const isPlainObject = isPlainObject$1;
|
|
412
199
|
|
|
413
|
-
const isObject$
|
|
200
|
+
const isObject$2 = value => {
|
|
414
201
|
return (typeof value === 'object' && value !== null) || typeof value === 'function';
|
|
415
202
|
};
|
|
416
203
|
|
|
@@ -528,7 +315,7 @@ const assignProp = (obj, prop, value, options) => {
|
|
|
528
315
|
};
|
|
529
316
|
|
|
530
317
|
const setValue = (target, path, value, options) => {
|
|
531
|
-
if (!path || !isObject$
|
|
318
|
+
if (!path || !isObject$2(target)) return target;
|
|
532
319
|
|
|
533
320
|
const keys = split$1(path, options);
|
|
534
321
|
let obj = target;
|
|
@@ -549,7 +336,7 @@ const setValue = (target, path, value, options) => {
|
|
|
549
336
|
continue;
|
|
550
337
|
}
|
|
551
338
|
|
|
552
|
-
if (!isObject$
|
|
339
|
+
if (!isObject$2(obj[key])) {
|
|
553
340
|
obj[key] = {};
|
|
554
341
|
}
|
|
555
342
|
|
|
@@ -576,10 +363,10 @@ const set = /*@__PURE__*/getDefaultExportFromCjs(setValue_1);
|
|
|
576
363
|
* Released under the MIT License.
|
|
577
364
|
*/
|
|
578
365
|
|
|
579
|
-
const isObject = isobject;
|
|
366
|
+
const isObject$1 = isobject;
|
|
580
367
|
|
|
581
368
|
var getValue = function(target, path, options) {
|
|
582
|
-
if (!isObject(options)) {
|
|
369
|
+
if (!isObject$1(options)) {
|
|
583
370
|
options = { default: options };
|
|
584
371
|
}
|
|
585
372
|
|
|
@@ -677,11 +464,333 @@ function isValid(key, target, options) {
|
|
|
677
464
|
}
|
|
678
465
|
|
|
679
466
|
function isValidObject(val) {
|
|
680
|
-
return isObject(val) || Array.isArray(val) || typeof val === 'function';
|
|
467
|
+
return isObject$1(val) || Array.isArray(val) || typeof val === 'function';
|
|
681
468
|
}
|
|
682
469
|
|
|
683
470
|
const get = /*@__PURE__*/getDefaultExportFromCjs(getValue);
|
|
684
471
|
|
|
472
|
+
function isObject(x) {
|
|
473
|
+
return typeof x === "object" && x !== null;
|
|
474
|
+
}
|
|
475
|
+
function promisify(task) {
|
|
476
|
+
return new Promise((resolve, reject) => {
|
|
477
|
+
if (Array.isArray(task)) {
|
|
478
|
+
return Promise.all(task.map((x) => promisify(x))).then(resolve).catch(reject);
|
|
479
|
+
} else {
|
|
480
|
+
if (task.destroyed) {
|
|
481
|
+
resolve(void 0);
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
484
|
+
task.on("finish", () => {
|
|
485
|
+
resolve(void 0);
|
|
486
|
+
}).on("error", (err) => {
|
|
487
|
+
reject(err);
|
|
488
|
+
});
|
|
489
|
+
}
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
function isSassLang(lang) {
|
|
494
|
+
return lang === "scss" || lang === "sass";
|
|
495
|
+
}
|
|
496
|
+
function isLessLang(lang) {
|
|
497
|
+
return lang === "less";
|
|
498
|
+
}
|
|
499
|
+
function isTsLang(lang) {
|
|
500
|
+
return lang === "ts";
|
|
501
|
+
}
|
|
502
|
+
async function getTasks(options) {
|
|
503
|
+
let { typescriptOptions } = options;
|
|
504
|
+
const { root: cwd, weappTailwindcssOptions, outDir, src: srcBase, extensions, exclude, include, postcssOptions, preprocessorOptions } = options;
|
|
505
|
+
const globsSet = new GlobsSet();
|
|
506
|
+
const base = srcBase ? srcBase + "/" : "";
|
|
507
|
+
const enableSass = Boolean(preprocessorOptions?.sass);
|
|
508
|
+
const enableLess = Boolean(preprocessorOptions?.less);
|
|
509
|
+
if (typescriptOptions === true) {
|
|
510
|
+
typescriptOptions = {
|
|
511
|
+
tsConfigFileName: "tsconfig.json"
|
|
512
|
+
};
|
|
513
|
+
} else if (isObject(typescriptOptions) && typescriptOptions.tsConfigFileName === void 0) {
|
|
514
|
+
typescriptOptions.tsConfigFileName = "tsconfig.json";
|
|
515
|
+
}
|
|
516
|
+
const enableTs = Boolean(typescriptOptions);
|
|
517
|
+
let sass;
|
|
518
|
+
if (enableSass) {
|
|
519
|
+
const sassLib = await import('sass');
|
|
520
|
+
sass = createSass(sassLib);
|
|
521
|
+
}
|
|
522
|
+
const { transformJs, transformWxml, transformWxss } = createPlugins(weappTailwindcssOptions);
|
|
523
|
+
function getGlobs(type) {
|
|
524
|
+
const globs = [];
|
|
525
|
+
if (typeof include === "function") {
|
|
526
|
+
globs.push(...include(type).map((x) => x));
|
|
527
|
+
}
|
|
528
|
+
if (typeof exclude === "function") {
|
|
529
|
+
globs.push(...exclude(type).map((x) => "!" + x));
|
|
530
|
+
} else if (Array.isArray(exclude)) {
|
|
531
|
+
globs.push(...exclude.map((x) => "!" + x));
|
|
532
|
+
}
|
|
533
|
+
globs.push(`!${outDir}/**/*`);
|
|
534
|
+
globs.push(`!./${outDir}/**/*`);
|
|
535
|
+
return globs;
|
|
536
|
+
}
|
|
537
|
+
function getJsTasks() {
|
|
538
|
+
const assetType = AssetType.JavaScript;
|
|
539
|
+
const globs = getGlobs(assetType);
|
|
540
|
+
globsSet.add(globs);
|
|
541
|
+
return extensions[assetType]?.map((x) => {
|
|
542
|
+
const src = `${base}**/*.${x}`;
|
|
543
|
+
globsSet.add(src);
|
|
544
|
+
const isTs = isTsLang(x);
|
|
545
|
+
const loadTs = enableTs && isTs;
|
|
546
|
+
let gulpTs;
|
|
547
|
+
if (enableTs && typeof typescriptOptions !== "boolean") {
|
|
548
|
+
gulpTs = typescript.createProject(typescriptOptions.tsConfigFileName ?? "tsconfig.json", typeof typescriptOptions === "boolean" ? {} : typescriptOptions);
|
|
549
|
+
}
|
|
550
|
+
return function JsTask() {
|
|
551
|
+
let chain = gulp.src([src, ...globs], { cwd, since: gulp.lastRun(JsTask) });
|
|
552
|
+
if (loadTs) {
|
|
553
|
+
chain = chain.pipe(gulpTs());
|
|
554
|
+
}
|
|
555
|
+
return promisify(
|
|
556
|
+
chain.pipe(
|
|
557
|
+
transformJs({
|
|
558
|
+
babelParserOptions: !enableTs && isTs ? {
|
|
559
|
+
plugins: ["typescript"]
|
|
560
|
+
} : void 0
|
|
561
|
+
})
|
|
562
|
+
).pipe(
|
|
563
|
+
gulpif(
|
|
564
|
+
loadTs,
|
|
565
|
+
rename({
|
|
566
|
+
extname: ".js"
|
|
567
|
+
})
|
|
568
|
+
)
|
|
569
|
+
).pipe(
|
|
570
|
+
gulp.dest(outDir, {
|
|
571
|
+
cwd
|
|
572
|
+
})
|
|
573
|
+
)
|
|
574
|
+
);
|
|
575
|
+
};
|
|
576
|
+
});
|
|
577
|
+
}
|
|
578
|
+
function getJsonTasks() {
|
|
579
|
+
const assetType = AssetType.Json;
|
|
580
|
+
const globs = getGlobs(assetType);
|
|
581
|
+
globsSet.add(globs);
|
|
582
|
+
return extensions[assetType]?.map((x) => {
|
|
583
|
+
const src = `${base}**/*.${x}`;
|
|
584
|
+
globsSet.add(src);
|
|
585
|
+
return function JsonTask() {
|
|
586
|
+
return promisify(
|
|
587
|
+
gulp.src([src, ...globs], { cwd, since: gulp.lastRun(JsonTask) }).pipe(
|
|
588
|
+
gulp.dest(outDir, {
|
|
589
|
+
cwd
|
|
590
|
+
})
|
|
591
|
+
)
|
|
592
|
+
);
|
|
593
|
+
};
|
|
594
|
+
});
|
|
595
|
+
}
|
|
596
|
+
function getCssTasks() {
|
|
597
|
+
const assetType = AssetType.Css;
|
|
598
|
+
const globs = getGlobs(assetType);
|
|
599
|
+
globsSet.add(globs);
|
|
600
|
+
return extensions[assetType]?.map((x) => {
|
|
601
|
+
const src = `${base}**/*.${x}`;
|
|
602
|
+
globsSet.add(src);
|
|
603
|
+
const loadSass = enableSass && isSassLang(x);
|
|
604
|
+
const loadLess = enableLess && isLessLang(x);
|
|
605
|
+
return function CssTask() {
|
|
606
|
+
let chain = gulp.src([src, ...globs], { cwd, since: gulp.lastRun(CssTask) });
|
|
607
|
+
if (loadSass) {
|
|
608
|
+
chain = chain.pipe(
|
|
609
|
+
sass.sync(
|
|
610
|
+
// @ts-ignore
|
|
611
|
+
typeof preprocessorOptions?.sass === "boolean" ? void 0 : preprocessorOptions?.sass
|
|
612
|
+
).on("error", sass.logError)
|
|
613
|
+
);
|
|
614
|
+
}
|
|
615
|
+
return promisify(
|
|
616
|
+
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(
|
|
617
|
+
gulpif(
|
|
618
|
+
loadSass || loadLess,
|
|
619
|
+
rename({
|
|
620
|
+
extname: ".wxss"
|
|
621
|
+
})
|
|
622
|
+
)
|
|
623
|
+
).pipe(
|
|
624
|
+
gulp.dest(outDir, {
|
|
625
|
+
cwd
|
|
626
|
+
})
|
|
627
|
+
)
|
|
628
|
+
);
|
|
629
|
+
};
|
|
630
|
+
});
|
|
631
|
+
}
|
|
632
|
+
function getHtmlTasks() {
|
|
633
|
+
const assetType = AssetType.Html;
|
|
634
|
+
const globs = getGlobs(assetType);
|
|
635
|
+
globsSet.add(globs);
|
|
636
|
+
return extensions[assetType]?.map((x) => {
|
|
637
|
+
const src = `${base}**/*.${x}`;
|
|
638
|
+
globsSet.add(src);
|
|
639
|
+
return function HtmlTask() {
|
|
640
|
+
return promisify(
|
|
641
|
+
gulp.src([src, ...globs], { cwd, since: gulp.lastRun(HtmlTask) }).pipe(transformWxml()).pipe(
|
|
642
|
+
gulp.dest(outDir, {
|
|
643
|
+
cwd
|
|
644
|
+
})
|
|
645
|
+
)
|
|
646
|
+
);
|
|
647
|
+
};
|
|
648
|
+
});
|
|
649
|
+
}
|
|
650
|
+
function copyOthers() {
|
|
651
|
+
if (Array.isArray(include)) {
|
|
652
|
+
const globs = include.map((x) => {
|
|
653
|
+
return `${base}${x}`;
|
|
654
|
+
});
|
|
655
|
+
globsSet.add(globs);
|
|
656
|
+
return promisify(
|
|
657
|
+
gulp.src(globs, { cwd, since: gulp.lastRun(copyOthers) }).pipe(
|
|
658
|
+
gulp.dest(outDir, {
|
|
659
|
+
cwd
|
|
660
|
+
})
|
|
661
|
+
)
|
|
662
|
+
);
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
return {
|
|
666
|
+
getGlobs,
|
|
667
|
+
getJsTasks,
|
|
668
|
+
getJsonTasks,
|
|
669
|
+
getCssTasks,
|
|
670
|
+
getHtmlTasks,
|
|
671
|
+
copyOthers,
|
|
672
|
+
globsSet
|
|
673
|
+
};
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
const defaultJavascriptExtensions = ["js"];
|
|
677
|
+
const defaultTypescriptExtensions = ["ts"];
|
|
678
|
+
const defaultWxsExtensions = ["wxs"];
|
|
679
|
+
const defaultNodeModulesDirs = [
|
|
680
|
+
"**/node_modules/**",
|
|
681
|
+
"**/miniprogram_npm/**",
|
|
682
|
+
"**/project.config.json/**",
|
|
683
|
+
"**/project.private.config.json/**",
|
|
684
|
+
"**/package.json/**",
|
|
685
|
+
"postcss.config.js",
|
|
686
|
+
"tailwind.config.js",
|
|
687
|
+
"weapp-tw.config.js"
|
|
688
|
+
];
|
|
689
|
+
async function createBuilder(options) {
|
|
690
|
+
let postcssOptionsFromConfig;
|
|
691
|
+
try {
|
|
692
|
+
postcssOptionsFromConfig = await loadPostcssConfig({ cwd: options?.root });
|
|
693
|
+
} catch {
|
|
694
|
+
}
|
|
695
|
+
const opt = defu(options, {
|
|
696
|
+
outDir: "dist",
|
|
697
|
+
weappTailwindcssOptions: {},
|
|
698
|
+
clean: true,
|
|
699
|
+
src: "",
|
|
700
|
+
exclude: [...defaultNodeModulesDirs],
|
|
701
|
+
extensions: {
|
|
702
|
+
javascript: [...defaultJavascriptExtensions, ...defaultTypescriptExtensions, ...defaultWxsExtensions],
|
|
703
|
+
html: ["wxml"],
|
|
704
|
+
css: ["wxss", "less", "sass", "scss"],
|
|
705
|
+
json: ["json"]
|
|
706
|
+
},
|
|
707
|
+
watchOptions: {
|
|
708
|
+
cwd: options?.root,
|
|
709
|
+
events: ["add", "change", "unlink", "ready"]
|
|
710
|
+
},
|
|
711
|
+
postcssOptions: postcssOptionsFromConfig
|
|
712
|
+
});
|
|
713
|
+
const { copyOthers, getCssTasks, getHtmlTasks, getJsTasks, getJsonTasks, globsSet } = await getTasks(opt);
|
|
714
|
+
const tasks = {
|
|
715
|
+
css: getCssTasks(),
|
|
716
|
+
html: getHtmlTasks(),
|
|
717
|
+
json: getJsonTasks(),
|
|
718
|
+
js: getJsTasks(),
|
|
719
|
+
extra: [copyOthers]
|
|
720
|
+
};
|
|
721
|
+
async function runTasks() {
|
|
722
|
+
debug("run tasks start");
|
|
723
|
+
for (const [key, value] of Object.entries(tasks)) {
|
|
724
|
+
if (value) {
|
|
725
|
+
debug(`run task ${pc.bold(pc.green(key))} start`);
|
|
726
|
+
for (const task of value) {
|
|
727
|
+
await task();
|
|
728
|
+
}
|
|
729
|
+
debug(`run task ${pc.bold(pc.green(key))} end`);
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
debug("run tasks end");
|
|
733
|
+
}
|
|
734
|
+
const { clean, outDir, root: cwd, watchOptions } = opt;
|
|
735
|
+
return {
|
|
736
|
+
watcher: void 0,
|
|
737
|
+
async build() {
|
|
738
|
+
if (clean) {
|
|
739
|
+
debug("del start");
|
|
740
|
+
const { deleteAsync } = await import('del');
|
|
741
|
+
const patterns = [outDir + "/**"];
|
|
742
|
+
await deleteAsync(patterns, { cwd, ignore: defaultNodeModulesDirs });
|
|
743
|
+
debug("del end");
|
|
744
|
+
}
|
|
745
|
+
ensureDirSync(path.resolve(cwd, outDir));
|
|
746
|
+
await runTasks();
|
|
747
|
+
return this;
|
|
748
|
+
},
|
|
749
|
+
watch() {
|
|
750
|
+
ensureDirSync(path.resolve(cwd, outDir));
|
|
751
|
+
const dumps = globsSet.dump();
|
|
752
|
+
const arr = (Array.isArray(watchOptions.ignored) ? watchOptions.ignored : [watchOptions.ignored]).filter(Boolean);
|
|
753
|
+
watchOptions.ignored = [...globsSet.dumpIgnored(), ...arr];
|
|
754
|
+
const watcher = gulp.watch(dumps, watchOptions, async (cb) => {
|
|
755
|
+
try {
|
|
756
|
+
await runTasks();
|
|
757
|
+
cb();
|
|
758
|
+
} catch (error) {
|
|
759
|
+
cb(error);
|
|
760
|
+
}
|
|
761
|
+
});
|
|
762
|
+
watcher.on("change", function(path2) {
|
|
763
|
+
console.log(`${pc.green("changed")} ${path2}`);
|
|
764
|
+
});
|
|
765
|
+
watcher.on("add", function(path2) {
|
|
766
|
+
console.log(`${pc.green("add")} ${path2}`);
|
|
767
|
+
});
|
|
768
|
+
watcher.on("unlink", function(path2) {
|
|
769
|
+
console.log(`${pc.green("remove")} ${path2}`);
|
|
770
|
+
});
|
|
771
|
+
watcher.on("ready", async function() {
|
|
772
|
+
const meta = await getPackageInfo("weapp-tailwindcss");
|
|
773
|
+
let weappTwVersionStr = "";
|
|
774
|
+
if (meta) {
|
|
775
|
+
weappTwVersionStr = `(${pc.blue(pc.underline(meta.version))})`;
|
|
776
|
+
}
|
|
777
|
+
console.log(`${pc.bold(`${pc.green("weapp")}-${pc.blue("tailwindcss")}`)}${weappTwVersionStr} ${pc.cyan("cli")}(${pc.blue(pc.underline(version))}) is ready!`);
|
|
778
|
+
});
|
|
779
|
+
this.watcher = watcher;
|
|
780
|
+
return this;
|
|
781
|
+
},
|
|
782
|
+
globsSet
|
|
783
|
+
};
|
|
784
|
+
}
|
|
785
|
+
async function build(options) {
|
|
786
|
+
const builder = await createBuilder(options);
|
|
787
|
+
return await builder.build();
|
|
788
|
+
}
|
|
789
|
+
async function watch(options) {
|
|
790
|
+
const builder = await createBuilder(options);
|
|
791
|
+
return await builder.watch();
|
|
792
|
+
}
|
|
793
|
+
|
|
685
794
|
function createConfigLoader(root) {
|
|
686
795
|
const explorer = cosmiconfigSync("weapp-tw");
|
|
687
796
|
function search(searchFrom = root) {
|
|
@@ -755,6 +864,7 @@ function updatePackageJson(options) {
|
|
|
755
864
|
const packageJson = fs.readJSONSync(packageJsonPath);
|
|
756
865
|
set(packageJson, "scripts.dev", "weapp-tw dev");
|
|
757
866
|
set(packageJson, "scripts.build", "weapp-tw build");
|
|
867
|
+
set(packageJson, "scripts.postinstall", "weapp-tw patch");
|
|
758
868
|
fs.outputJSONSync(dest ?? packageJsonPath, packageJson, {
|
|
759
869
|
spaces: 2
|
|
760
870
|
});
|
|
@@ -785,7 +895,9 @@ export default defineConfig(${configOptionsStr})
|
|
|
785
895
|
fs.writeFileSync(
|
|
786
896
|
configPath,
|
|
787
897
|
`/** @type {import('@weapp-tailwindcss/cli').UserConfig} */
|
|
788
|
-
|
|
898
|
+
const config = ${configOptionsStr}
|
|
899
|
+
|
|
900
|
+
module.exports = config
|
|
789
901
|
`,
|
|
790
902
|
"utf8"
|
|
791
903
|
);
|