Skip to content

Commit

Permalink
feat: modify template rules
Browse files Browse the repository at this point in the history
  • Loading branch information
lenconda committed Jan 22, 2021
1 parent 7b595bb commit 8f31e97
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Go to <https://github.com/dolliejs?tab=repositories&q=scaffold->, find an approp
### Create a Template

- Create all of the essential files for your scaffold
- Rename file starts with `__` when you want to get the props from CLI's prompt to inject into it. For example, if you want to make `package.json` as a customizable file, you should rename it as `__package.json`
- Rename file starts with `__template.` when you want to get the props from CLI's prompt to inject into it. For example, if you want to make `package.json` as a customizable file, you should rename it as `__template.package.json`
- Create a file named `.dollie.json`, put your questions in the `questions` param
- Contact [[email protected]](mailto:[email protected]), then we will fork your GitHub repository into our organization

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dollie/cli",
"version": "0.2.1",
"version": "0.3.0",
"description": "A generator for generating everything",
"homepage": "https://github.com/dolliejs/dollie-cli#readme",
"author": {
Expand Down
15 changes: 3 additions & 12 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,20 +125,11 @@ class DollieGenerator extends Generator {
this.log.info('Writing template...');
traverse(TEMPLATE_DIR, /^((?!(\.dollie\.json)).)+$/, (pathname: string, entity: string) => {
const relativePath = path.relative(TEMPLATE_DIR, pathname);
const entityHeadUnderscoreCounter = entity.split('').reduce((counter, currentCharacter) => {
if (currentCharacter === '_' && counter.flag) {
counter.count = counter.count + 1;
}
if (currentCharacter !== '_' && counter.flag) {
counter.flag = false;
}
return counter;
}, { count: 0, flag: true } as { count: number, flag: boolean });

if (entity.startsWith('__') && entityHeadUnderscoreCounter.count >= 2) {

if (entity.startsWith('__template.')) {
this.fs.copyTpl(
pathname,
this.destinationPath(`${relativePath.slice(0, 0 - entity.length)}${entity.slice(2)}`),
this.destinationPath(`${relativePath.slice(0, 0 - entity.length)}${entity.slice(11)}`),
this.props,
);
} else {
Expand Down

0 comments on commit 8f31e97

Please sign in to comment.