Skip to content

Commit d5c2da4

Browse files
committed
Merge branch 'develop' into ci/check-email
2 parents c7ce398 + ee98164 commit d5c2da4

File tree

228 files changed

+3397
-3430
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

228 files changed

+3397
-3430
lines changed

.eslintignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
**/*.wxs
2-
src/common/lib
32
miniprogram_dist
43
node_modules
5-
common

.github/workflows/pkg-pr-new.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Publish_Any_Commit
2+
on:
3+
push:
4+
branches: [develop]
5+
pull_request:
6+
branches: [develop]
7+
8+
jobs:
9+
build:
10+
if: ${{ github.repository == 'Tencent/tdesign-miniprogram' && !startsWith(github.head_ref, 'release/') }}
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- uses: actions/setup-node@v4
17+
with:
18+
node-version: 18
19+
20+
- run: npm install
21+
22+
- run: npm run build
23+
24+
- run: npx pkg-pr-new publish --compact

.github/workflows/typos-config.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ actived = "actived"
55
Colum = "Colum"
66
ded = "ded"
77
destory ="destory"
8+
nd = "nd"
89

910
[files]
1011
extend-exclude = ["CHANGELOG.md"]

CHANGELOG.md

Lines changed: 2112 additions & 2065 deletions
Large diffs are not rendered by default.

example/components/demo-block/index.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@import '../../../src/common/index.less';
1+
@import '../../../src/common/style/index.less';
22

33
.demo-block {
44
margin: @spacer-4 0 0;

example/utils/gulpError.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
/* eslint-disable */
21
const gulpError = `gulpErrorPlaceHolder`;
2+
33
export default gulpError;

package.json

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "tdesign-miniprogram",
33
"purename": "tdesign",
4-
"version": "1.8.6",
4+
"version": "1.9.0",
55
"description": "tdesign-miniprogram",
66
"title": "tdesign-miniprogram",
77
"main": "miniprogram_dist/index.js",
@@ -66,6 +66,7 @@
6666
"commitizen": "^4.2.4",
6767
"cross-env": "^7.0.2",
6868
"cz-conventional-changelog": "^3.3.0",
69+
"dayjs": "^1.10.7",
6970
"del": "^6.1.1",
7071
"eslint": "^7.0.0",
7172
"eslint-config-airbnb-base": "^14.2.1",
@@ -76,14 +77,19 @@
7677
"gray-matter": "^4.0.3",
7778
"gulp": "^4.0.2",
7879
"gulp-changed": "^4.0.2",
80+
"gulp-clean-css": "^4.3.0",
81+
"gulp-htmlmin": "^5.0.1",
7982
"gulp-if": "^3.0.0",
83+
"gulp-insert": "^0.5.0",
84+
"gulp-jsonminify": "^1.1.0",
8085
"gulp-less": "^5.0.0",
8186
"gulp-mp-npm": "^1.9.7",
8287
"gulp-plumber": "^1.2.1",
8388
"gulp-rename": "^2.0.0",
8489
"gulp-replace": "^1.0.0",
8590
"gulp-replace-task": "^2.0.1",
8691
"gulp-sourcemaps": "^3.0.0",
92+
"gulp-terser": "^2.1.0",
8793
"gulp-typescript": "^6.0.0-alpha.1",
8894
"husky": "^7.0.4",
8995
"jest": "^26.6.3",
@@ -92,6 +98,7 @@
9298
"less": "^4.1.1",
9399
"lint-staged": "^10.0.0-1",
94100
"lodash": "^4.17.21",
101+
"merge2": "^1.4.1",
95102
"miniprogram-api-typings": "^3.4.6",
96103
"miniprogram-automator": "^0.10.0",
97104
"miniprogram-simulate": "^1.6.0",
@@ -104,6 +111,9 @@
104111
"tdesign-icons-view": "^0.3.2",
105112
"tdesign-publish-cli": "^0.0.12",
106113
"tdesign-site-components": "^0.15.2",
114+
"tdesign-theme-generator": "^1.1.0",
115+
"tinycolor2": "^1.4.2",
116+
"tslib": "^2.8.1",
107117
"typescript": "~4.7.2",
108118
"vite": "^2.7.6",
109119
"vite-plugin-tdoc": "^2.0.1",
@@ -122,9 +132,5 @@
122132
"{src,example}/**/*.{js,ts}": [
123133
"eslint --fix"
124134
]
125-
},
126-
"dependencies": {
127-
"dayjs": "^1.10.7",
128-
"tinycolor2": "^1.4.2"
129135
}
130136
}

