更新文档

This commit is contained in:
wxzhang 2022-04-03 15:39:17 +08:00
parent bd80def8ad
commit 834ae4cbfd
17 changed files with 90 additions and 231 deletions

View File

@ -1,59 +0,0 @@
/**
*
* 读取当前项目的<package.json>.version,然后运行git tag [Version]在当前工程中添加版本tag
*
* 添加会判断是否已经存在该版本标签如果存在则不添加
* 本脚本用在发布后自动添加版本标签
*
* addGitTag
*
* {
* scripts:{
* "publish":"node version patch",
* // 在发布后在当前工程中添加版本标签
* "postpublish":"node addGitTag
* "
* }
*
* }
*/
const fs = require("fs-extra");
const path = require("path");
const dayjs = require("dayjs");
const shelljs = require("shelljs");
// 可选的,指定工程目录
const args = process.argv.slice(2);
const projectFolder = args.length > 0 ? (path.isAbsolute(args[0]) ? args[0] : path.join(process.cwd(),args[0])) : process.cwd();
// 读取当前项目的package.json
const pkgFile = path.join(projectFolder, "package.json")
const pkg = fs.readJSONSync(pkgFile);
// 切换到当前目录
shelljs.cd(projectFolder);
// 读取当前版本
const tagInfo = shelljs.exec(`git describe --tags --match=V${pkg.version}`, {silent: true}).stdout.trim();
if(tagInfo.length===0){
console.log(`未发现版本标签V${pkg.version}`);
if(shelljs.exec(`git tag V${pkg.version}`, {silent: false}).code>0){
console.log(`添加版本标签<V${pkg.version}>失败`)
}else{
console.log(`已添加版本标签:V${pkg.version}`)
}
}else {
console.log(`已发现版本标签:${tagInfo}`);
}
// 更新

View File

