From 98cf22b47e9e9729f10a0d124c756299479e2938 Mon Sep 17 00:00:00 2001 From: tackchen Date: Wed, 16 Dec 2020 13:37:28 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9=20webpack=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- helper/all/index.d.ts | 20 ++++----- helper/build-npm.js | 80 +++++++++++++++------------------- webpack-config/build.js | 4 +- webpack-config/build.plugin.js | 2 +- 4 files changed, 47 insertions(+), 59 deletions(-) diff --git a/helper/all/index.d.ts b/helper/all/index.d.ts index 6adb48c..90c5b1e 100644 --- a/helper/all/index.d.ts +++ b/helper/all/index.d.ts @@ -36,15 +36,15 @@ declare interface DrawOption { clear?: boolean; // 绘制前是否清空容器 默认为true style?: { // 样式类 backgroundColor?: string, // 默认为#fff - showOutline?: boolean;//: true, - showCharacter?: boolean;//: true, - currentColor?: string;//: '#b44', // 仅在stroke模式下有效 - length?: number;//: 60, - padding?: number;//: 5, // 数值, 默认 20。 画布的汉字和边缘之间的填充 - outlineColor?: string;//: '#ddd', // 十六进制字符, 默认 '#DDD'。 - strokeColor?: string;//: '#555', // 十六进制字符, 默认 '#555'。绘制每个笔划的颜色。 - radicalColor?: string;//: null, // 十六进制字符, 默认 null。 如果存在偏旁部首数据,则在笔划中绘制偏旁部首的颜色。 如果没有设置,激光将绘制与其他笔划相同的颜色。 - strokeFadeDuration?: number; //400 + showOutline?: boolean;// : true, + showCharacter?: boolean;// : true, + currentColor?: string;// : '#b44', // 仅在stroke模式下有效 + length?: number;// : 60, + padding?: number;// : 5, // 数值, 默认 20。 画布的汉字和边缘之间的填充 + outlineColor?: string;// : '#ddd', // 十六进制字符, 默认 '#DDD'。 + strokeColor?: string;// : '#555', // 十六进制字符, 默认 '#555'。绘制每个笔划的颜色。 + radicalColor?: string;// : null, // 十六进制字符, 默认 null。 如果存在偏旁部首数据,则在笔划中绘制偏旁部首的颜色。 如果没有设置,激光将绘制与其他笔划相同的颜色。 + strokeFadeDuration?: number; // 400 }, line?: { // 背景线条类 lineStraight?: boolean;// : true, @@ -159,7 +159,7 @@ export declare interface CnCharStatic { transformTone(spell: string, tone?: boolean, type?: 'low' | 'up'): { spell: string; tone: toneType; - index: number; + index: number; isTrans: boolean; }; isCnChar(word: string): boolean; diff --git a/helper/build-npm.js b/helper/build-npm.js index 91a67f2..a874334 100644 --- a/helper/build-npm.js +++ b/helper/build-npm.js @@ -3,15 +3,12 @@ const rename = require('gulp-rename'); const fs = require('fs'); const babel = require('gulp-babel'); const toc = require('gulp-markdown-toc'); -let version = require('../package.json').version; -let files = [ - '../npm/order/package.json', - '../npm/poly/package.json', - '../npm/trad/package.json', - '../npm/draw/package.json', - '../npm/idiom/package.json', - '../npm/xhy/package.json', - '../npm/radical/package.json', +const version = require('../package.json').version; + +const plugins = ['order', 'poly', 'trad', 'draw', 'idiom', 'xhy', 'radical']; + +const files = [ + ...plugins.map(plugin => `../npm/${plugin}/package.json`), '../npm/cnchar/package.json', '../npm/all/package.json', '../npm/hanzi-util/package.json', @@ -20,14 +17,14 @@ let files = [ function modVersion () { files.forEach(file => { - let pkg = require(file); + const pkg = require(file); pkg.version = version; fs.writeFile(file.substr(1), JSON.stringify(pkg, null, 4), 'utf8', (err) => { if (err) throw err; }); }); } -let depFiles = [ +const depFiles = [ '../npm/all/package.json', '../npm/hanzi-util/package.json', '../npm/hanzi-util-base/package.json' @@ -35,9 +32,9 @@ let depFiles = [ function modDep () { depFiles.forEach(file => { - let pkg = require(file); - let dep = pkg.dependencies; - for (let key in dep) { + const pkg = require(file); + const dep = pkg.dependencies; + for (const key in dep) { if (key.substr(0, 6) === 'cnchar') { dep[key] = '^' + version; } @@ -56,50 +53,41 @@ function task () { transEs6ByBabel(); } +function buildPluginGulpFiles (plugin) { + const path = `src/plugin/${plugin}/`; + return [`${path}dict/*.json`, `${path}types`, `${path}*.d.ts`]; +} + +function gulpPlugin (plugin) { + gulp.src(buildPluginGulpFiles(plugin)) + .pipe(gulp.dest(`npm/${plugin}`)); +} + function copyToNPM () { - gulp.src('helper/README.md') + const gulpReadme = gulp.src(['helper/README.md', 'LICENSE']) .pipe(toc()) .pipe(gulp.dest('.')) - .pipe(gulp.dest('npm/cnchar')) - .pipe(gulp.dest('npm/order')) - .pipe(gulp.dest('npm/poly')) - .pipe(gulp.dest('npm/trad')) - .pipe(gulp.dest('npm/draw')) - .pipe(gulp.dest('npm/idiom')) - .pipe(gulp.dest('npm/radical')) - .pipe(gulp.dest('npm/xhy')); - - gulp.src(['src/main/*.json', 'src/main/*.d.ts', 'LICENSE']) .pipe(gulp.dest('npm/cnchar')); - gulp.src(['src/plugin/order/*.json', 'src/plugin/order/*.d.ts', 'LICENSE']) - .pipe(gulp.dest('npm/order')); + plugins.forEach(plugin => { + gulpReadme = gulpReadme.pipe(`npm/${plugin}`); + }); - gulp.src(['src/plugin/poly/*.json', 'src/plugin/poly/*.d.ts', 'LICENSE']) - .pipe(gulp.dest('npm/poly')); + gulp.src(['src/main/dict/*.json', 'src/main/types', 'src/main/*.d.ts']) + .pipe(gulp.dest('npm/cnchar')); + + plugins.forEach(plugin => { + gulpPlugin(plugin); + }); - gulp.src(['src/plugin/trad/*.json', 'src/plugin/trad/*.d.ts', 'LICENSE']) - .pipe(gulp.dest('npm/trad')); - - gulp.src(['src/plugin/draw/*.json', 'src/plugin/draw/*.d.ts', 'LICENSE']) - .pipe(gulp.dest('npm/draw')); - - gulp.src(['src/plugin/idiom/*.json', 'src/plugin/idiom/*.d.ts', 'LICENSE']) - .pipe(gulp.dest('npm/idiom')); - - gulp.src(['src/plugin/radical/*.json', 'src/plugin/radical/*.d.ts', 'LICENSE']) - .pipe(gulp.dest('npm/radical')); - - gulp.src(['src/plugin/xhy/*.json', 'src/plugin/xhy/*.d.ts', 'LICENSE']) - .pipe(gulp.dest('npm/xhy')); - - gulp.src(['src/main/*.d.ts', 'LICENSE']) + gulp.src(['src/main/*.d.ts', 'src/main/types']) .pipe(gulp.dest('npm/hanzi-util-base')); - gulp.src(['helper/all/*.d.ts', 'LICENSE']) + gulp.src(['helper/all/*.d.ts']) .pipe(gulp.dest('npm/all')) .pipe(gulp.dest('npm/hanzi-util')); } + function copyLatest () { // gulp.src(`dist/*.${version}.min.js`) // .pipe(rename(function (path) { diff --git a/webpack-config/build.js b/webpack-config/build.js index 7d7feb2..832766d 100644 --- a/webpack-config/build.js +++ b/webpack-config/build.js @@ -2,7 +2,7 @@ const version = require('../package.json').version; const path = require('path'); const tool = require('../helper/tool'); -tool.write('./src/main/version.js', 'module.exports = \'' + version + '\';'); +tool.write('./src/main/version.ts', 'module.exports = \'' + version + '\';'); // module.exports = { // entry: path.resolve('./', 'src/main/index.js'), @@ -22,7 +22,7 @@ tool.write('./src/main/version.js', 'module.exports = \'' + version + '\';'); module.exports = { mode: 'production', - entry: path.resolve('./', 'src/main/index.js'), + entry: path.resolve('./', 'src/main/index.ts'), output: { path: path.resolve('./', 'npm/cnchar'), filename: 'cnchar.min.js', diff --git a/webpack-config/build.plugin.js b/webpack-config/build.plugin.js index 908038a..ae48dd9 100644 --- a/webpack-config/build.plugin.js +++ b/webpack-config/build.plugin.js @@ -24,7 +24,7 @@ module.exports = (env) => { const plugin = env.pluginname; return { mode: 'production', - entry: path.resolve('./', 'src/plugin/' + plugin + '/index.js'), + entry: path.resolve('./', 'src/plugin/' + plugin + '/index.ts'), output: { path: path.resolve('./', 'npm/' + plugin), filename: 'cnchar.' + plugin + '.min.js',