Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/create-turbo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"dependencies": {
"commander": "^11.0.0",
"fs-extra": "^11.1.1",
"inquirer": "^8.2.7",
"inquirer": "^8.0.0",
"picocolors": "1.0.1",
"proxy-agent": "^6.5.0",
"semver": "^7.3.8",
Expand Down
4 changes: 2 additions & 2 deletions packages/turbo-codemod/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
"find-up": "4.1.0",
"fs-extra": "^10.0.0",
"gradient-string": "^2.0.0",
"inquirer": "^8.2.7",
"inquirer": "^8.2.4",
"inquirer-file-tree-selection-prompt": "^1.0.19",
"is-git-clean": "^1.1.0",
"json5": "^2.2.3",
"is-git-clean": "^1.1.0",
"ora": "4.1.1",
"picocolors": "1.0.1",
"semver": "^7.3.7",
Expand Down
6 changes: 3 additions & 3 deletions packages/turbo-gen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
"@turbo/workspaces": "workspace:*",
"commander": "^10.0.0",
"fs-extra": "^10.1.0",
"inquirer": "^8.2.7",
"inquirer": "^8.2.4",
"minimatch": "^9.0.0",
"node-plop": "0.32.1",
"node-plop": "^0.26.3",
"picocolors": "1.0.1",
"proxy-agent": "^6.5.0",
"ts-node": "^10.9.2",
Expand All @@ -47,8 +47,8 @@
"@types/inquirer": "^8.2.5",
"@types/node": "^18.17.2",
"@types/validate-npm-package-name": "^4.0.0",
"jest": "^29.7.0",
"publint": "^0.3.12",
"jest": "^29.7.0",
"ts-jest": "^29.2.5",
"tsup": "^6.7.0",
"typescript": "5.5.4"
Expand Down
10 changes: 2 additions & 8 deletions packages/turbo-gen/src/generators/custom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ export async function generate({
opts,
}: CustomGeneratorArguments) {
let isOnboarding = false;
let generators = await getCustomGenerators({
project,
configPath: opts.config,
});
let generators = getCustomGenerators({ project, configPath: opts.config });
if (!generators.length) {
logger.error(`No generators found.`);
logger.log();
Expand Down Expand Up @@ -43,10 +40,7 @@ export async function generate({
logger.log();

// fetch generators again, and continue to selection prompt
generators = await getCustomGenerators({
project,
configPath: opts.config,
});
generators = getCustomGenerators({ project, configPath: opts.config });

// something went wrong and we weren't able to find our new custom generator
if (!generators.length) {
Expand Down
64 changes: 28 additions & 36 deletions packages/turbo-gen/src/utils/plop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import path from "node:path";
import fs from "fs-extra";
import type { Project } from "@turbo/workspaces";
import type { NodePlopAPI, PlopGenerator } from "node-plop";
import nodePlop from "node-plop";
import { register } from "ts-node";
import { Separator } from "inquirer";
import { searchUp, getTurboConfigs, logger } from "@turbo/utils";
Expand All @@ -26,13 +27,13 @@ export type Generator = PlopGenerator & {
name: string;
};

export async function getPlop({
export function getPlop({
project,
configPath,
}: {
project: Project;
configPath?: string;
}): Promise<NodePlopAPI | undefined> {
}): NodePlopAPI | undefined {
// init ts-node for plop to support ts configs
register({
transpileOnly: true,
Expand All @@ -55,8 +56,7 @@ export async function getPlop({
}

try {
const { default: nodePlop } = await import("node-plop");
plop = await nodePlop(configPath, {
plop = nodePlop(configPath, {
destBasePath: configPath,
force: false,
});
Expand All @@ -65,33 +65,26 @@ export async function getPlop({
}
} else {
// look for a root config
const rootConfigPromises = SUPPORTED_ROOT_GENERATOR_CONFIGS.map(
async (possiblePath) => {
const plopFile = path.join(project.paths.root, possiblePath);
if (!fs.existsSync(plopFile)) {
return null;
}

try {
const { default: nodePlop } = await import("node-plop");
return await nodePlop(plopFile, {
destBasePath: project.paths.root,
force: false,
});
} catch (e) {
logger.error(e);
return null;
}
for (const possiblePath of SUPPORTED_ROOT_GENERATOR_CONFIGS) {
const plopFile = path.join(project.paths.root, possiblePath);
if (!fs.existsSync(plopFile)) {
continue;
}
);

const rootConfigs = await Promise.all(rootConfigPromises);
plop = rootConfigs.find((config) => config !== null) || undefined;
try {
plop = nodePlop(plopFile, {
destBasePath: project.paths.root,
force: false,
});
break;
} catch (e) {
logger.error(e);
}
}

if (!plop && workspaceConfigs.length > 0) {
// if no root config, use the first workspace config as the entrypoint
const { default: nodePlop } = await import("node-plop");
plop = await nodePlop(workspaceConfigs[0].config, {
plop = nodePlop(workspaceConfigs[0].config, {
destBasePath: workspaceConfigs[0].root,
force: false,
});
Expand All @@ -101,30 +94,29 @@ export async function getPlop({

if (plop) {
// add in all the workspace configs
const loadPromises = workspaceConfigs.map(async (c) => {
workspaceConfigs.forEach((c) => {
try {
await plop.load(c.config, {
plop.load(c.config, {
destBasePath: c.root,
force: false,
});
} catch (e) {
logger.error(e);
}
});
await Promise.all(loadPromises);
}

return plop;
}

export async function getCustomGenerators({
export function getCustomGenerators({
project,
configPath,
}: {
project: Project;
configPath?: string;
}): Promise<Array<Generator | Separator>> {
const plop = await getPlop({ project, configPath });
}): Array<Generator | Separator> {
const plop = getPlop({ project, configPath });

if (!plop) {
return [];
Expand Down Expand Up @@ -174,16 +166,16 @@ export async function getCustomGenerators({
return gensWithSeparators;
}

export async function getCustomGenerator({
export function getCustomGenerator({
project,
generator,
configPath,
}: {
project: Project;
generator: string;
configPath?: string;
}): Promise<string | undefined> {
const plop = await getPlop({ project, configPath });
}): string | undefined {
const plop = getPlop({ project, configPath });
if (!plop) {
return undefined;
}
Expand Down Expand Up @@ -257,7 +249,7 @@ export async function runCustomGenerator({
bypassArgs?: Array<string>;
configPath?: string;
}): Promise<void> {
const plop = await getPlop({ project, configPath });
const plop = getPlop({ project, configPath });
if (!plop) {
throw new GeneratorError("Unable to load generators", {
type: "plop_unable_to_load_config",
Expand Down
3 changes: 1 addition & 2 deletions packages/turbo-gen/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"extends": "@turbo/tsconfig/library.json",
"exclude": ["src/templates", "dist", "node_modules"],
"compilerOptions": {
"rootDir": ".",
"module": "ESNext"
"rootDir": "."
}
}
2 changes: 1 addition & 1 deletion packages/turbo-workspaces/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"fast-glob": "^3.2.12",
"fs-extra": "^10.1.0",
"gradient-string": "^2.0.0",
"inquirer": "^8.2.7",
"inquirer": "^8.0.0",
"js-yaml": "^4.1.0",
"ora": "4.1.1",
"picocolors": "1.0.1",
Expand Down
Loading
Loading