@weapp-tailwindcss/cli 1.0.2 → 1.0.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/README.md +5 -1
- package/dist/index.cjs +132 -100
- package/dist/index.d.cts +8 -1
- package/dist/index.d.mts +8 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.mjs +132 -100
- package/package.json +33 -29
package/README.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -90,10 +90,48 @@ function createDefu(merger) {
|
|
|
90
90
|
}
|
|
91
91
|
const defu = createDefu();
|
|
92
92
|
|
|
93
|
-
const version = "1.0.
|
|
93
|
+
const version = "1.0.3";
|
|
94
94
|
|
|
95
95
|
const debug = createDebug__default("weapp-tw-cli");
|
|
96
96
|
|
|
97
|
+
const defaultJavascriptExtensions = ["js"];
|
|
98
|
+
const defaultTypescriptExtensions = ["ts"];
|
|
99
|
+
const defaultWxsExtensions = ["wxs"];
|
|
100
|
+
const defaultNodeModulesDirs = [
|
|
101
|
+
"**/node_modules/**",
|
|
102
|
+
"**/miniprogram_npm/**",
|
|
103
|
+
"**/project.config.json/**",
|
|
104
|
+
"**/project.private.config.json/**",
|
|
105
|
+
"**/package.json/**",
|
|
106
|
+
"postcss.config.js",
|
|
107
|
+
"tailwind.config.js",
|
|
108
|
+
"weapp-tw.config.js"
|
|
109
|
+
];
|
|
110
|
+
function noop() {
|
|
111
|
+
}
|
|
112
|
+
function getDefaultOptions(options, postcssOptionsFromConfig) {
|
|
113
|
+
return {
|
|
114
|
+
outDir: "dist",
|
|
115
|
+
weappTailwindcssOptions: {},
|
|
116
|
+
clean: true,
|
|
117
|
+
src: "",
|
|
118
|
+
exclude: [...defaultNodeModulesDirs],
|
|
119
|
+
include: ["**/*.{png,jpg,jpeg,gif,svg,webp}"],
|
|
120
|
+
extensions: {
|
|
121
|
+
javascript: [...defaultJavascriptExtensions, ...defaultTypescriptExtensions, ...defaultWxsExtensions],
|
|
122
|
+
html: ["wxml"],
|
|
123
|
+
css: ["wxss", "less", "sass", "scss"],
|
|
124
|
+
json: ["json"]
|
|
125
|
+
},
|
|
126
|
+
watchOptions: {
|
|
127
|
+
cwd: options?.root,
|
|
128
|
+
events: ["add", "change", "unlink", "ready"]
|
|
129
|
+
},
|
|
130
|
+
postcssOptions: postcssOptionsFromConfig,
|
|
131
|
+
gulpChain: noop
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
97
135
|
var __defProp = Object.defineProperty;
|
|
98
136
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
99
137
|
var __publicField = (obj, key, value) => {
|
|
@@ -132,6 +170,10 @@ class GlobsSet {
|
|
|
132
170
|
}
|
|
133
171
|
}
|
|
134
172
|
|
|
173
|
+
function isStream(stream, { checkOpen = true } = {}) {
|
|
174
|
+
return stream !== null && typeof stream === "object" && (stream.writable || stream.readable || !checkOpen || stream.writable === void 0 && stream.readable === void 0) && typeof stream.pipe === "function";
|
|
175
|
+
}
|
|
176
|
+
|
|
135
177
|
var AssetType = /* @__PURE__ */ ((AssetType2) => {
|
|
136
178
|
AssetType2["JavaScript"] = "javascript";
|
|
137
179
|
AssetType2["Json"] = "json";
|
|
@@ -508,7 +550,6 @@ function promisify(task) {
|
|
|
508
550
|
}
|
|
509
551
|
});
|
|
510
552
|
}
|
|
511
|
-
|
|
512
553
|
function isSassLang(lang) {
|
|
513
554
|
return lang === "scss" || lang === "sass";
|
|
514
555
|
}
|
|
@@ -518,6 +559,17 @@ function isLessLang(lang) {
|
|
|
518
559
|
function isTsLang(lang) {
|
|
519
560
|
return lang === "ts";
|
|
520
561
|
}
|
|
562
|
+
|
|
563
|
+
function normalizePlugin(plugin) {
|
|
564
|
+
if (isStream(plugin)) {
|
|
565
|
+
return plugin;
|
|
566
|
+
} else if (typeof plugin === "function") {
|
|
567
|
+
return plugin.apply(plugin);
|
|
568
|
+
} else if (Array.isArray(plugin)) {
|
|
569
|
+
const [fn, ...args] = plugin;
|
|
570
|
+
return fn.apply(fn, args);
|
|
571
|
+
}
|
|
572
|
+
}
|
|
521
573
|
async function getTasks(options) {
|
|
522
574
|
let { typescriptOptions } = options;
|
|
523
575
|
const {
|
|
@@ -529,12 +581,20 @@ async function getTasks(options) {
|
|
|
529
581
|
exclude,
|
|
530
582
|
include,
|
|
531
583
|
postcssOptions,
|
|
532
|
-
preprocessorOptions
|
|
584
|
+
preprocessorOptions,
|
|
585
|
+
gulpChain
|
|
533
586
|
} = options;
|
|
534
587
|
const globsSet = new GlobsSet();
|
|
535
588
|
const base = srcBase ? `${srcBase}/` : "";
|
|
536
589
|
const enableSass = Boolean(preprocessorOptions?.sass);
|
|
537
590
|
const enableLess = Boolean(preprocessorOptions?.less);
|
|
591
|
+
function resolvePipes(plugins, type) {
|
|
592
|
+
const newPlugins = gulpChain(plugins, type);
|
|
593
|
+
if (newPlugins === void 0) {
|
|
594
|
+
return plugins;
|
|
595
|
+
}
|
|
596
|
+
return newPlugins.map((x) => normalizePlugin(x)).filter((x) => x);
|
|
597
|
+
}
|
|
538
598
|
if (typescriptOptions === true) {
|
|
539
599
|
typescriptOptions = {
|
|
540
600
|
tsConfigFileName: "tsconfig.json"
|
|
@@ -581,29 +641,28 @@ async function getTasks(options) {
|
|
|
581
641
|
}
|
|
582
642
|
return function JsTask() {
|
|
583
643
|
let chain = gulp__default.src([src, ...globs], { cwd, since: gulp__default.lastRun(JsTask) });
|
|
644
|
+
const pipes = [];
|
|
584
645
|
if (loadTs) {
|
|
585
|
-
|
|
646
|
+
pipes.push(gulpTs());
|
|
586
647
|
}
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
)
|
|
606
|
-
);
|
|
648
|
+
pipes.push(transformJs({
|
|
649
|
+
babelParserOptions: !enableTs && isTs ? {
|
|
650
|
+
plugins: ["typescript"]
|
|
651
|
+
} : void 0
|
|
652
|
+
}));
|
|
653
|
+
pipes.push(gulpif__default(
|
|
654
|
+
loadTs,
|
|
655
|
+
rename__default({
|
|
656
|
+
extname: ".js"
|
|
657
|
+
})
|
|
658
|
+
));
|
|
659
|
+
pipes.push(gulp__default.dest(outDir, {
|
|
660
|
+
cwd
|
|
661
|
+
}));
|
|
662
|
+
for (const p of resolvePipes(pipes, assetType)) {
|
|
663
|
+
chain = chain.pipe(p);
|
|
664
|
+
}
|
|
665
|
+
return promisify(chain);
|
|
607
666
|
};
|
|
608
667
|
});
|
|
609
668
|
}
|
|
@@ -615,13 +674,14 @@ async function getTasks(options) {
|
|
|
615
674
|
const src = `${base}**/*.${x}`;
|
|
616
675
|
globsSet.add(src);
|
|
617
676
|
return function JsonTask() {
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
)
|
|
624
|
-
|
|
677
|
+
const pipes = [gulp__default.dest(outDir, {
|
|
678
|
+
cwd
|
|
679
|
+
})];
|
|
680
|
+
let chain = gulp__default.src([src, ...globs], { cwd, since: gulp__default.lastRun(JsonTask) });
|
|
681
|
+
for (const p of resolvePipes(pipes, assetType)) {
|
|
682
|
+
chain = chain.pipe(p);
|
|
683
|
+
}
|
|
684
|
+
return promisify(chain);
|
|
625
685
|
};
|
|
626
686
|
});
|
|
627
687
|
}
|
|
@@ -636,33 +696,32 @@ async function getTasks(options) {
|
|
|
636
696
|
const loadLess = enableLess && isLessLang(x);
|
|
637
697
|
return function CssTask() {
|
|
638
698
|
let chain = gulp__default.src([src, ...globs], { cwd, since: gulp__default.lastRun(CssTask) });
|
|
699
|
+
const pipes = [];
|
|
639
700
|
if (loadSass) {
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
).on("error", sass.logError)
|
|
645
|
-
);
|
|
701
|
+
pipes.push(sass.sync(
|
|
702
|
+
// @ts-ignore
|
|
703
|
+
typeof preprocessorOptions?.sass === "boolean" ? void 0 : preprocessorOptions?.sass
|
|
704
|
+
).on("error", sass.logError));
|
|
646
705
|
}
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
);
|
|
706
|
+
pipes.push(gulpif__default(
|
|
707
|
+
loadLess,
|
|
708
|
+
less__default(typeof preprocessorOptions?.less === "boolean" ? void 0 : preprocessorOptions?.less)
|
|
709
|
+
));
|
|
710
|
+
pipes.push(gulpif__default(Boolean(postcssOptions), postcssrc__default(postcssOptions?.plugins, postcssOptions?.options)));
|
|
711
|
+
pipes.push(transformWxss());
|
|
712
|
+
pipes.push(gulpif__default(
|
|
713
|
+
loadSass || loadLess,
|
|
714
|
+
rename__default({
|
|
715
|
+
extname: ".wxss"
|
|
716
|
+
})
|
|
717
|
+
));
|
|
718
|
+
pipes.push(gulp__default.dest(outDir, {
|
|
719
|
+
cwd
|
|
720
|
+
}));
|
|
721
|
+
for (const p of resolvePipes(pipes, assetType)) {
|
|
722
|
+
chain = chain.pipe(p);
|
|
723
|
+
}
|
|
724
|
+
return promisify(chain);
|
|
666
725
|
};
|
|
667
726
|
});
|
|
668
727
|
}
|
|
@@ -674,12 +733,15 @@ async function getTasks(options) {
|
|
|
674
733
|
const src = `${base}**/*.${x}`;
|
|
675
734
|
globsSet.add(src);
|
|
676
735
|
return function HtmlTask() {
|
|
736
|
+
let chain = gulp__default.src([src, ...globs], { cwd, since: gulp__default.lastRun(HtmlTask) });
|
|
737
|
+
const pipes = [transformWxml(), gulp__default.dest(outDir, {
|
|
738
|
+
cwd
|
|
739
|
+
})];
|
|
740
|
+
for (const p of resolvePipes(pipes, assetType)) {
|
|
741
|
+
chain = chain.pipe(p);
|
|
742
|
+
}
|
|
677
743
|
return promisify(
|
|
678
|
-
|
|
679
|
-
gulp__default.dest(outDir, {
|
|
680
|
-
cwd
|
|
681
|
-
})
|
|
682
|
-
)
|
|
744
|
+
chain
|
|
683
745
|
);
|
|
684
746
|
};
|
|
685
747
|
});
|
|
@@ -690,13 +752,14 @@ async function getTasks(options) {
|
|
|
690
752
|
return `${base}${x}`;
|
|
691
753
|
});
|
|
692
754
|
globsSet.add(globs);
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
)
|
|
699
|
-
|
|
755
|
+
let chain = gulp__default.src([...globs, ...outDirGlobs], { cwd, since: gulp__default.lastRun(copyOthers) });
|
|
756
|
+
const pipes = [gulp__default.dest(outDir, {
|
|
757
|
+
cwd
|
|
758
|
+
})];
|
|
759
|
+
for (const p of pipes) {
|
|
760
|
+
chain = chain.pipe(p);
|
|
761
|
+
}
|
|
762
|
+
return promisify(chain);
|
|
700
763
|
}
|
|
701
764
|
}
|
|
702
765
|
return {
|
|
@@ -710,44 +773,13 @@ async function getTasks(options) {
|
|
|
710
773
|
};
|
|
711
774
|
}
|
|
712
775
|
|
|
713
|
-
const defaultJavascriptExtensions = ["js"];
|
|
714
|
-
const defaultTypescriptExtensions = ["ts"];
|
|
715
|
-
const defaultWxsExtensions = ["wxs"];
|
|
716
|
-
const defaultNodeModulesDirs = [
|
|
717
|
-
"**/node_modules/**",
|
|
718
|
-
"**/miniprogram_npm/**",
|
|
719
|
-
"**/project.config.json/**",
|
|
720
|
-
"**/project.private.config.json/**",
|
|
721
|
-
"**/package.json/**",
|
|
722
|
-
"postcss.config.js",
|
|
723
|
-
"tailwind.config.js",
|
|
724
|
-
"weapp-tw.config.js"
|
|
725
|
-
];
|
|
726
776
|
async function createBuilder(options) {
|
|
727
777
|
let postcssOptionsFromConfig;
|
|
728
778
|
try {
|
|
729
779
|
postcssOptionsFromConfig = await loadPostcssConfig__default({ cwd: options?.root });
|
|
730
780
|
} catch {
|
|
731
781
|
}
|
|
732
|
-
const opt = defu(options,
|
|
733
|
-
outDir: "dist",
|
|
734
|
-
weappTailwindcssOptions: {},
|
|
735
|
-
clean: true,
|
|
736
|
-
src: "",
|
|
737
|
-
exclude: [...defaultNodeModulesDirs],
|
|
738
|
-
include: ["**/*.{png,jpg,jpeg,gif,svg,webp}"],
|
|
739
|
-
extensions: {
|
|
740
|
-
javascript: [...defaultJavascriptExtensions, ...defaultTypescriptExtensions, ...defaultWxsExtensions],
|
|
741
|
-
html: ["wxml"],
|
|
742
|
-
css: ["wxss", "less", "sass", "scss"],
|
|
743
|
-
json: ["json"]
|
|
744
|
-
},
|
|
745
|
-
watchOptions: {
|
|
746
|
-
cwd: options?.root,
|
|
747
|
-
events: ["add", "change", "unlink", "ready"]
|
|
748
|
-
},
|
|
749
|
-
postcssOptions: postcssOptionsFromConfig
|
|
750
|
-
});
|
|
782
|
+
const opt = defu(options, getDefaultOptions(options, postcssOptionsFromConfig));
|
|
751
783
|
const { copyOthers, getCssTasks, getHtmlTasks, getJsTasks, getJsonTasks, globsSet } = await getTasks(opt);
|
|
752
784
|
const tasks = {
|
|
753
785
|
css: getCssTasks(),
|
package/dist/index.d.cts
CHANGED
|
@@ -110,13 +110,20 @@ interface BuildOptions {
|
|
|
110
110
|
watchOptions: WatchOptions;
|
|
111
111
|
/**
|
|
112
112
|
* @group 2.编译支持
|
|
113
|
-
* @description typescript
|
|
113
|
+
* @description typescript 的编译配置,默认不传为不编译 ts
|
|
114
114
|
* @description 需要安装 typescript
|
|
115
115
|
*/
|
|
116
116
|
typescriptOptions: boolean | {
|
|
117
117
|
settings?: Settings;
|
|
118
118
|
tsConfigFileName?: string;
|
|
119
119
|
};
|
|
120
|
+
/**
|
|
121
|
+
* @group 2.编译支持
|
|
122
|
+
* @description 扩展 cli 里默认的 gulp 文件流处理方式
|
|
123
|
+
* 第一个参数为原型注册的内置插件, 第二个参数为处理的文件类型
|
|
124
|
+
* 返回一个新的插件数组为取代原先的处理流程,返回 undefined 为使用默认处理流程
|
|
125
|
+
*/
|
|
126
|
+
gulpChain: (plugins: any[], type: AssetType) => any[] | undefined;
|
|
120
127
|
}
|
|
121
128
|
type UserConfig = Partial<BuildOptions>;
|
|
122
129
|
|
package/dist/index.d.mts
CHANGED
|
@@ -110,13 +110,20 @@ interface BuildOptions {
|
|
|
110
110
|
watchOptions: WatchOptions;
|
|
111
111
|
/**
|
|
112
112
|
* @group 2.编译支持
|
|
113
|
-
* @description typescript
|
|
113
|
+
* @description typescript 的编译配置,默认不传为不编译 ts
|
|
114
114
|
* @description 需要安装 typescript
|
|
115
115
|
*/
|
|
116
116
|
typescriptOptions: boolean | {
|
|
117
117
|
settings?: Settings;
|
|
118
118
|
tsConfigFileName?: string;
|
|
119
119
|
};
|
|
120
|
+
/**
|
|
121
|
+
* @group 2.编译支持
|
|
122
|
+
* @description 扩展 cli 里默认的 gulp 文件流处理方式
|
|
123
|
+
* 第一个参数为原型注册的内置插件, 第二个参数为处理的文件类型
|
|
124
|
+
* 返回一个新的插件数组为取代原先的处理流程,返回 undefined 为使用默认处理流程
|
|
125
|
+
*/
|
|
126
|
+
gulpChain: (plugins: any[], type: AssetType) => any[] | undefined;
|
|
120
127
|
}
|
|
121
128
|
type UserConfig = Partial<BuildOptions>;
|
|
122
129
|
|
package/dist/index.d.ts
CHANGED
|
@@ -110,13 +110,20 @@ interface BuildOptions {
|
|
|
110
110
|
watchOptions: WatchOptions;
|
|
111
111
|
/**
|
|
112
112
|
* @group 2.编译支持
|
|
113
|
-
* @description typescript
|
|
113
|
+
* @description typescript 的编译配置,默认不传为不编译 ts
|
|
114
114
|
* @description 需要安装 typescript
|
|
115
115
|
*/
|
|
116
116
|
typescriptOptions: boolean | {
|
|
117
117
|
settings?: Settings;
|
|
118
118
|
tsConfigFileName?: string;
|
|
119
119
|
};
|
|
120
|
+
/**
|
|
121
|
+
* @group 2.编译支持
|
|
122
|
+
* @description 扩展 cli 里默认的 gulp 文件流处理方式
|
|
123
|
+
* 第一个参数为原型注册的内置插件, 第二个参数为处理的文件类型
|
|
124
|
+
* 返回一个新的插件数组为取代原先的处理流程,返回 undefined 为使用默认处理流程
|
|
125
|
+
*/
|
|
126
|
+
gulpChain: (plugins: any[], type: AssetType) => any[] | undefined;
|
|
120
127
|
}
|
|
121
128
|
type UserConfig = Partial<BuildOptions>;
|
|
122
129
|
|
package/dist/index.mjs
CHANGED
|
@@ -72,10 +72,48 @@ function createDefu(merger) {
|
|
|
72
72
|
}
|
|
73
73
|
const defu = createDefu();
|
|
74
74
|
|
|
75
|
-
const version = "1.0.
|
|
75
|
+
const version = "1.0.3";
|
|
76
76
|
|
|
77
77
|
const debug = createDebug("weapp-tw-cli");
|
|
78
78
|
|
|
79
|
+
const defaultJavascriptExtensions = ["js"];
|
|
80
|
+
const defaultTypescriptExtensions = ["ts"];
|
|
81
|
+
const defaultWxsExtensions = ["wxs"];
|
|
82
|
+
const defaultNodeModulesDirs = [
|
|
83
|
+
"**/node_modules/**",
|
|
84
|
+
"**/miniprogram_npm/**",
|
|
85
|
+
"**/project.config.json/**",
|
|
86
|
+
"**/project.private.config.json/**",
|
|
87
|
+
"**/package.json/**",
|
|
88
|
+
"postcss.config.js",
|
|
89
|
+
"tailwind.config.js",
|
|
90
|
+
"weapp-tw.config.js"
|
|
91
|
+
];
|
|
92
|
+
function noop() {
|
|
93
|
+
}
|
|
94
|
+
function getDefaultOptions(options, postcssOptionsFromConfig) {
|
|
95
|
+
return {
|
|
96
|
+
outDir: "dist",
|
|
97
|
+
weappTailwindcssOptions: {},
|
|
98
|
+
clean: true,
|
|
99
|
+
src: "",
|
|
100
|
+
exclude: [...defaultNodeModulesDirs],
|
|
101
|
+
include: ["**/*.{png,jpg,jpeg,gif,svg,webp}"],
|
|
102
|
+
extensions: {
|
|
103
|
+
javascript: [...defaultJavascriptExtensions, ...defaultTypescriptExtensions, ...defaultWxsExtensions],
|
|
104
|
+
html: ["wxml"],
|
|
105
|
+
css: ["wxss", "less", "sass", "scss"],
|
|
106
|
+
json: ["json"]
|
|
107
|
+
},
|
|
108
|
+
watchOptions: {
|
|
109
|
+
cwd: options?.root,
|
|
110
|
+
events: ["add", "change", "unlink", "ready"]
|
|
111
|
+
},
|
|
112
|
+
postcssOptions: postcssOptionsFromConfig,
|
|
113
|
+
gulpChain: noop
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
79
117
|
var __defProp = Object.defineProperty;
|
|
80
118
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
81
119
|
var __publicField = (obj, key, value) => {
|
|
@@ -114,6 +152,10 @@ class GlobsSet {
|
|
|
114
152
|
}
|
|
115
153
|
}
|
|
116
154
|
|
|
155
|
+
function isStream(stream, { checkOpen = true } = {}) {
|
|
156
|
+
return stream !== null && typeof stream === "object" && (stream.writable || stream.readable || !checkOpen || stream.writable === void 0 && stream.readable === void 0) && typeof stream.pipe === "function";
|
|
157
|
+
}
|
|
158
|
+
|
|
117
159
|
var AssetType = /* @__PURE__ */ ((AssetType2) => {
|
|
118
160
|
AssetType2["JavaScript"] = "javascript";
|
|
119
161
|
AssetType2["Json"] = "json";
|
|
@@ -490,7 +532,6 @@ function promisify(task) {
|
|
|
490
532
|
}
|
|
491
533
|
});
|
|
492
534
|
}
|
|
493
|
-
|
|
494
535
|
function isSassLang(lang) {
|
|
495
536
|
return lang === "scss" || lang === "sass";
|
|
496
537
|
}
|
|
@@ -500,6 +541,17 @@ function isLessLang(lang) {
|
|
|
500
541
|
function isTsLang(lang) {
|
|
501
542
|
return lang === "ts";
|
|
502
543
|
}
|
|
544
|
+
|
|
545
|
+
function normalizePlugin(plugin) {
|
|
546
|
+
if (isStream(plugin)) {
|
|
547
|
+
return plugin;
|
|
548
|
+
} else if (typeof plugin === "function") {
|
|
549
|
+
return plugin.apply(plugin);
|
|
550
|
+
} else if (Array.isArray(plugin)) {
|
|
551
|
+
const [fn, ...args] = plugin;
|
|
552
|
+
return fn.apply(fn, args);
|
|
553
|
+
}
|
|
554
|
+
}
|
|
503
555
|
async function getTasks(options) {
|
|
504
556
|
let { typescriptOptions } = options;
|
|
505
557
|
const {
|
|
@@ -511,12 +563,20 @@ async function getTasks(options) {
|
|
|
511
563
|
exclude,
|
|
512
564
|
include,
|
|
513
565
|
postcssOptions,
|
|
514
|
-
preprocessorOptions
|
|
566
|
+
preprocessorOptions,
|
|
567
|
+
gulpChain
|
|
515
568
|
} = options;
|
|
516
569
|
const globsSet = new GlobsSet();
|
|
517
570
|
const base = srcBase ? `${srcBase}/` : "";
|
|
518
571
|
const enableSass = Boolean(preprocessorOptions?.sass);
|
|
519
572
|
const enableLess = Boolean(preprocessorOptions?.less);
|
|
573
|
+
function resolvePipes(plugins, type) {
|
|
574
|
+
const newPlugins = gulpChain(plugins, type);
|
|
575
|
+
if (newPlugins === void 0) {
|
|
576
|
+
return plugins;
|
|
577
|
+
}
|
|
578
|
+
return newPlugins.map((x) => normalizePlugin(x)).filter((x) => x);
|
|
579
|
+
}
|
|
520
580
|
if (typescriptOptions === true) {
|
|
521
581
|
typescriptOptions = {
|
|
522
582
|
tsConfigFileName: "tsconfig.json"
|
|
@@ -563,29 +623,28 @@ async function getTasks(options) {
|
|
|
563
623
|
}
|
|
564
624
|
return function JsTask() {
|
|
565
625
|
let chain = gulp.src([src, ...globs], { cwd, since: gulp.lastRun(JsTask) });
|
|
626
|
+
const pipes = [];
|
|
566
627
|
if (loadTs) {
|
|
567
|
-
|
|
628
|
+
pipes.push(gulpTs());
|
|
568
629
|
}
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
)
|
|
588
|
-
);
|
|
630
|
+
pipes.push(transformJs({
|
|
631
|
+
babelParserOptions: !enableTs && isTs ? {
|
|
632
|
+
plugins: ["typescript"]
|
|
633
|
+
} : void 0
|
|
634
|
+
}));
|
|
635
|
+
pipes.push(gulpif(
|
|
636
|
+
loadTs,
|
|
637
|
+
rename({
|
|
638
|
+
extname: ".js"
|
|
639
|
+
})
|
|
640
|
+
));
|
|
641
|
+
pipes.push(gulp.dest(outDir, {
|
|
642
|
+
cwd
|
|
643
|
+
}));
|
|
644
|
+
for (const p of resolvePipes(pipes, assetType)) {
|
|
645
|
+
chain = chain.pipe(p);
|
|
646
|
+
}
|
|
647
|
+
return promisify(chain);
|
|
589
648
|
};
|
|
590
649
|
});
|
|
591
650
|
}
|
|
@@ -597,13 +656,14 @@ async function getTasks(options) {
|
|
|
597
656
|
const src = `${base}**/*.${x}`;
|
|
598
657
|
globsSet.add(src);
|
|
599
658
|
return function JsonTask() {
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
)
|
|
606
|
-
|
|
659
|
+
const pipes = [gulp.dest(outDir, {
|
|
660
|
+
cwd
|
|
661
|
+
})];
|
|
662
|
+
let chain = gulp.src([src, ...globs], { cwd, since: gulp.lastRun(JsonTask) });
|
|
663
|
+
for (const p of resolvePipes(pipes, assetType)) {
|
|
664
|
+
chain = chain.pipe(p);
|
|
665
|
+
}
|
|
666
|
+
return promisify(chain);
|
|
607
667
|
};
|
|
608
668
|
});
|
|
609
669
|
}
|
|
@@ -618,33 +678,32 @@ async function getTasks(options) {
|
|
|
618
678
|
const loadLess = enableLess && isLessLang(x);
|
|
619
679
|
return function CssTask() {
|
|
620
680
|
let chain = gulp.src([src, ...globs], { cwd, since: gulp.lastRun(CssTask) });
|
|
681
|
+
const pipes = [];
|
|
621
682
|
if (loadSass) {
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
).on("error", sass.logError)
|
|
627
|
-
);
|
|
683
|
+
pipes.push(sass.sync(
|
|
684
|
+
// @ts-ignore
|
|
685
|
+
typeof preprocessorOptions?.sass === "boolean" ? void 0 : preprocessorOptions?.sass
|
|
686
|
+
).on("error", sass.logError));
|
|
628
687
|
}
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
);
|
|
688
|
+
pipes.push(gulpif(
|
|
689
|
+
loadLess,
|
|
690
|
+
less(typeof preprocessorOptions?.less === "boolean" ? void 0 : preprocessorOptions?.less)
|
|
691
|
+
));
|
|
692
|
+
pipes.push(gulpif(Boolean(postcssOptions), postcssrc(postcssOptions?.plugins, postcssOptions?.options)));
|
|
693
|
+
pipes.push(transformWxss());
|
|
694
|
+
pipes.push(gulpif(
|
|
695
|
+
loadSass || loadLess,
|
|
696
|
+
rename({
|
|
697
|
+
extname: ".wxss"
|
|
698
|
+
})
|
|
699
|
+
));
|
|
700
|
+
pipes.push(gulp.dest(outDir, {
|
|
701
|
+
cwd
|
|
702
|
+
}));
|
|
703
|
+
for (const p of resolvePipes(pipes, assetType)) {
|
|
704
|
+
chain = chain.pipe(p);
|
|
705
|
+
}
|
|
706
|
+
return promisify(chain);
|
|
648
707
|
};
|
|
649
708
|
});
|
|
650
709
|
}
|
|
@@ -656,12 +715,15 @@ async function getTasks(options) {
|
|
|
656
715
|
const src = `${base}**/*.${x}`;
|
|
657
716
|
globsSet.add(src);
|
|
658
717
|
return function HtmlTask() {
|
|
718
|
+
let chain = gulp.src([src, ...globs], { cwd, since: gulp.lastRun(HtmlTask) });
|
|
719
|
+
const pipes = [transformWxml(), gulp.dest(outDir, {
|
|
720
|
+
cwd
|
|
721
|
+
})];
|
|
722
|
+
for (const p of resolvePipes(pipes, assetType)) {
|
|
723
|
+
chain = chain.pipe(p);
|
|
724
|
+
}
|
|
659
725
|
return promisify(
|
|
660
|
-
|
|
661
|
-
gulp.dest(outDir, {
|
|
662
|
-
cwd
|
|
663
|
-
})
|
|
664
|
-
)
|
|
726
|
+
chain
|
|
665
727
|
);
|
|
666
728
|
};
|
|
667
729
|
});
|
|
@@ -672,13 +734,14 @@ async function getTasks(options) {
|
|
|
672
734
|
return `${base}${x}`;
|
|
673
735
|
});
|
|
674
736
|
globsSet.add(globs);
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
)
|
|
681
|
-
|
|
737
|
+
let chain = gulp.src([...globs, ...outDirGlobs], { cwd, since: gulp.lastRun(copyOthers) });
|
|
738
|
+
const pipes = [gulp.dest(outDir, {
|
|
739
|
+
cwd
|
|
740
|
+
})];
|
|
741
|
+
for (const p of pipes) {
|
|
742
|
+
chain = chain.pipe(p);
|
|
743
|
+
}
|
|
744
|
+
return promisify(chain);
|
|
682
745
|
}
|
|
683
746
|
}
|
|
684
747
|
return {
|
|
@@ -692,44 +755,13 @@ async function getTasks(options) {
|
|
|
692
755
|
};
|
|
693
756
|
}
|
|
694
757
|
|
|
695
|
-
const defaultJavascriptExtensions = ["js"];
|
|
696
|
-
const defaultTypescriptExtensions = ["ts"];
|
|
697
|
-
const defaultWxsExtensions = ["wxs"];
|
|
698
|
-
const defaultNodeModulesDirs = [
|
|
699
|
-
"**/node_modules/**",
|
|
700
|
-
"**/miniprogram_npm/**",
|
|
701
|
-
"**/project.config.json/**",
|
|
702
|
-
"**/project.private.config.json/**",
|
|
703
|
-
"**/package.json/**",
|
|
704
|
-
"postcss.config.js",
|
|
705
|
-
"tailwind.config.js",
|
|
706
|
-
"weapp-tw.config.js"
|
|
707
|
-
];
|
|
708
758
|
async function createBuilder(options) {
|
|
709
759
|
let postcssOptionsFromConfig;
|
|
710
760
|
try {
|
|
711
761
|
postcssOptionsFromConfig = await loadPostcssConfig({ cwd: options?.root });
|
|
712
762
|
} catch {
|
|
713
763
|
}
|
|
714
|
-
const opt = defu(options,
|
|
715
|
-
outDir: "dist",
|
|
716
|
-
weappTailwindcssOptions: {},
|
|
717
|
-
clean: true,
|
|
718
|
-
src: "",
|
|
719
|
-
exclude: [...defaultNodeModulesDirs],
|
|
720
|
-
include: ["**/*.{png,jpg,jpeg,gif,svg,webp}"],
|
|
721
|
-
extensions: {
|
|
722
|
-
javascript: [...defaultJavascriptExtensions, ...defaultTypescriptExtensions, ...defaultWxsExtensions],
|
|
723
|
-
html: ["wxml"],
|
|
724
|
-
css: ["wxss", "less", "sass", "scss"],
|
|
725
|
-
json: ["json"]
|
|
726
|
-
},
|
|
727
|
-
watchOptions: {
|
|
728
|
-
cwd: options?.root,
|
|
729
|
-
events: ["add", "change", "unlink", "ready"]
|
|
730
|
-
},
|
|
731
|
-
postcssOptions: postcssOptionsFromConfig
|
|
732
|
-
});
|
|
764
|
+
const opt = defu(options, getDefaultOptions(options, postcssOptionsFromConfig));
|
|
733
765
|
const { copyOthers, getCssTasks, getHtmlTasks, getJsTasks, getJsonTasks, globsSet } = await getTasks(opt);
|
|
734
766
|
const tasks = {
|
|
735
767
|
css: getCssTasks(),
|
package/package.json
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weapp-tailwindcss/cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "The cli of weapp-tailwindcss",
|
|
5
|
-
"keywords": [
|
|
6
|
-
"weapp",
|
|
7
|
-
"tailwindcss",
|
|
8
|
-
"cli",
|
|
9
|
-
"plugin"
|
|
10
|
-
],
|
|
11
5
|
"author": "SonOfMagic <qq1324318532@gmail.com>",
|
|
12
6
|
"license": "MIT",
|
|
7
|
+
"homepage": "https://weapp-tw.icebreaker.top/docs/quick-start/native/install",
|
|
13
8
|
"bugs": {
|
|
14
9
|
"url": "https://github.com/sonofmagic/weapp-tailwindcss/issues"
|
|
15
10
|
},
|
|
16
|
-
"
|
|
11
|
+
"keywords": [
|
|
12
|
+
"weapp",
|
|
13
|
+
"tailwindcss",
|
|
14
|
+
"cli",
|
|
15
|
+
"plugin",
|
|
16
|
+
"gulp",
|
|
17
|
+
"native"
|
|
18
|
+
],
|
|
17
19
|
"sideEffects": false,
|
|
18
|
-
"type": "commonjs",
|
|
19
20
|
"exports": {
|
|
20
21
|
".": {
|
|
21
22
|
"types": "./dist/index.d.ts",
|
|
@@ -29,26 +30,6 @@
|
|
|
29
30
|
"files": [
|
|
30
31
|
"dist"
|
|
31
32
|
],
|
|
32
|
-
"dependencies": {
|
|
33
|
-
"commander": "^12.0.0",
|
|
34
|
-
"cosmiconfig": "^9.0.0",
|
|
35
|
-
"debug": "4.3.4",
|
|
36
|
-
"del": "^7.1.0",
|
|
37
|
-
"fs-extra": "^11.2.0",
|
|
38
|
-
"gulp": "^4.0.2",
|
|
39
|
-
"gulp-debug": "^5.0.1",
|
|
40
|
-
"gulp-if": "^3.0.0",
|
|
41
|
-
"gulp-less": "^5.0.0",
|
|
42
|
-
"gulp-plumber": "^1.2.1",
|
|
43
|
-
"gulp-postcss": "^10.0.0",
|
|
44
|
-
"gulp-rename": "^2.0.0",
|
|
45
|
-
"gulp-sass": "^5.1.0",
|
|
46
|
-
"gulp-typescript": "6.0.0-alpha.1",
|
|
47
|
-
"local-pkg": "^0.5.0",
|
|
48
|
-
"picocolors": "^1.0.0",
|
|
49
|
-
"postcss": "^8.4.38",
|
|
50
|
-
"postcss-load-config": "^5.1.0"
|
|
51
|
-
},
|
|
52
33
|
"peerDependencies": {
|
|
53
34
|
"less": "*",
|
|
54
35
|
"sass": "*",
|
|
@@ -66,10 +47,33 @@
|
|
|
66
47
|
"optional": true
|
|
67
48
|
}
|
|
68
49
|
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"commander": "^12.1.0",
|
|
52
|
+
"cosmiconfig": "^9.0.0",
|
|
53
|
+
"debug": "4.3.5",
|
|
54
|
+
"del": "^7.1.0",
|
|
55
|
+
"fs-extra": "^11.2.0",
|
|
56
|
+
"gulp": "^4.0.2",
|
|
57
|
+
"gulp-debug": "^5.0.1",
|
|
58
|
+
"gulp-if": "^3.0.0",
|
|
59
|
+
"gulp-less": "^5.0.0",
|
|
60
|
+
"gulp-plumber": "^1.2.1",
|
|
61
|
+
"gulp-postcss": "^10.0.0",
|
|
62
|
+
"gulp-rename": "^2.0.0",
|
|
63
|
+
"gulp-sass": "^5.1.0",
|
|
64
|
+
"gulp-typescript": "6.0.0-alpha.1",
|
|
65
|
+
"local-pkg": "^0.5.0",
|
|
66
|
+
"picocolors": "^1.0.1",
|
|
67
|
+
"postcss": "^8.4.38",
|
|
68
|
+
"postcss-load-config": "^5.1.0"
|
|
69
|
+
},
|
|
69
70
|
"publishConfig": {
|
|
70
71
|
"access": "public",
|
|
71
72
|
"registry": "https://registry.npmjs.org"
|
|
72
73
|
},
|
|
74
|
+
"devDependencies": {
|
|
75
|
+
"tailwindcss": "^3.4.3"
|
|
76
|
+
},
|
|
73
77
|
"scripts": {
|
|
74
78
|
"dev": "unbuild --sourcemap",
|
|
75
79
|
"build": "unbuild",
|