Skip to content

Commit

Permalink
feat: 新增配置 customVariablesfileheader,支持自定义变量和自定义文件头内容
Browse files Browse the repository at this point in the history
Co-authored-by: ygqygq2 <[email protected]>
  • Loading branch information
ygqygq2 committed Mar 21, 2024
1 parent ed622d5 commit 0e8e93f
Show file tree
Hide file tree
Showing 11 changed files with 155 additions and 51 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

All notable changes to the "turbo-file-header" extension will be documented in this file.

# [0.1.0]

## 新增功能 🌱

- feat: 新增配置 `customVariables``fileheader`,支持自定义变量和自定义文件头内容
- feat: 配置中使用 `usePrevious: true` 支持文件头保留字段
- feat: 配置中使用 `wholeLine: true` 支持文件头变量值占据整行

# [0.0.8]

## 新增功能 🌱
Expand Down
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Properties:
| Include glob | "include glob" for `autoInsertOnCreateFile` and batch update command | include | `**/this-default-glob/*` |
| Exclude glob | "exclude glob" for `autoInsertOnCreateFile` and batch update command | exclude | `` |
| Disable fields in file header | The fields that you want to disable in file header | disableLabels | `[]` |
| Custom variable | Support use other variable | customVariables | `[]` |
| Custom variable | Support use other variable | customVariables | `[]` |
| File header content | File header content, overwrite the default file header content | fileheader | the below |
| Only dirty file or not to support | Only dirty file to support update file header | updateHeaderForModifiedFilesOnly | `false` |
| Extra languages support | To support new or unknown languages | languages | the below |
Expand Down Expand Up @@ -77,11 +77,16 @@ Properties:
{
"name": "description",
"value": ""
},
{
"name": "copyright",
"value": "Copyright ©{{companyName}} All rights reserved"
}
]
```

>Tips:
> Tips:
- To match the `fileheader` settings `usePrevious` fields

`fileheader` default settings:
Expand Down Expand Up @@ -111,14 +116,13 @@ Properties:
},
{
"label": "@copyright",
"value": "Copyright ©{{companyName}} All rights reserved",
"value": "{{copyright}}",
"wholeLine": true
}
]
```

>Tips:
- if use `"usePrevious": true`, don't use `"wholeLine": true`, because label could not be matched.
> Tips:
- if use `"usePrevious": true`, please set the custom variable, then use the entire variable to represent the entire value.

`languages` default settings:
Expand Down
7 changes: 6 additions & 1 deletion README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,14 @@ Properties:
- `{{description}}` {string} 文件描述,由用户输入
- `{{now}}` {string} 生成文件头时的时间

**自定义变量可以这样使用:**

- `{{now 'YYYY-MM-DD HH:mm:ss'}}` {string} 生成文件头的当前时间,可以自定义格式
- `{{now-1 'MM'}}` {string} 自定义格式的当前时间,并且支持简单计算,注意格式化后值是支持计算的才行

## 默认配置列表

`customVariables` 设置设置:
`customVariables` 默认设置:

```
[
Expand Down
7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "turbo-file-header",
"displayName": "Turbo File Header",
"description": "Sets file header information globally or for a project.",
"version": "0.0.8",
"version": "0.1.0",
"icon": "resources/icons/icon.png",
"repository": {
"type": "git",
Expand Down Expand Up @@ -158,10 +158,6 @@
{
"name": "copyright",
"value": " * Copyright ©{{companyName}} All rights reserved"
},
{
"name": "test1",
"value": "{{now-1 'YYYY'}}"
}
]
},
Expand Down Expand Up @@ -578,6 +574,7 @@
"handlebars": "^4.7.8",
"json5": "^2.2.3",
"lodash": "^4.17.21",
"mathjs": "^12.4.1",
"minimatch": "^9.0.3",
"upath": "^2.0.1",
"yaml": "^2.4.1"
Expand Down
2 changes: 1 addition & 1 deletion package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"turboFileHeader.disableLabels.items.enum.lastModified": "The file last modified time",
"turboFileHeader.disableLabels.items.enum.copyright": "Copyright information",
"turboFileHeader.disableLabels.markdownDescription": "Disable some fields in default fileheader. This properties can not affect the custom fileheader config file.",
"turboFileHeader.customVariables.description": "Custom fields can be used in fileheader.",
"turboFileHeader.customVariables.description": "Custom variables that can be referenced in the header support {{name}} form to be referenced, and {{now}} to refer to built-in variables.",
"turboFileHeader.customVariables.items.properties.name.description": "The key of custom field. Can be used in `turboFileHeader.fileheader` with {{name}}.",
"turboFileHeader.fileheader.description": "File header, if set, will be overwrite efault file header",
"turboFileHeader.fileheader.items.properties.label.description": "The left label of file header",
Expand Down
2 changes: 1 addition & 1 deletion package.nls.zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"turboFileHeader.disableLabels.items.enum.lastModified": "文件最后修改时间",
"turboFileHeader.disableLabels.items.enum.copyright": "版权信息",
"turboFileHeader.disableLabels.markdownDescription": "禁用默认文件头中的某些字段. 该属性不会影响自定义文件头",
"turboFileHeader.customVariables.description": "",
"turboFileHeader.customVariables.description": "可以文件头中被引用的自定义变量,支持 {{name}} 形式被引用,和 {{内置变量}} 引用内置变量",
"turboFileHeader.customVariables.items.properties.name.description": "自定义字段 key,可以在 `turboFileHeader.fileheader` 中以 {{name}} 形式引用",
"turboFileHeader.fileheader.description": "文件头内容,如果设置,将会覆盖默认文件头内容",
"turboFileHeader.fileheader.items.properties.label.description": "左边标签的名称",
Expand Down
63 changes: 63 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions src/fileheader/FileheaderManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ export class FileheaderManager {
const originContentLineCount = originContent.split('\n').length;
const dateformat = config.get(ConfigSection.dateFormat, 'YYYY-MM-DD HH:mm:ss');
const dateRegex = new RegExp(convertDateFormatToRegex(dateformat), 'g');
const descriptionRegex = new RegExp('description.*');

let headerSame: boolean = false;
if (originContentLineCount > 1) {
Expand All @@ -140,7 +139,6 @@ export class FileheaderManager {
}
const originContentProcessed = removeSpecialString(originContentLines.join('\n'), [
dateRegex,
descriptionRegex,
]);

let newFileheaderLines = newFileheader.split('\n').map((line) => line.trim());
Expand All @@ -153,7 +151,6 @@ export class FileheaderManager {
}
const newFileheaderProcessed = removeSpecialString(newFileheaderLines.join('\n'), [
dateRegex,
descriptionRegex,
]);

headerSame = originContentProcessed === newFileheaderProcessed;
Expand Down
Loading

0 comments on commit 0e8e93f

Please sign in to comment.