Skip to content

Commit

Permalink
Centralize string transforms
Browse files Browse the repository at this point in the history
  • Loading branch information
bertdeblock committed Mar 20, 2024
1 parent 6fdf3c1 commit 6a24b10
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 64 deletions.
28 changes: 10 additions & 18 deletions documents/component.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,65 +4,57 @@ root: "."
output: "**/*"
---

# {{inputs.ts ? "!" : (inputs.classBased ? "!" : "")}}{{inputs.name}}.gjs
# {{inputs.ts ? "!" : (inputs.classBased ? "!" : "")}}{{inputs.name.kebab}}.gjs

```gjs
<template>{{"{{"}}yield{{"}}"}}</template>
```

# {{inputs.ts ? "!" : (inputs.classBased ? "" : "!")}}{{inputs.name}}.gjs
# {{inputs.ts ? "!" : (inputs.classBased ? "" : "!")}}{{inputs.name.kebab}}.gjs

```gjs
{{name := pascal(inputs.name)-}}
import Component from "@glimmer/component";
export default class {{name}} extends Component {
export default class {{inputs.name.pascal}} extends Component {
<template>{{"{{"}}yield{{"}}"}}</template>
}
```

# {{inputs.ts ? (inputs.classBased ? "!" : "") : "!"}}{{inputs.name}}.gts
# {{inputs.ts ? (inputs.classBased ? "!" : "") : "!"}}{{inputs.name.kebab}}.gts

```gts
{{name := pascal(inputs.name)-}}
{{signature := (name + "Signature")-}}
import type { TOC } from '@ember/component/template-only';
export interface {{signature}} {
export interface {{inputs.signature}} {
Args: {};
Blocks: {
default: [];
};
Element: null;
}
const {{name}}: TOC<{{signature}}> = <template>{{"{{"}}yield{{"}}"}}</template>;
const {{inputs.name.pascal}}: TOC<{{inputs.signature}}> = <template>{{"{{"}}yield{{"}}"}}</template>;
export default {{name}};
export default {{inputs.name.pascal}};
```

# {{inputs.ts ? (inputs.classBased ? "" : "!") : "!"}}{{inputs.name}}.gts
# {{inputs.ts ? (inputs.classBased ? "" : "!") : "!"}}{{inputs.name.kebab}}.gts

```gts
{{name := pascal(inputs.name)-}}
{{signature := (name + "Signature")-}}
import Component from "@glimmer/component";
export interface {{signature}} {
export interface {{inputs.signature}} {
Args: {};
Blocks: {
default: [];
};
Element: null;
}
export default class {{name}} extends Component<{{signature}}> {
export default class {{inputs.name.pascal}} extends Component<{{inputs.signature}}> {
<template>
{{"{{"}}yield{{"}}"}}
</template>
Expand Down
30 changes: 10 additions & 20 deletions documents/helper.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,81 +4,71 @@ root: "."
output: "**/*"
---

# {{inputs.ts ? "!" : (inputs.classBased ? "!" : "")}}{{inputs.name}}.js
# {{inputs.ts ? "!" : (inputs.classBased ? "!" : "")}}{{inputs.name.kebab}}.js

```js
{{name := camel(inputs.name)-}}

import { helper } from "@ember/component/helper";

