@@ -5,7 +5,6 @@ const getBabelCommonConfig = require('./getBabelCommonConfig');
5
5
const merge2 = require ( 'merge2' ) ;
6
6
const { execSync } = require ( 'child_process' ) ;
7
7
const through2 = require ( 'through2' ) ;
8
- const transformLess = require ( './transformLess' ) ;
9
8
const webpack = require ( 'webpack' ) ;
10
9
const babel = require ( 'gulp-babel' ) ;
11
10
const argv = require ( 'minimist' ) ( process . argv . slice ( 2 ) ) ;
@@ -27,15 +26,22 @@ const compareVersions = require('compare-versions');
27
26
const getTSCommonConfig = require ( './getTSCommonConfig' ) ;
28
27
const replaceLib = require ( './replaceLib' ) ;
29
28
const sortApiTable = require ( './sortApiTable' ) ;
29
+ const { glob } = require ( 'glob' ) ;
30
30
31
31
const packageJson = require ( getProjectPath ( 'package.json' ) ) ;
32
32
const tsDefaultReporter = ts . reporter . defaultReporter ( ) ;
33
33
const cwd = process . cwd ( ) ;
34
34
const libDir = getProjectPath ( 'lib' ) ;
35
35
const esDir = getProjectPath ( 'es' ) ;
36
+ const localeDir = getProjectPath ( 'locale' ) ;
36
37
37
38
const tsConfig = getTSCommonConfig ( ) ;
38
39
40
+ // FIXME: hard code, not find typescript can modify the path resolution
41
+ const localeDts = `import type { Locale } from '../lib/locale-provider';
42
+ declare const localeValues: Locale;
43
+ export default localeValues;` ;
44
+
39
45
function dist ( done ) {
40
46
rimraf . sync ( path . join ( cwd , 'dist' ) ) ;
41
47
process . env . RUN_ENV = 'PRODUCTION' ;
@@ -108,6 +114,11 @@ gulp.task('tsc', () =>
108
114
) ,
109
115
) ;
110
116
117
+ gulp . task ( 'clean' , ( ) => {
118
+ rimraf . sync ( getProjectPath ( '_site' ) ) ;
119
+ rimraf . sync ( getProjectPath ( '_data' ) ) ;
120
+ } ) ;
121
+
111
122
function babelify ( js , modules ) {
112
123
const babelConfig = getBabelCommonConfig ( modules ) ;
113
124
babelConfig . babelrc = false ;
@@ -118,17 +129,7 @@ function babelify(js, modules) {
118
129
const stream = js . pipe ( babel ( babelConfig ) ) . pipe (
119
130
through2 . obj ( function z ( file , encoding , next ) {
120
131
this . push ( file . clone ( ) ) ;
121
- if ( file . path . match ( / \/ s t y l e \/ i n d e x \. ( j s | j s x | t s | t s x ) $ / ) ) {
122
- const content = file . contents . toString ( encoding ) ;
123
- file . contents = Buffer . from (
124
- content
125
- . replace ( / \/ s t y l e \/ ? ' / g, "/style/css'" )
126
- . replace ( / \/ s t y l e \/ ? " / g, '/style/css"' )
127
- . replace ( / \. l e s s / g, '.css' ) ,
128
- ) ;
129
- file . path = file . path . replace ( / i n d e x \. ( j s | j s x | t s | t s x ) $ / , 'css.js' ) ;
130
- this . push ( file ) ;
131
- } else if ( modules !== false ) {
132
+ if ( modules !== false ) {
132
133
const content = file . contents . toString ( encoding ) ;
133
134
file . contents = Buffer . from (
134
135
content
@@ -144,47 +145,9 @@ function babelify(js, modules) {
144
145
}
145
146
146
147
function compile ( modules ) {
147
- const { compile : { transformTSFile, transformFile, includeLessFile = [ ] } = { } } = getConfig ( ) ;
148
+ const { compile : { transformTSFile, transformFile } = { } } = getConfig ( ) ;
148
149
rimraf . sync ( modules !== false ? libDir : esDir ) ;
149
150
150
- // =============================== LESS ===============================
151
- const less = gulp
152
- . src ( [ 'components/**/*.less' ] )
153
- . pipe (
154
- through2 . obj ( function ( file , encoding , next ) {
155
- // Replace content
156
- const cloneFile = file . clone ( ) ;
157
- const content = file . contents . toString ( ) . replace ( / ^ \uFEFF / , '' ) ;
158
-
159
- cloneFile . contents = Buffer . from ( content ) ;
160
-
161
- // Clone for css here since `this.push` will modify file.path
162
- const cloneCssFile = cloneFile . clone ( ) ;
163
-
164
- this . push ( cloneFile ) ;
165
-
166
- // Transform less file
167
- if (
168
- file . path . match ( / ( \/ | \\ ) s t y l e ( \/ | \\ ) i n d e x \. l e s s $ / ) ||
169
- file . path . match ( / ( \/ | \\ ) s t y l e ( \/ | \\ ) v 2 - c o m p a t i b l e - r e s e t \. l e s s $ / ) ||
170
- includeLessFile . some ( regex => file . path . match ( regex ) )
171
- ) {
172
- transformLess ( cloneCssFile . contents . toString ( ) , cloneCssFile . path )
173
- . then ( css => {
174
- cloneCssFile . contents = Buffer . from ( css ) ;
175
- cloneCssFile . path = cloneCssFile . path . replace ( / \. l e s s $ / , '.css' ) ;
176
- this . push ( cloneCssFile ) ;
177
- next ( ) ;
178
- } )
179
- . catch ( e => {
180
- console . error ( e ) ;
181
- } ) ;
182
- } else {
183
- next ( ) ;
184
- }
185
- } ) ,
186
- )
187
- . pipe ( gulp . dest ( modules === false ? esDir : libDir ) ) ;
188
151
const assets = gulp
189
152
. src ( [ 'components/**/*.@(png|svg)' ] )
190
153
. pipe ( gulp . dest ( modules === false ? esDir : libDir ) ) ;
@@ -259,7 +222,26 @@ function compile(modules) {
259
222
tsResult . on ( 'end' , check ) ;
260
223
const tsFilesStream = babelify ( tsResult . js , modules ) ;
261
224
const tsd = tsResult . dts . pipe ( gulp . dest ( modules === false ? esDir : libDir ) ) ;
262
- return merge2 ( [ less , tsFilesStream , tsd , assets , transformFileStream ] . filter ( s => s ) ) ;
225
+ return merge2 ( [ tsFilesStream , tsd , assets , transformFileStream ] . filter ( s => s ) ) ;
226
+ }
227
+
228
+ function generateLocale ( ) {
229
+ if ( ! fs . existsSync ( localeDir ) ) {
230
+ fs . mkdirSync ( localeDir ) ;
231
+ }
232
+
233
+ const localeFiles = glob . sync ( 'components/locale/*.ts?(x)' ) ;
234
+ localeFiles . forEach ( item => {
235
+ const match = item . match ( / c o m p o n e n t s \/ l o c a l e \/ ( .* ) \. t s x ? / ) ;
236
+ if ( match ) {
237
+ const locale = match [ 1 ] ;
238
+ fs . writeFileSync (
239
+ path . join ( localeDir , `${ locale } .js` ) ,
240
+ `module.exports = require('../lib/locale/${ locale } ');` ,
241
+ ) ;
242
+ fs . writeFileSync ( path . join ( localeDir , `${ locale } .d.ts` ) , localeDts ) ;
243
+ }
244
+ } ) ;
263
245
}
264
246
265
247
function tag ( ) {
@@ -395,7 +377,10 @@ gulp.task('compile-with-es', done => {
395
377
396
378
gulp . task ( 'compile-with-lib' , done => {
397
379
console . log ( '[Parallel] Compile to js...' ) ;
398
- compile ( ) . on ( 'finish' , done ) ;
380
+ compile ( ) . on ( 'finish' , ( ) => {
381
+ generateLocale ( ) ;
382
+ done ( ) ;
383
+ } ) ;
399
384
} ) ;
400
385
401
386
gulp . task ( 'compile-finalize' , done => {
0 commit comments