Skip to content

Commit

Permalink
build: add templates
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeJim committed Nov 2, 2022
1 parent c0a50d2 commit 79f1478
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 0 deletions.
1 change: 1 addition & 0 deletions .templates/$$var_template/$$var_filename.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Component({})
6 changes: 6 additions & 0 deletions .templates/$$var_template/$$var_filename.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"component": true,
"usingComponents": {
"t-$$var_textInFile": "tdesign-miniprogram/$$var_textInFile/$$var_textInFile"
}
}
1 change: 1 addition & 0 deletions .templates/$$var_template/$$var_filename.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<t-$$var_textInFile></t-$$var_textInFile>
Empty file.
21 changes: 21 additions & 0 deletions .templates/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# @see https://editorconfig-specification.readthedocs.io/en/latest/

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
charset = utf-8

# 4 space indentation
[*.py]
indent_style = space
indent_size = 4

# Tab indentation (no size specified)
[Makefile]
indent_style = tab
1 change: 1 addition & 0 deletions .templates/_example/$$var_filename.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Component({})
3 changes: 3 additions & 0 deletions .templates/_example/$$var_filename.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"component": true
}
3 changes: 3 additions & 0 deletions .templates/_example/$$var_filename.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<view class="demo-title"></view>
<view class="demo-desc"></view>
<t-demo title="01 类型" desc=""> </t-demo>
Empty file.
37 changes: 37 additions & 0 deletions .vscode/new.code-snippets
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"component-json-template": {
"prefix": "newts",
"body": [
"import { SuperComponent, wxComponent } from '../common/src/index';",
"import config from '../common/config';",
"import props from './props';",
"",
"const { prefix } = config;",
"const name = `\\${prefix}-$1`;",
"",
"@wxComponent()",
"export default class $2 extends SuperComponent {",
" externalClasses = [",
" `\\${prefix}-class`,",
" ];",
"",
" properties = props;",
"",
" observers = {",
" };",
"",
" data = {",
" classPrefix: name,",
" prefix,",
" };",
"",
" methods = {",
" ",
" }",
"}",
"",
],
"scope": "typescript",
"description": "新组件 ts"
},
}
34 changes: 34 additions & 0 deletions template.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* This file is a configuration file generated by the `Template` extension on `vscode`
* @see https://marketplace.visualstudio.com/items?itemName=yongwoo.template
*/
module.exports = {
// You can change the template path to another path
templateRootPath: "./.templates",
// After copying the template file the `replaceFileTextFn` function is executed
replaceFileTextFn: (fileText, templateName, utils) => {
// @see https://www.npmjs.com/package/change-case
const { changeCase } = utils;
// You can change the text in the file
return fileText
.replace(/__templateName__/g, templateName)
.replace(
/__templateNameToPascalCase__/g,
changeCase.pascalCase(templateName)
)
.replace(
/__templateNameToParamCase__/g,
changeCase.paramCase(templateName)
);
},
renameFileFn: (fileName, templateName, utils) => {
const { path } = utils;
const { base } = path.parse(fileName);
return base.replace(/__templateName__/gm, templateName);
},
renameSubDirectoriesFn: (directoryName, templateName, _utils) => {
const { changeCase } = _utils;
const newDirectoryName = changeCase.paramCase(templateName);
return directoryName.replace(/__templateName__/g, newDirectoryName);
}
};

0 comments on commit 79f1478

Please sign in to comment.