Skip to content

Commit

Permalink
feat: add uuid template string
Browse files Browse the repository at this point in the history
  • Loading branch information
uetchy committed Oct 9, 2019
1 parent 7e23047 commit 5795ddb
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ Output text in kebab-case.

In the case of `name` is `CreateReactApp`, `{{kebab name}}` becomes `create-react-app`.

#### `uuid`

Generates unique UUID string.

```
{{uuid}}
{{upper (uuid)}}
```

## Config

You can find the app config in `src/cli.ts`.
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
"inquirer": "^7.0.0",
"is-utf8": "^0.2.1",
"license.js": "^3.1.2",
"uuid": "^3.3.3",
"yargs-interactive": "^3.0.0"
},
"devDependencies": {
"@types/cross-spawn": "^6.0.1",
"@types/node": "^12.7.11",
"@types/uuid": "^3.4.5",
"shipjs": "^0.6.0",
"shx": "^0.3.2",
"typescript": "^3.6.3"
Expand Down
7 changes: 7 additions & 0 deletions src/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import fs from 'fs';
import path from 'path';
import globby from 'globby';
import isUtf8 from 'is-utf8';
import uuidv4 from 'uuid/v4';
import Handlebars from 'handlebars';

import {Config} from '.';

function trim(text: string) {
Expand Down Expand Up @@ -46,6 +48,11 @@ function kebab(text: string) {
}
Handlebars.registerHelper('kebab', kebab);

function uuid() {
return uuidv4();
}
Handlebars.registerHelper('uuid', uuid);

function format<T>(text: Buffer | string, view: T) {
const template = Handlebars.compile(text.toString(), {noEscape: true});
return template(view);
Expand Down
9 changes: 8 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@
dependencies:
"@types/node" "*"

"@types/uuid@^3.4.5":
version "3.4.5"
resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-3.4.5.tgz#d4dc10785b497a1474eae0ba7f0cb09c0ddfd6eb"
integrity sha512-MNL15wC3EKyw1VLF+RoVO4hJJdk9t/Hlv3rt1OL65Qvuadm4BYo6g9ZJQqoq7X8NBFSsQXgAujWciovh2lpVjA==
dependencies:
"@types/node" "*"

"@types/yargs-interactive@^2.1.0":
version "2.1.0"
resolved "https://registry.yarnpkg.com/@types/yargs-interactive/-/yargs-interactive-2.1.0.tgz#5b131283652b738ad219d04cd163f3e0ae61cd95"
Expand Down Expand Up @@ -2208,7 +2215,7 @@ uuid@^2.0.1:
resolved "https://registry.yarnpkg.com/uuid/-/uuid-2.0.3.tgz#67e2e863797215530dff318e5bf9dcebfd47b21a"
integrity sha1-Z+LoY3lyFVMN/zGOW/nc6/1Hsho=

uuid@^3.3.2:
uuid@^3.3.2, uuid@^3.3.3:
version "3.3.3"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.3.3.tgz#4568f0216e78760ee1dbf3a4d2cf53e224112866"
integrity sha512-pW0No1RGHgzlpHJO1nsVrHKpOEIxkGg1xB+v0ZmdNH5OAeAwzAVrCnI2/6Mtx+Uys6iaylxa+D3g4j63IKKjSQ==
Expand Down

0 comments on commit 5795ddb

Please sign in to comment.