-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(generators): support starting from a template (#4951)
- Loading branch information
Showing
12 changed files
with
215 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module.exports = function generator(plop) { | ||
plop.setGenerator("example", { | ||
description: | ||
"An example Turborepo generator - creates a new file at the root of the project", | ||
prompts: [ | ||
{ | ||
type: "input", | ||
name: "file", | ||
message: "What is the name of the file to create?", | ||
}, | ||
{ | ||
type: "input", | ||
name: "author", | ||
message: "What is your name? (Will be added as the file author)", | ||
}, | ||
{ | ||
type: "list", | ||
name: "type", | ||
message: "What type of file should be created?", | ||
choices: [".md", ".txt"], | ||
}, | ||
], | ||
actions: [ | ||
{ | ||
type: "add", | ||
path: "{{ turbo.paths.root }}/{{ dashCase file }}{{ type }}", | ||
templateFile: "templates/turborepo-generators.hbs", | ||
}, | ||
], | ||
}); | ||
}; |
5 changes: 5 additions & 0 deletions
5
packages/turbo-gen/src/templates/simple-js/templates/turborepo-generators.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Turborepo Generators | ||
|
||
Read the docs at [turbo.build](https://turbo.build/repo/docs). | ||
|
||
Created by {{ author }}. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { PlopTypes } from "@turbo/gen"; | ||
|
||
export default function generator(plop: PlopTypes.NodePlopAPI): void { | ||
plop.setGenerator("example", { | ||
description: | ||
"An example Turborepo generator - creates a new file at the root of the project", | ||
prompts: [ | ||
{ | ||
type: "input", | ||
name: "file", | ||
message: "What is the name of the file to create?", | ||
}, | ||
{ | ||
type: "input", | ||
name: "author", | ||
message: "What is your name? (Will be added as the file author)", | ||
}, | ||
{ | ||
type: "list", | ||
name: "type", | ||
message: "What type of file should be created?", | ||
choices: [".md", ".txt"], | ||
}, | ||
], | ||
actions: [ | ||
{ | ||
type: "add", | ||
path: "{{ turbo.paths.root }}/{{ dashCase file }}{{ type }}", | ||
templateFile: "templates/turborepo-generators.hbs", | ||
}, | ||
], | ||
}); | ||
} |
5 changes: 5 additions & 0 deletions
5
packages/turbo-gen/src/templates/simple-ts/templates/turborepo-generators.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Turborepo Generators | ||
|
||
Read the docs at [turbo.build](https://turbo.build/repo/docs). | ||
|
||
Created by {{ author }}. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import type { Project } from "@turbo/workspaces"; | ||
import path from "path"; | ||
import fs from "fs-extra"; | ||
import { GeneratorError } from "./error"; | ||
|
||
export async function setupFromTemplate({ | ||
project, | ||
template, | ||
}: { | ||
project: Project; | ||
template: "ts" | "js"; | ||
}) { | ||
const configDirectory = path.join(project.paths.root, "turbo", "generators"); | ||
|
||
// TODO: could create some more complex starters in the future | ||
const toCopy = `simple-${template}`; | ||
|
||
// required to ensure we don't overwrite any existing files at this location | ||
if (await fs.pathExists(configDirectory)) { | ||
throw new GeneratorError( | ||
`Generator config directory already exists at ${configDirectory}`, | ||
{ type: "config_directory_already_exists" } | ||
); | ||
} | ||
|
||
// copy templates to project | ||
await fs.copy(path.join(__dirname, "templates", toCopy), configDirectory, { | ||
recursive: true, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,23 @@ | ||
import { defineConfig, Options } from "tsup"; | ||
import fs from "fs-extra"; | ||
import chalk from "chalk"; | ||
|
||
export default defineConfig((options: Options) => ({ | ||
entry: ["src/cli.ts", "src/types.ts"], | ||
format: ["cjs"], | ||
dts: true, | ||
clean: true, | ||
minify: true, | ||
onSuccess: async () => { | ||
// start time | ||
const start = Date.now(); | ||
await fs.copy("src/templates", "dist/templates"); | ||
// make the output match | ||
console.log( | ||
chalk.hex("#7c5cad")("TEMPLATES"), | ||
"copied in", | ||
chalk.green(`${Date.now() - start}ms`) | ||
); | ||
}, | ||
...options, | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { PlopTypes } from "@turbo/gen"; | ||
|
||
export default function generator(plop: PlopTypes.NodePlopAPI): void { | ||
plop.setGenerator("example", { | ||
description: | ||
"An example Turborepo generator - creates a new file at the root of the project", | ||
prompts: [ | ||
{ | ||
type: "input", | ||
name: "file", | ||
placeholder: "generator-docs", | ||
message: "What is the name of the file to create?", | ||
}, | ||
{ | ||
type: "input", | ||
name: "author", | ||
default: "turbobot", | ||
message: "What is your name? (Will be added as the file author)", | ||
}, | ||
{ | ||
type: "list", | ||
name: "type", | ||
message: "What type of file should be created?", | ||
choices: [".md", ".txt"], | ||
default: ".md", | ||
}, | ||
], | ||
actions: [ | ||
{ | ||
type: "add", | ||
path: "{{ turbo.paths.root }}/{{ dashCase file }}{{ type }}", | ||
templateFile: "templates/turborepo-generators.hbs", | ||
}, | ||
], | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Turborepo Generators | ||
|
||
Read the docs at [turbo.build](https://turbo.build/repo/docs). | ||
|
||
Created by {{ author }}. |
a0c228a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
turbo-site – ./docs
www.turbo.build
turbopack.org
turbo.build
turbo-site.vercel.sh
www.turborepo.com
www.turbopack.org
turbo.vercel.app
turbo.vercel.sh
turborepo.org
www.turborepo.org
turbo-site-git-main.vercel.sh