export default helper(function {{name}}(positional, named) {
export default helper(function {{inputs.name.camel}}(positional, named) {
return positional;
});

```

# {{inputs.ts ? "!" : (inputs.classBased ? "" : "!")}}{{inputs.name}}.js
# {{inputs.ts ? "!" : (inputs.classBased ? "" : "!")}}{{inputs.name.kebab}}.js

```js
{{name := pascal(inputs.name)-}}

import Helper from "@ember/component/helper";

export default class {{name}} extends Helper {
export default class {{inputs.name.pascal}} extends Helper {
compute(positional, named) {
return positional;
}
}

```

# {{inputs.ts ? (inputs.classBased ? "!" : "") : "!"}}{{inputs.name}}.ts
# {{inputs.ts ? (inputs.classBased ? "!" : "") : "!"}}{{inputs.name.kebab}}.ts

```ts
{{name := camel(inputs.name)-}}
{{signature := (pascal(inputs.name) + "Signature")-}}

import { helper } from "@ember/component/helper";

type Named = {};
type Positional = [];
type Return = Positional;

export interface {{signature}} {
export interface {{inputs.signature}} {
Args: {
Named: Named;
Positional: Positional;
};
Return: Return;
}

export default helper<{{signature}}>(function {{name}}(positional, named) {
export default helper<{{inputs.signature}}>(function {{inputs.name.camel}}(positional, named) {
return positional;
});

```

# {{inputs.ts ? (inputs.classBased ? "" : "!") : "!"}}{{inputs.name}}.ts
# {{inputs.ts ? (inputs.classBased ? "" : "!") : "!"}}{{inputs.name.kebab}}.ts

```ts
{{name := pascal(inputs.name)-}}
{{signature := (pascal(inputs.name) + "Signature")-}}

import Helper from "@ember/component/helper";

type Named = {};
type Positional = [];
type Return = Positional;

export interface {{signature}} {
export interface {{inputs.signature}} {
Args: {
Named: Named;
Positional: Positional;
};
Return: Return;
}

export default class {{name}} extends Helper<{{signature}}> {
export default class {{inputs.name.pascal}} extends Helper<{{inputs.signature}}> {
compute(positional: Positional, named: Named): Return {
return positional;
}
Expand Down
30 changes: 10 additions & 20 deletions documents/modifier.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,71 +4,61 @@ root: "."
output: "**/*"
---

# {{inputs.ts ? "!" : (inputs.classBased ? "!" : "")}}{{inputs.name}}.js
# {{inputs.ts ? "!" : (inputs.classBased ? "!" : "")}}{{inputs.name.kebab}}.js

```js
{{name := camel(inputs.name)-}}

import { modifier } from "ember-modifier";

export default modifier(function {{name}}(element, positional, named) {});
export default modifier(function {{inputs.name.camel}}(element, positional, named) {});

```

# {{inputs.ts ? "!" : (inputs.classBased ? "" : "!")}}{{inputs.name}}.js
# {{inputs.ts ? "!" : (inputs.classBased ? "" : "!")}}{{inputs.name.kebab}}.js

```js
{{name := pascal(inputs.name)-}}

import Modifier from "ember-modifier";

export default class {{name}} extends Modifier {
export default class {{inputs.name.pascal}} extends Modifier {
modify(element, positional, named) {}
}

```

# {{inputs.ts ? (inputs.classBased ? "!" : "") : "!"}}{{inputs.name}}.ts
# {{inputs.ts ? (inputs.classBased ? "!" : "") : "!"}}{{inputs.name.kebab}}.ts

```ts
{{name := camel(inputs.name)-}}
{{signature := (pascal(inputs.name) + "Signature")-}}

import { modifier } from "ember-modifier";

export interface {{signature}} {
export interface {{inputs.signature}} {
Args: {
Named: {};
Positional: [];
};
Element: null;
}

export default modifier<{{signature}}>(function {{name}}(element, positional, named) {});
export default modifier<{{inputs.signature}}>(function {{inputs.name.camel}}(element, positional, named) {});

```

# {{inputs.ts ? (inputs.classBased ? "" : "!") : "!"}}{{inputs.name}}.ts
# {{inputs.ts ? (inputs.classBased ? "" : "!") : "!"}}{{inputs.name.kebab}}.ts

```ts
{{name := pascal(inputs.name)-}}
{{signature := (pascal(inputs.name) + "Signature")-}}

import Modifier from "ember-modifier";

type Named = {};
type Positional = [];
type Element = null;

export interface {{signature}} {
export interface {{inputs.signature}} {
Args: {
Named: Named;
Positional: Positional;
};
Element: Element;
}

export default class {{name}} extends Modifier<{{signature}}> {
export default class {{inputs.name.pascal}} extends Modifier<{{inputs.signature}}> {
modify(element: Element, positional: Positional, named: Named) {}
}

Expand Down
8 changes: 3 additions & 5 deletions documents/service.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@ root: "."
output: "**/*"
---

# {{inputs.name}}.{{inputs.ts ? "ts" : "js"}}
# {{inputs.name.kebab}}.{{inputs.ts ? "ts" : "js"}}

```ts
{{name := pascal(inputs.name)-}}

import Service from "@ember/service";

export default class {{name}} extends Service {}
export default class {{inputs.name.pascal}} extends Service {}
{{if inputs.ts}}
declare module "@ember/service" {
interface Registry {
"{{inputs.name}}": {{name}};
"{{inputs.name.kebab}}": {{inputs.name.pascal}};
}
}
{{end}}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
},
"dependencies": {
"chalk": "^5.3.0",
"change-case": "^5.4.3",
"fs-extra": "^11.2.0",
"scaffdog": "^3.0.0",
"yargs": "^17.7.2"
Expand Down
7 changes: 7 additions & 0 deletions pnpm-lock.yaml

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

12 changes: 11 additions & 1 deletion src/generate-document.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import chalk from "chalk";
import { camelCase, kebabCase, pascalCase } from "change-case";
import { ensureDir } from "fs-extra";
import { writeFile } from "node:fs/promises";
import { dirname, isAbsolute, join, parse, relative } from "node:path";
Expand Down Expand Up @@ -31,7 +32,16 @@ export async function generateDocument(

const documentPath = getDocumentPath(documentName, cwd, path);
const files = await scaffdog.generate(document, documentPath, {
inputs: { ...inputs, name: entityName },
inputs: {
...inputs,
name: {
camel: camelCase(entityName),
kebab: kebabCase(entityName),
pascal: pascalCase(entityName),
raw: entityName,
},
signature: pascalCase(entityName) + "Signature",
},
});

for (const file of files) {
Expand Down

0 comments on commit 6a24b10

Please sign in to comment.