This repository has been archived by the owner on Jun 1, 2023. It is now read-only.
generated from Mister-Hope/miniapp-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
126 lines (98 loc) · 3.11 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
const { dest, parallel, src, watch } = require("gulp");
const rename = require("gulp-rename");
const { sassSync } = require("@mr-hope/gulp-sass");
const PluginError = require("plugin-error");
const typescript = require("gulp-typescript");
const { Transform } = require("stream");
const appTSProject = typescript.createProject("tsconfig.app.json");
const cloudTSProject = typescript.createProject("tsconfig.cloud.json");
const buildWXSS = () =>
src("app/**/*.scss")
.pipe(
sassSync({
// use `@` as hack for remaining '@import'
importer: (url) => {
if (url.includes(".css")) return null;
return { contents: `@import "${url}.css"` };
},
}).on("error", sassSync.logError)
)
.pipe(rename({ extname: ".wxss" }))
.pipe(
new Transform({
objectMode: true,
transform(chunk, _enc, callback) {
if (chunk.isNull()) {
this.push(chunk);
return callback();
}
if (chunk.isStream()) {
this.emit(
"error",
new PluginError("Sass", "Streaming not supported")
);
return callback();
}
const content = chunk.contents
.toString()
.replace(/@import "@(.*?)\.css"/gu, '@import "$1.wxss"');
chunk.contents = Buffer.from(content);
this.push(chunk);
callback();
},
})
)
.pipe(dest("dist/app"));
const moveAppFiles = () =>
src("app/**/*.{wxml,wxs,json,svg,png,webp}").pipe(dest("dist/app"));
const moveCloudFiles = () => src("cloud/**/*.json").pipe(dest("dist/cloud"));
const watchWXSS = () =>
watch("app/**/*.scss", { ignoreInitial: false }, buildWXSS);
const buildAppTypesciprt = () =>
appTSProject.src().pipe(appTSProject()).pipe(dest("dist/app"));
const buildCloudTypesciprt = () =>
cloudTSProject.src().pipe(cloudTSProject()).pipe(dest("dist/cloud"));
const watchAppTypescript = () =>
watch("app/**/*.ts", { ignoreInitial: false }, buildAppTypesciprt);
const watchCloudTypescript = () =>
watch("cloud/**/*.ts", { ignoreInitial: false }, buildCloudTypesciprt);
const watchAppFiles = () =>
watch(
"app/**/*.{wxml,wxs,json,svg,png,webp}",
{ ignoreInitial: false },
moveAppFiles
);
const watchCloudFiles = () =>
watch(
"cloud/**/*.{wxml,wxs,json,svg,png}",
{ ignoreInitial: false },
moveCloudFiles
);
const watchApp = parallel(watchWXSS, watchAppTypescript, watchAppFiles);
const watchCloud = parallel(watchCloudTypescript, watchCloudFiles);
const watchCommand = parallel(
watchWXSS,
watchAppTypescript,
watchCloudTypescript,
watchAppFiles,
watchCloudFiles
);
const buildApp = parallel(buildWXSS, buildAppTypesciprt, moveAppFiles);
const buildCloud = parallel(
buildCloudTypesciprt,
moveCloudFiles
);
const build = parallel(
buildWXSS,
buildAppTypesciprt,
buildCloudTypesciprt,
moveAppFiles,
moveCloudFiles
);
exports.watchApp = watchApp;
exports.watchCloud = watchCloud;
exports.watch = watchCommand;
exports.buildApp = buildApp;
exports.buildCloud = buildCloud;
exports.build = build;
exports.default = build;