@ -38,17 +38,6 @@
// const packages = [
// "git log --format=%cd --date=iso -1 -- packages/babel/package.json",
// "git log --format=%cd --date=iso -1 -- packages/cli/package.json",
// "git log --format=%cd --date=iso -1 -- packages/runtime/package.json",
// "git log --format=%cd --date=iso -1 -- packages/formatters/package.json",
// "git log --format=%cd --date=iso -1 -- packages/vue/package.json",
// "git log --format=%cd --date=iso -1 -- packages/vite/package.json",
// "git log --format=%cd --date=iso -1 -- packages/autopublish/package.json",
// "git log --format=%cd --date=iso -1 -- packages/utils/package.json"
// ]
function getPackages(){
let workspaceRoot = process.cwd()
if(!fs.existsSync(path.join(workspaceRoot,"pnpm-workspace.yaml"))){
@ -147,6 +136,7 @@ let VERSION_STEPS = ["major", "minor", "patch","premajor","preminor","prepatch",
program
.command("publish")
.description("发布当前工作区下的包")
.option("-p, --package-name", "包名称")
.option("-f, --force", "强制发布")
.option("--no-auto-commit", "不提交源码")
.option("-q, --query", "询问是否发布,否则会自动发布")
@ -156,22 +146,16 @@ program
console.log(JSON.stringify(options))
const {versionIncrementStep,autoCommit,addVersionTag} = options
if(!VERSION_STEPS.includes(versionIncrementStep)){
versionIncrementStep = "patch"
}
const packageFolder = process.cwd()
const packageName = path.basename(packageFolder)
const pkgFile = path.join(packageFolder,"package.json")
const package = fs.readJSONSync(pkgFile)
const packageBackup = Object.assign({},package) // 备份package.json当操作失败时还原
logger.log("包名:{}",`${packageName}`)
logger.log("将发布包:{}",`${packageName}`)
// 第一步: 提交代码
commitProject(package,{versionIncrementStep,autoCommit})
commitProject(package,options)
// 第二步: 更新版本号和发布时间
package.version = semver.inc(package.version,versionIncrementStep)
@ -179,46 +163,7 @@ program
fs.writeJSONSync(pkgFile,package)
// const lastChanges = getPackageLastChanges(packageName)
// let lastCommit = shelljs.exec(`git log --format=%cd --date=iso -1 -- .`, { silent: true }).stdout.trim()
// let hasError = false // 执行过程是否出错了
// let isCommit = autoCommit // 是否执行了提交操作
// if(lastCommit){
// lastCommit = dayjs(lastCommit)
// logger.log("最后一次提交:{}({})",lastCommit.format("YYYY-MM-DD HH:mm:ss"),lastCommit.fromNow())
// }
// // 如果当前包有变化时需要要进行提交
// if(lastChanges.length>0){
// logger.log("包[{}]存在{}个未提交的文件:",packageName,lastChanges.length)
// lastChanges.forEach(file=>logger.log(` - ${file.trim()}`))
// if(!autoCommit){
// const result = await inquirer.prompt({
// name:"isCommit",
// type:"confirm",
// message:"是否提交以上文件到仓库?"
// })
// isCommit = result.isCommit
// }
// if(isCommit){
// // 由于更新版本号、发布时间等信息需要修改package.json所以在提交一份
// execShellScript(`npm version ${versionIncrementStep}`)
// // 重新读取package.json
// package = fs.readJSONSync(pkgFile)
// // 保存发布时间
// package.lastPublish = dayjs().format()
// // 由于更新版本号、发布时间等信息需要修改package.json所以在提交一份
// execShellScript(`npm version ${versionIncrementStep}`)
// // 提交代码到仓库
// execShellScript(`git commit -a -m "Update ${packageName}"`)
// // 添加版本标签
// if(addVersionTag){
// execShellScript(`git tag Version:${package.version}`)
// }
// }
// }
// 第三步执行发布到Npm

View File

@ -1,43 +0,0 @@
/**
* 用于多包环境下的自动发布
*
*
* {
* scripts:{
* "publish":"autopublish [options]",
* }
* }
*/
const fs = require("fs-extra");
const path = require("path");
const dayjs = require("dayjs");
const shelljs = require("shelljs");
const shelljs = require("shelljs");
const createLogger = require("logsets");
const commander = require("commander");
const dayjs = require("dayjs");
const relativeTime = require("dayjs/plugin/relativeTime");
dayjs.extend(relativeTime);
const logger = createLogger();
const program = commander()
program
.version("1.0.0")
.option("-v, --auto", "自动发布")
.option("-a, --auto", "启用自动发布")
.option("-p, --push []", "发布前执行git push")
.option("-m, --commit [message]", "发布前执行git commit")
.option("-v, --version", "默认版本升级取值major,minor,patch")
.action((options) => {
}))

View File

@ -1,6 +1,6 @@
{
"name": "@voerkai18n/babel",
"version": "1.0.3",
"version": "1.0.4",
"description": "VoerkaI18n babel plugin",
"main": "index.js",
"homepage": "https://gitee.com/zhangfisher/voerka-i18n",

View File

@ -1,4 +1,4 @@
module.exports = {
export default {
"1": "支持的语言\\t: {}",
"2": "默认语言\\t: {}",
"3": "激活语言\\t: {}",
@ -34,16 +34,17 @@ module.exports = {
"33": " - 运行<{}>扫描提取要翻译的文本",
"34": " - 运行<{}>编译语言包",
"35": "创建语言包文件夹: {}",
"36": "正在安装多语言运行时:{}",
"37": "模块类型\\t: {}",
"38": "编译结果输出至:{}",
"39": "读取语言文件{}失败:{}",
"40": " - 语言包文件: {}",
"41": " - idMap文件: {}",
"42": " - 格式化器:{}",
"43": "Now is { value | date | bjTime }",
"44": " - 共合成{}条文本",
"45": " - 运行时: {}",
"46": "自动安装默认语言",
"47": "不嵌入运行时源码"
"36": "模块类型\\t: {}",
"37": "编译结果输出至:{}",
"38": "读取语言文件{}失败:{}",
"39": " - 语言包文件: {}",
"40": " - idMap文件: {}",
"41": " - 格式化器:{}",
"42": "Now is { value | date | bjTime }",
"43": " - 共合成{}条文本",
"44": " - 运行时: {}",
"45": "自动安装默认语言",
"46": "不嵌入运行时源码",
"47": " - 安装运行时: {}",
"48": " - 运行时{}已安装"
}

View File

@ -1,4 +1,4 @@
module.exports = {
export default {
"1": "Supported languages\\t: {}",
"2": "Default language\\t: {}",
"3": "Active language\\t\\t: {}",
@ -34,16 +34,17 @@ module.exports = {
"33": " - Run <{}> scan to extract the messages to be translated",
"34": " - Run <{}> compile language messages",
"35": "Create <languages> folder: {}",
"36": "Installing @voerkai18n/runtime{}",
"37": "Type of module\\t\\t: {}",
"38": "Compile to{}",
"39": "Error while read language file{}: {}",
"40": " - Language file: {}",
"41": " - idMap file: {}",
"42": " - Formatters: {}",
"43": "Now is { value | date | bjTime }",
"44": " - Total{} messages",
"45": " - Runtime: {}",
"46": "Auto install default language",
"47": "Not inline runtime source"
"36": "Type of module\\t\\t: {}",
"37": "Compile to{}",
"38": "Error while read language file{}: {}",
"39": " - Language file: {}",
"40": " - idMap file: {}",
"41": " - Formatters: {}",
"42": "Now is { value | date | bjTime }",
"43": " - Total{} messages",
"44": " - Runtime: {}",
"45": "Auto install default language",
"46": "Not inline runtime source",
"47": " - Install runtime: {}",
"48": " - Runtime{} is installed"
}

View File

@ -46,7 +46,7 @@
*
*/
module.exports = {
export default {
// 在所有语言下生效的格式化器
"*":{
//[格式化名称]:(value)=>{...},

View File

@ -1,4 +1,4 @@
module.exports = {
export default {
"支持的语言\\t: {}": 1,
"默认语言\\t: {}": 2,
"激活语言\\t: {}": 3,
@ -34,16 +34,17 @@ module.exports = {
" - 运行<{}>扫描提取要翻译的文本": 33,
" - 运行<{}>编译语言包": 34,
"创建语言包文件夹: {}": 35,
"正在安装多语言运行时:{}": 36,
"模块类型\\t: {}": 37,
"编译结果输出至:{}": 38,
"读取语言文件{}失败:{}": 39,
" - 语言包文件: {}": 40,
" - idMap文件: {}": 41,
" - 格式化器:{}": 42,
"Now is { value | date | bjTime }": 43,
" - 共合成{}条文本": 44,
" - 运行时: {}": 45,
"自动安装默认语言": 46,
"不嵌入运行时源码": 47
"模块类型\\t: {}": 36,
"编译结果输出至:{}": 37,
"读取语言文件{}失败:{}": 38,
" - 语言包文件: {}": 39,
" - idMap文件: {}": 40,
" - 格式化器:{}": 41,
"Now is { value | date | bjTime }": 42,
" - 共合成{}条文本": 43,
" - 运行时: {}": 44,
"自动安装默认语言": 45,
"不嵌入运行时源码": 46,
" - 安装运行时: {}": 47,
" - 运行时{}已安装": 48
}

View File

@ -1,9 +1,9 @@
const messageIds = require("./idMap")
const { translate,i18nScope } = require("./runtime.js")
import messageIds from "./idMap.js"
import { translate,i18nScope } from "./runtime"
const formatters = require("./formatters.js")
const defaultMessages = require("./cn.js")
import formatters from "./formatters.js"
import defaultMessages from "./cn.js"
const activeMessages = defaultMessages
@ -39,7 +39,8 @@ const scope = new i18nScope({
// 翻译函数
const t = translate.bind(scope)
module.exports.t = t
module.exports.i18nScope = scope
module.exports.i18nManager = VoerkaI18n
export {
t,
i18nScope:scope
}

View File

@ -1,5 +1,3 @@
'use strict';
/**
*
* 简单的事件触发器
@ -921,4 +919,4 @@ var runtime ={
isPlainObject
};
module.exports = runtime;
export { runtime as default };

View File

@ -213,12 +213,6 @@
"init.command.js"
]
},
"正在安装多语言运行时:{}": {
"en": "Installing @voerkai18n/runtime{}",
"$file": [
"init.command.js"
]
},
"模块类型\\t: {}": {
"en": "Type of module\\t\\t: {}",
"$file": [
@ -284,5 +278,17 @@
"$file": [
"index.js"
]
},
" - 安装运行时: {}": {
"en": " - Install runtime: {}",
"$file": [
"compile.command.js"
]
},
" - 运行时{}已安装": {
"en": " - Runtime{} is installed",
"$file": [
"compile.command.js"
]
}
}

View File

@ -1,6 +1,6 @@
{
"name": "@voerkai18n/cli",
"version": "1.0.11",
"version": "1.0.15",
"description": "VoerkaI18n command line interactive tools",
"main": "index.js",
"homepage": "https://gitee.com/zhangfisher/voerka-i18n",

View File

@ -1,6 +1,6 @@
{
"name": "@voerkai18n/runtime",
"version": "1.0.8",
"version": "1.0.9",
"description": "Voerkai18n Runtime",
"main": "./dist/index.cjs",
"module": "dist/index.esm.js",

View File

@ -1,12 +1,11 @@
{
"name": "@voerkai18n/utils",
"version": "1.0.0",
"version": "1.0.2",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"release": "npm version patch && npm run build && npm publish -access public"
"release": "npm version patch && pnpm publish --no-git-checks --access public"
},
"author": "",
"license": "ISC",

View File

@ -1,6 +1,6 @@
{
"name": "@voerkai18n/vite",
"version": "1.0.0",
"version": "1.0.1",
"description": "",
"main": "index.js",
"scripts": {

View File

@ -1,6 +1,6 @@
{
"name": "@voerkai18n/vue",
"version": "1.0.0",
"version": "1.0.1",
"description": "",
"main": "index.js",
"scripts": {
@ -23,4 +23,4 @@
"vite": "^2.8.6",
"vite-plugin-inspect": "^0.4.3"
}
}
}

View File

@ -54,6 +54,7 @@
yarn global add @voerkai18/cli
pnpm add -g @voerkai18/cli
```
- **@voerkai18/runtime**
**可选的**,运行时,`@voerkai18/cli`的依赖。大部分情况下不需要手动安装,一般仅在开发库项目时采用独立的运行时依赖。
@ -71,6 +72,14 @@
- **@voerkai18/babel**
可选的`babel`插件,用来实现自动导入翻译函数和翻译文本映射自动替换。
- **@voerkai18/vue**
可选的`vue`插件用来为Vue应用提供语言动态切换功能。
- **@voerkai18/vite**
可选的`vite`插件,用来为`vite`应用提供自动导入翻译函数和翻译文本映射自动替换。
# 快速入门
@ -261,7 +270,7 @@ import { i18nScope } from "./languages"
// 切换到英文
await i18nScope.change("en")
// VoerkaI18n是一个全局单例可以直接访问
VoerkaI18n.change("en")
await VoerkaI18n.change("en")
```
`i18nScope.change``VoerkaI18n.change`两者是等价的。
@ -625,7 +634,7 @@ VoerkaI18n.on((newLanguage)=>{
- **@voerkai18n/vue**
**Vue插件**在初始化Vue应用时引入提供访问`当前语言``切换语言``自动更新`等功能。
**Vue插件**,在初始化`Vue`应用时引入,提供访问`当前语言``切换语言``自动更新`等功能。
- **@voerkai18n/vite**
@ -633,9 +642,9 @@ VoerkaI18n.on((newLanguage)=>{
`@voerkai18n/vue``@voerkai18n/vite`两件插件相互配合安装配置好这两个插件后就可以在Vue文件使用多语言`t`函数。
`@voerkai18n/vue``@voerkai18n/vite`两件插件相互配合,安装配置好这两个插件后,就可以在`Vue`文件使用多语言`t`函数。
**重点:`t`函数会在使用`@voerkai18n/vite`插件后自动注入因此在Vue文件中可以直接使用。**
**重点:`t`函数会在使用`@voerkai18n/vite`插件后自动注入,因此在`Vue`文件中可以直接使用。**
```Vue
<Script setup>
@ -768,7 +777,7 @@ export default {
`voerkai18n `支持多个库国际化的联动和协作,即**当主程序切换语言时,所有引用依赖库也会跟随主程序进行语言切换**,整个切换过程对所有库开发都是透明的。
![结构图](images\arch.png)
![结构图](./images/arch.png)
当我们在开发一个应用或者库并`import "./languages"`时,在`langauges/index.js`进行了如下处理: