Skip to content

Commit

Permalink
Merge branch 'release/1.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
lindsayevans committed Jun 28, 2024
2 parents 88ca497 + 810d87b commit 1ab4030
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 9 deletions.
1 change: 1 addition & 0 deletions DEVELOPING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pnpm start https://raw.githubusercontent.com/lindsayevans/scffld/develop/example
pnpm start github:lindsayevans/scffld/examples/simple --name="My Github Component"
pnpm start github:lindsayevans/scffld/examples/simple@main --name="My Github Component"
pnpm start reg:parcel-web-app --overwrite --outputDirectory=./demo-src/reg-app/
pnpm start show github:lindsayevans/scffld/examples/simple
```

Generator
Expand Down
4 changes: 2 additions & 2 deletions docs/generator.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ If a `.gitignore` is present it will respect it.
Grab everything in a directory:

```sh
npx @querc/scffld@alpha generate ./src/ > templates/app.md
npx @querc/scffld generate ./src/ > templates/app.md
```

Only include specific filetypes in a subdirectory:

```sh
npx @querc/scffld@alpha generate \
npx @querc/scffld generate \
./src/components/**/*.{tsx,scss} */ \
> templates/components.md
```
24 changes: 24 additions & 0 deletions docs/show.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Show command

Outputs the contents of a template

## Syntax

```
scffld show <template>
```

## Examples

Print the template to the screen:

```sh
npx @querc/scffld show github:lindsayevans/scffld/examples/simple
```

Copy a template to local:

```sh
npx @querc/scffld show github:lindsayevans/scffld/examples/simple \
> templates/thing.md
```
5 changes: 5 additions & 0 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,8 @@ npx @querc/scffld github:lindsayevans/scffld/examples/simple@v0.11.0 \
| `-h` `--help` | Show available options for the template |
| `-o` `--outputDirectory` | Base directory where files should be written<br>Defaults to the `outputDirectory` defined in the template |
| `--overwrite` | `true`: overwrite existing files<br>`false`: exit instead of overwriting |

## Other commands

- [`show`](./show.md) - Outputs the contents of a template
- [`generate`](./generator.md) - Generate template from existing files
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@querc/scffld",
"version": "1.3.1",
"version": "1.4.0",
"description": "Simple code scaffolding tool using a Markdown file to define templates & properties",
"main": "dist/index.js",
"bin": "./dist/cli.js",
Expand Down
5 changes: 4 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#!/usr/bin/env node

import { SHOW_COMMAND, show } from './cli/show.js';
import { GENERATE_COMMAND, generate } from './cli/generate.js';
import { scaffold } from './cli/scaffold.js';

if (process.argv[2] === GENERATE_COMMAND) {
if (process.argv[2] === SHOW_COMMAND) {
show(process.argv);
} else if (process.argv[2] === GENERATE_COMMAND) {
generate(process.argv);
} else {
scaffold(process.argv);
Expand Down
19 changes: 14 additions & 5 deletions src/cli/loadTemplate.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import fs from 'node:fs';
import path from 'node:path';
import ora from 'ora';
import ora, { Ora } from 'ora';

export const loadTemplate = async (templateName: string): Promise<string> => {
export const loadTemplate = async (
templateName: string,
options: { quiet?: boolean } = {}
): Promise<string> => {
let templateContent: string;
const { quiet } = options;

if (
templateName.startsWith('http:') ||
Expand All @@ -12,8 +16,11 @@ export const loadTemplate = async (templateName: string): Promise<string> => {
templateName.startsWith('reg:')
) {
// Remote template
console.log('');
const fetchSpinner = ora(`Fetching template ${templateName}...`).start();
let fetchSpinner: Ora | undefined = undefined;
if (!quiet) {
console.log('');
fetchSpinner = ora(`Fetching template ${templateName}...`).start();
}
let url = templateName;

if (templateName.startsWith('github:')) {
Expand Down Expand Up @@ -48,7 +55,9 @@ export const loadTemplate = async (templateName: string): Promise<string> => {

const response = await fetch(url);
templateContent = await response.text();
fetchSpinner.succeed();
if (fetchSpinner !== undefined && !quiet) {
fetchSpinner.succeed();
}
} else {
// Local template
templateContent = fs
Expand Down
10 changes: 10 additions & 0 deletions src/cli/show.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { loadTemplate } from './loadTemplate.js';

export const SHOW_COMMAND = 'show';

export const show = async (argv: string[]) => {
const templateName = argv[3];
const template = await loadTemplate(templateName, { quiet: true });

console.log(template);
};

0 comments on commit 1ab4030

Please sign in to comment.