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