script/gulpfile.base.js

Lines changed: 79 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
1+
const path = require('path');
12
const gulp = require('gulp');
23
const del = require('del');
34
const replace = require('gulp-replace');
45
const plumber = require('gulp-plumber');
56
const changed = require('gulp-changed');
67
const gulpTs = require('gulp-typescript');
8+
const merge2 = require('merge2');
79
const sourcemaps = require('gulp-sourcemaps');
810
const gulpLess = require('gulp-less');
11+
const cssmin = require('gulp-clean-css');
12+
const gulpInsert = require('gulp-insert');
13+
const jsmin = require('gulp-terser');
14+
const jsonmin = require('gulp-jsonminify');
15+
const wxmlmin = require('gulp-htmlmin');
916
const rename = require('gulp-rename');
1017
const replaceTask = require('gulp-replace-task');
1118
const mpNpm = require('gulp-mp-npm');
1219
const gulpIf = require('gulp-if');
1320

1421
const config = require('./config');
1522

23+
const baseCssPath = path.resolve(__dirname, '../src/common/style/index.wxss');
24+
1625
const isProduction = process.env.NODE_ENV === 'production';
1726

1827
// set displayName
@@ -35,20 +44,32 @@ const generateConfigReplaceTask = (replaceConfig, options = {}) => {
3544
});
3645
};
3746

