feat: 3.0.0typescript改造上线
This commit is contained in:
parent
86949db8fd
commit
8f4d29f6f1
|
@ -1,3 +1,3 @@
|
|||
*.js linguist-language=JavaScript
|
||||
*.js linguist-language=TypeScript
|
||||
# *.css linguist-language=JavaScript
|
||||
*.html linguist-language=JavaScript
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
let dict = require('../src/main/spell-dict-jian.json');
|
||||
const dict = require('../src/main/spell-dict-jian.json');
|
||||
const {isCnChar} = require('../src/main/tool');
|
||||
const tool = require('./tool');
|
||||
|
||||
let polyArr = []; ;
|
||||
let words = [];
|
||||
const polyArr = []; ;
|
||||
const words = [];
|
||||
|
||||
for (let k in dict) {
|
||||
for (const k in dict) {
|
||||
for (let i = 0; i < dict[k].length; i++) {
|
||||
let word = dict[k][i];
|
||||
const word = dict[k][i];
|
||||
if (isCnChar(word)) {
|
||||
if (words.indexOf(word) === -1) {
|
||||
words.push(word);
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
|
||||
const {exec, Packages} = require('./tool');
|
||||
const {plugins, allPackage, mainPackage, npmPackage} = Packages;
|
||||
|
||||
// plugins 'main' 'npm' 可选
|
||||
// npm run build: 默认build 全部
|
||||
// npm run build main poly npm: build三个
|
||||
|
||||
async function main () {
|
||||
const webpack = 'node ./node_modules/webpack/bin/webpack.js --config ';
|
||||
const buildPlugin = 'webpack-config/build.plugin.js --env.pluginname=';
|
||||
const buildMain = `${webpack}webpack-config/build.js`;
|
||||
const buildNpm = `node ./helper/build-npm.js`;
|
||||
let cmds = [];
|
||||
let cmdConsole = [];
|
||||
const packages = process.argv.slice(2);
|
||||
|
||||
packages.forEach(package => {
|
||||
if (plugins.includes(package) || package === allPackage) {
|
||||
cmds.push(`${webpack} ${buildPlugin}${package}`);
|
||||
cmdConsole.push(package);
|
||||
} else if (package === mainPackage) {
|
||||
cmds.push(buildMain);
|
||||
cmdConsole.push(mainPackage);
|
||||
} else if (package === npmPackage) {
|
||||
cmds.push(buildNpm);
|
||||
cmdConsole.push(npmPackage);
|
||||
}
|
||||
});
|
||||
if (cmds.length === 0) {
|
||||
cmds = [
|
||||
buildMain,
|
||||
...plugins.map(plugin => `${webpack} ${buildPlugin}${plugin}`),
|
||||
`${webpack} ${buildPlugin}${allPackage}`,
|
||||
buildNpm
|
||||
];
|
||||
cmdConsole = [
|
||||
mainPackage,
|
||||
...plugins,
|
||||
allPackage,
|
||||
npmPackage
|
||||
];
|
||||
}
|
||||
console.log(`Start Building... [0/${cmds.length}]`);
|
||||
for (let i = 0; i < cmds.length; i++) {
|
||||
await exec(cmds[i]);
|
||||
console.log(`${cmdConsole[i]} build success. [${i + 1}/${cmds.length}]`);
|
||||
}
|
||||
console.log('Finished!');
|
||||
}
|
||||
|
||||
main();
|
|
@ -0,0 +1,59 @@
|
|||
|
||||
const {exec, Packages} = require('./tool');
|
||||
const {plugins, allPackage, mainPackage, types, utils} = Packages;
|
||||
|
||||
// plugins 'main' 'npm' 'types' 可选
|
||||
// npm run publish: 默认build 全部
|
||||
// npm run publish main poly npm: build三个
|
||||
|
||||
async function main () {
|
||||
const publish = 'npm publish ';
|
||||
const publishPackage = `${publish}npm/packages/`;
|
||||
const publishAll = `${publishPackage}cnchar-all`;
|
||||
const publishTypes = `${publish}src/cnchar-types`;
|
||||
const publishMain = `${publishPackage}cnchar`;
|
||||
let cmds = [];
|
||||
let cmdConsole = [];
|
||||
const packages = process.argv.slice(2);
|
||||
|
||||
packages.forEach(package => {
|
||||
if (plugins.includes(package) || utils.includes(package)) {
|
||||
cmds.push(`${publishPackage}${package}`);
|
||||
cmdConsole.push(package);
|
||||
} else if (package === mainPackage) {
|
||||
cmds.push(publishMain);
|
||||
cmdConsole.push(mainPackage);
|
||||
} else if (package === allPackage) {
|
||||
cmds.push(publishAll);
|
||||
cmdConsole.push(allPackage);
|
||||
} else if (package === types) {
|
||||
cmds.push(publishTypes);
|
||||
cmdConsole.push(types);
|
||||
}
|
||||
});
|
||||
|
||||
if (cmds.length === 0) {
|
||||
cmds = [
|
||||
publishTypes,
|
||||
publishMain,
|
||||
...plugins.map(plugin => `${publishPackage}${plugin}`),
|
||||
publishAll,
|
||||
...utils.map(util => `${publishPackage}${util}`)
|
||||
];
|
||||
cmdConsole = [
|
||||
types,
|
||||
mainPackage,
|
||||
...plugins,
|
||||
allPackage,
|
||||
...utils
|
||||
];
|
||||
}
|
||||
console.log(`Start Publish... [0/${cmds.length}]`);
|
||||
for (let i = 0; i < cmds.length; i++) {
|
||||
await exec(cmds[i]);
|
||||
console.log(`${cmdConsole[i]} publish success. [${i + 1}/${cmds.length}]`);
|
||||
}
|
||||
console.log('Finished!');
|
||||
}
|
||||
|
||||
main();
|
|
@ -1,28 +1,71 @@
|
|||
const fs = require('fs');
|
||||
const childProcess = require('child_process');
|
||||
|
||||
const plugins = [
|
||||
'poly',
|
||||
'order',
|
||||
'trad',
|
||||
'draw',
|
||||
'idiom',
|
||||
'xhy',
|
||||
'radical',
|
||||
];
|
||||
|
||||
const allPackage = 'all';
|
||||
const mainPackage = 'main';
|
||||
const npmPackage = 'npm';
|
||||
const types = 'types';
|
||||
const utils = ['hanzi-util', 'hanzi-util-base'];
|
||||
|
||||
function read (file, cb) {
|
||||
fs.readFile(file, 'utf8', (err, code) => {
|
||||
if (err) throw err;
|
||||
cb(code);
|
||||
});
|
||||
}
|
||||
|
||||
function write (file, txt, cb) {
|
||||
fs.writeFile(file, txt, 'utf8', (err) => {
|
||||
if (err) throw err;
|
||||
if (cb)cb();
|
||||
});
|
||||
}
|
||||
|
||||
function pick ({data = {}, target, attrs}) {
|
||||
if (!attrs) {
|
||||
attrs = Object.keys(target);
|
||||
}
|
||||
attrs.forEach(name => {
|
||||
if (typeof target[name] !== 'undefined')
|
||||
data[name] = target[name];
|
||||
});
|
||||
return data;
|
||||
}
|
||||
async function exec (cmd) {
|
||||
return new Promise(resolve => {
|
||||
childProcess.exec(cmd, function (error, stdout, stderr) {
|
||||
if (error) {
|
||||
throw new Error('publish error');
|
||||
}
|
||||
resolve({
|
||||
success: true,
|
||||
stdout,
|
||||
stderr
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
module.exports = {
|
||||
read: function (file, cb) {
|
||||
fs.readFile(file, 'utf8', (err, code) => {
|
||||
if (err) throw err;
|
||||
cb(code);
|
||||
});
|
||||
},
|
||||
|
||||
write: function (file, txt, cb) {
|
||||
fs.writeFile(file, txt, 'utf8', (err) => {
|
||||
if (err) throw err;
|
||||
if (cb)cb();
|
||||
});
|
||||
},
|
||||
|
||||
pick: function ({data = {}, target, attrs}) {
|
||||
if (!attrs) {
|
||||
attrs = Object.keys(target);
|
||||
}
|
||||
attrs.forEach(name => {
|
||||
if (typeof target[name] !== 'undefined')
|
||||
data[name] = target[name];
|
||||
});
|
||||
return data;
|
||||
read,
|
||||
write,
|
||||
pick,
|
||||
exec,
|
||||
Packages: {
|
||||
plugins,
|
||||
mainPackage,
|
||||
npmPackage,
|
||||
allPackage,
|
||||
types,
|
||||
utils,
|
||||
}
|
||||
};
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"name": "cnchar-npm",
|
||||
"version": "2.2.8-beta3",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
"cnchar-types": {
|
||||
"version": "2.2.8-beta3"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "cnchar-npm",
|
||||
"version": "2.2.8",
|
||||
"version": "2.2.8-beta3",
|
||||
"description": "功能全面、多端支持的汉字拼音笔画js库,支持多音字、繁体字、火星文",
|
||||
"main": "cnchar.min.js",
|
||||
"scripts": {},
|
||||
|
@ -27,6 +27,6 @@
|
|||
},
|
||||
"homepage": "https://www.theajack.com/cnchar/",
|
||||
"dependencies": {
|
||||
"cnchar-types": "^2.2.8"
|
||||
"cnchar-types": "2.2.8-beta3"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "cnchar",
|
||||
"version": "2.2.8-beta2",
|
||||
"version": "3.0.0",
|
||||
"description": "功能全面、多端支持的汉字拼音笔画js库,支持多音字、繁体字、火星文",
|
||||
"main": "cnchar.min.js",
|
||||
"scripts": {},
|
||||
|
@ -27,6 +27,6 @@
|
|||
},
|
||||
"homepage": "https://www.theajack.com/cnchar/",
|
||||
"dependencies": {
|
||||
"cnchar-types": "^0.0.2"
|
||||
"cnchar-types": "^3.0.0"
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because one or more lines are too long
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "cnchar-draw",
|
||||
"version": "2.2.8-beta2",
|
||||
"version": "3.0.0",
|
||||
"description": "功能全面、多端支持的汉字拼音笔画js库,支持多音字、繁体字、火星文",
|
||||
"main": "cnchar.draw.min.js",
|
||||
"unpkg": "cnchar.draw.min.js",
|
||||
|
@ -27,6 +27,6 @@
|
|||
},
|
||||
"homepage": "https://www.theajack.com/cnchar/",
|
||||
"dependencies": {
|
||||
"cnchar-types": "^0.0.2"
|
||||
"cnchar-types": "^3.0.0"
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "cnchar",
|
||||
"version": "2.2.8",
|
||||
"version": "3.0.0",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
|
18
package.json
18
package.json
|
@ -19,26 +19,14 @@
|
|||
"汉字工具"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "npm run build:main && npm run build:plugin && npm run build:npm",
|
||||
"build:main": "webpack --config webpack-config/build.js",
|
||||
"build:poly": "webpack --config webpack-config/build.plugin.js --env.pluginname=poly",
|
||||
"build:order": "webpack --config webpack-config/build.plugin.js --env.pluginname=order",
|
||||
"build:trad": "webpack --config webpack-config/build.plugin.js --env.pluginname=trad",
|
||||
"build:draw": "webpack --config webpack-config/build.plugin.js --env.pluginname=draw",
|
||||
"build:idiom": "webpack --config webpack-config/build.plugin.js --env.pluginname=idiom",
|
||||
"build:xhy": "webpack --config webpack-config/build.plugin.js --env.pluginname=xhy",
|
||||
"build:radical": "webpack --config webpack-config/build.plugin.js --env.pluginname=radical",
|
||||
"build:all": "webpack --config webpack-config/build.plugin.js --env.pluginname=all",
|
||||
"build:plugin": "npm run build:poly && npm run build:order && npm run build:trad && npm run build:draw && npm run build:idiom && npm run build:xhy && npm run build:radical && npm run build:all",
|
||||
"build:npm": "node ./helper/build-npm.js",
|
||||
"start": "webpack-dev-server --open --config webpack-config/dev.js",
|
||||
"dev": "webpack-dev-server --open --config webpack-config/dev.js",
|
||||
"publish": "npm publish src/cnchar-types && npm publish npm/packages/cnchar && npm publish npm/packages/order && npm publish npm/packages/poly && npm publish npm/packages/trad && npm publish npm/packages/draw && npm publish npm/packages/idiom && npm publish npm/packages/xhy && npm publish npm/packages/radical && npm publish npm/packages/cnchar-all && npm publish npm/packages/hanzi-util-base && npm publish npm/packages/hanzi-util",
|
||||
"build": "node ./helper/build.js",
|
||||
"publish": "node ./helper/publish.js",
|
||||
"lint": "eslint src --ext js",
|
||||
"test": "node test npm",
|
||||
"dev:docs": "vuepress dev vuepress",
|
||||
"build:docs": "bash helper/build-docs.sh",
|
||||
"build:docs-win": "vuepress build vuepress && node ./helper/build-docs.js"
|
||||
"build:docs": "vuepress build vuepress && node ./helper/build-docs.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.5.5",
|
||||
|
|
|
@ -80,7 +80,6 @@ export interface ICnChar {
|
|||
spell: ISpell;
|
||||
stroke: IStroke;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
declare global {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"name": "cnchar-types",
|
||||
"version": "0.0.2",
|
||||
"version": "2.2.8-beta3",
|
||||
"lockfileVersion": 1
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "cnchar-types",
|
||||
"version": "0.0.2",
|
||||
"version": "3.0.0",
|
||||
"description": "功能全面、多端支持的汉字拼音笔画js库,支持多音字、繁体字、火星文",
|
||||
"main": "index.js",
|
||||
"scripts": {},
|
||||
|
@ -24,4 +24,4 @@
|
|||
"url": "https://github.com/theajack/cnchar/issues"
|
||||
},
|
||||
"homepage": "https://www.theajack.com/cnchar/"
|
||||
}
|
||||
}
|
|
@ -21,6 +21,9 @@ export default class HanziWriter {
|
|||
static create(node: Node, text: string, option: IDrawOption): HanziWriter;
|
||||
static loadCharacterData(str: string): Promise<ICharData>;
|
||||
static getScalingTransform(width?: number, height?: number, padding?: number): {
|
||||
transform: string
|
||||
scale: number;
|
||||
transform: string;
|
||||
x: number;
|
||||
y: number;
|
||||
};
|
||||
}
|
File diff suppressed because one or more lines are too long
|
@ -46,7 +46,6 @@ function renderFanningStrokes ({
|
|||
const group: SVGGElement = document.createElementNS('http://www.w3.org/2000/svg', 'g');
|
||||
|
||||
const transformData = HanziWriter.getScalingTransform(width, width, option.padding);
|
||||
console.log(transformData);
|
||||
group.setAttributeNS(null, 'transform', transformData.transform);
|
||||
svg.appendChild(group);
|
||||
for (let i = 0; i <= current; i++) {
|
||||
|
|
Loading…
Reference in New Issue