47+
const isComponentFolder = (dir) => {
48+
return dir === 'src';
49+
};
50+
51+
const ignoreFilesForDTS = (file) => {
52+
return ['props.d.ts', 'type.d.ts'].includes(file.basename);
53+
};
54+
3855
/* return gulpfile base tasks */
3956
module.exports = (src, dist, moduleName) => {
4057
const tsProject = gulpTs.createProject('tsconfig.json', {
4158
declaration: true,
4259
removeComments: isProduction,
60+
importHelpers: true,
61+
noEmitHelpers: true,
4362
});
4463

4564
// options
4665
const ignore = ['**/__test__', '**/__test__/**', '**/_example/**', '**/_common/**'];
4766
const srcOptions = { base: src, ignore };
4867
const watchOptions = { events: ['add', 'change'] };
4968
const gulpErrorPath = 'example/utils/gulpError.js';
69+
5070
// 文件匹配路径
5171
const globs = {
72+
wxml: `${src}/**/*.wxml`, // 匹配 wxml 文件
5273
ts: `${src}/**/*.ts`, // 匹配 ts 文件
5374
js: `${src}/**/*.js`, // 匹配 js 文件
5475
wxs: `${src}/**/*.wxs`, // 匹配 wxs 文件
@@ -57,15 +78,18 @@ module.exports = (src, dist, moduleName) => {
5778
wxss: `${src}/**/*.wxss`, // 匹配 wxss 文件
5879
md: `${src}/**/*.md`, // 匹配 md 文件
5980
};
81+
6082
// 匹配需要拷贝的文件
6183
globs.copy = [
6284
`${src}/**`,
85+
`!${globs.wxml}`,
6386
`!${globs.ts}`,
6487
`!${globs.js}`,
6588
`!${globs.wxs}`,
6689
`!${globs.json}`,
6790
`!${globs.less}`,
6891
`!${globs.wxss}`,
92+
`!${globs.md}`,
6993
'!**/_example/**',
7094
];
7195

@@ -104,11 +128,30 @@ module.exports = (src, dist, moduleName) => {
104128
.pipe(changed(dist)) // 过滤掉未改变的文件
105129
.pipe(gulp.dest(dist));
106130

131+
/** `gulp wxml`
132+
* 处理 wxml
133+
* */
134+
tasks.wxml = () =>
135+
gulp
136+
.src(globs.wxml, { ...srcOptions, since: since(tasks.wxml) })
137+
.pipe(
138+
gulpIf(
139+
isComponentFolder(src) && isProduction,
140+
wxmlmin({
141+
removeComments: true,
142+
collapseWhitespace: true,
143+
keepClosingSlash: true,
144+
caseSensitive: true,
145+
}),
146+
),
147+
)
148+
.pipe(gulp.dest(dist));
149+
107150
/** `gulp ts`
108151
* 处理ts
109152
* */
110-
tasks.ts = () =>
111-
gulp
153+
tasks.ts = () => {
154+
const tsResult = gulp
112155
.src(globs.ts, srcOptions)
113156
.pipe(
114157
plumber({
@@ -119,10 +162,17 @@ module.exports = (src, dist, moduleName) => {
119162
)
120163
.pipe(generateConfigReplaceTask(config, { stringify: true }))
121164
.pipe(gulpIf(!isProduction, sourcemaps.init()))
122-
.pipe(tsProject()) // 编译ts
123-
.pipe(mpNpm())
124-
.pipe(gulpIf(!isProduction, sourcemaps.write('.')))
125-
.pipe(gulp.dest(dist));
165+
.pipe(tsProject()); // 编译ts
166+
167+
return merge2(
168+
tsResult.js
169+
.pipe(mpNpm())
170+
.pipe(gulpIf(isComponentFolder(src) && isProduction, jsmin()))
171+
.pipe(sourcemaps.write('.'))
172+
.pipe(gulp.dest(dist)),
173+
tsResult.dts.pipe(gulpIf((file) => !isProduction || !ignoreFilesForDTS(file), gulp.dest(dist))),
174+
);
175+
};
126176

127177
/** `gulp js`
128178
* 处理js
@@ -131,6 +181,7 @@ module.exports = (src, dist, moduleName) => {
131181
gulp
132182
.src(globs.js, { ...srcOptions, since: since(tasks.js) })
133183
.pipe(generateConfigReplaceTask(config, { stringify: true }))
184+
.pipe(gulpIf(isComponentFolder(src) && isProduction, jsmin()))
134185
.pipe(gulp.dest(dist));
135186

136187
/** `gulp wxs`
@@ -145,7 +196,11 @@ module.exports = (src, dist, moduleName) => {
145196
/** `gulp json`
146197
* 处理json
147198
* */
148-
tasks.json = () => gulp.src(globs.json, { ...srcOptions, dot: true, since: since(tasks.json) }).pipe(gulp.dest(dist));
199+
tasks.json = () =>
200+
gulp
201+
.src(globs.json, { ...srcOptions, dot: true, since: since(tasks.json) })
202+
.pipe(gulpIf(isComponentFolder(src) && isProduction, jsonmin()))
203+
.pipe(gulp.dest(dist));
149204

150205
/** `gulp less`
151206
* 处理less
@@ -164,6 +219,21 @@ module.exports = (src, dist, moduleName) => {
164219
.pipe(generateConfigReplaceTask(config, { stringify: false }))
165220
.pipe(gulpIf(!isProduction, sourcemaps.init()))
166221
.pipe(gulpLess()) // 编译less
222+
.pipe(gulpIf(isComponentFolder(src) && isProduction, cssmin()))
223+
.pipe(
224+
gulpIf(
225+
isComponentFolder(src),
226+
gulpInsert.transform((contents, file) => {
227+
if (!file.path.includes(`src${path.sep}common`)) {
228+
const relativePath = path
229+
.relative(path.normalize(`${file.path}${path.sep}..`), baseCssPath)
230+
.replace(/\\/g, '/');
231+
contents = `@import '${relativePath}';${contents}`;
232+
}
233+
return contents;
234+
}),
235+
),
236+
)
167237
.pipe(rename({ extname: '.wxss' }))
168238
.pipe(gulpIf(!isProduction, sourcemaps.write('.')))
169239
.pipe(gulp.dest(dist));
@@ -187,14 +257,15 @@ module.exports = (src, dist, moduleName) => {
187257
tasks.build = gulp.series(
188258
tasks.clear,
189259
tasks.resetError,
190-
gulp.parallel(tasks.copy, tasks.ts, tasks.js, tasks.wxs, tasks.json, tasks.less, tasks.wxss),
260+
gulp.parallel(tasks.copy, tasks.wxml, tasks.ts, tasks.js, tasks.wxs, tasks.json, tasks.less, tasks.wxss),
191261
);
192262

193263
/** `gulp watch`
194264
* 监听
195265
* */
196266
tasks.watch = () => {
197267
gulp.watch(globs.copy, watchOptions, tasks.copy);
268+
gulp.watch(globs.wxml, watchOptions, tasks.wxml);
198269
gulp.watch(globs.ts, watchOptions, gulp.series(tasks.resetError, tasks.ts));
199270
gulp.watch(globs.js, watchOptions, tasks.js);
200271
gulp.watch(globs.wxs, watchOptions, tasks.wxs);

site/app.vue

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@
1010
</template>
1111

1212
<script>
13-
import siteConfig from './site.config';
14-
import { changeThemeMode } from './theme/dark';
15-
1613
import { defineComponent } from 'vue';
14+
import siteConfig from './site.config';
1715
1816
const { docs, enDocs } = JSON.parse(JSON.stringify(siteConfig).replace(/component:.+/g, ''));
1917
@@ -43,25 +41,6 @@ const docsMap = {
4341
en: sortDocs(enDocs),
4442
};
4543
46-
function watchHtmlMode(callback = () => {}) {
47-
const targetNode = document.documentElement;
48-
const config = { attributes: true };
49-
50-
const observerCallback = (mutationsList) => {
51-
for (const mutation of mutationsList) {
52-
if (mutation.attributeName === 'theme-mode') {
53-
const themeMode = mutation.target.getAttribute('theme-mode') || 'light';
54-
if (themeMode) callback(themeMode);
55-
}
56-
}
57-
};
58-
59-
const observer = new MutationObserver(observerCallback);
60-
observer.observe(targetNode, config);
61-
62-
return observer;
63-
}
64-
6544
export default defineComponent({
6645
data() {
6746
return {
@@ -88,7 +67,7 @@ export default defineComponent({
8867
window.scrollTo(0, 0);
8968
};
9069
this.$refs.tdDocSearch.docsearchInfo = { indexName: 'tdesign_doc_miniprogram' };
91-
watchHtmlMode(changeThemeMode);
70+
this.initThemeGenerator();
9271
},
9372
9473
watch: {
@@ -106,6 +85,11 @@ export default defineComponent({
10685
callback();
10786
});
10887
},
88+
initThemeGenerator() {
89+
const generator = document.createElement('td-theme-generator');
90+
generator.setAttribute('device', 'mini-program');
91+
document.body.appendChild(generator);
92+
},
10993
},
11094
});
11195
</script>

site/main.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { createApp } from 'vue';
22
// eslint-disable-next-line import/no-duplicates
33
import { registerLocaleChange } from 'tdesign-site-components';
4+
import 'tdesign-theme-generator';
5+
46
import app from './app.vue';
57
import router from './router';
68

0 commit comments

Comments
 (0)