Skip to content

Commit

Permalink
chore: upgrade plop to 4.0.1 (strapi#21798)
Browse files Browse the repository at this point in the history
  • Loading branch information
innerdvations authored Oct 21, 2024
1 parent 8aa515f commit 73dea42
Show file tree
Hide file tree
Showing 12 changed files with 445 additions and 969 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
"lint-staged": "15.2.10",
"lodash": "4.17.21",
"nx": "18.2.2",
"plop": "2.7.6",
"plop": "4.0.1",
"prettier": "3.3.3",
"prettier-2": "npm:prettier@^2",
"qs": "6.11.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/generators/generators/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"copyfiles": "2.4.1",
"fs-extra": "11.2.0",
"node-plop": "0.26.3",
"plop": "2.7.6",
"plop": "4.0.1",
"pluralize": "8.0.0"
},
"devDependencies": {
Expand Down
24 changes: 15 additions & 9 deletions packages/generators/generators/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
import { join } from 'node:path';
import { Plop, run } from 'plop';
import nodePlop from 'node-plop';

// Starts the Plop CLI programmatically
export const runCLI = () => {
Plop.launch({ configPath: join(__dirname, 'plopfile.js') }, (env) => {
const options = { ...env, dest: join(process.cwd(), 'src') };
run(options, undefined, true);
});
export const runCLI = async () => {
const { Plop, run } = await import('plop');

Plop.prepare(
{
configPath: join(__dirname, 'plopfile.js'),
},
(env) => {
const argv = process.argv.slice(2); // Extract command-line arguments
Plop.execute(env, argv, (env, argv) => run(env, argv, true)); // Pass the third argument 'true' for passArgsBeforeDashes
}
);
};

// Runs a generator programmatically without prompts
export const generate = async (
export const generate = async <T extends Record<string, any>>(
generatorName: string,
options: unknown,
options: T,
{ dir = process.cwd(), plopFile = 'plopfile.js' } = {}
) => {
const plop = nodePlop(join(__dirname, plopFile), {
Expand All @@ -22,7 +28,7 @@ export const generate = async (
});

const generator = plop.getGenerator(generatorName);
await generator.runActions(options, {
await generator.runActions(options satisfies T, {
onSuccess() {},
onFailure() {},
onComment() {},
Expand Down
2 changes: 1 addition & 1 deletion packages/generators/generators/src/plopfile.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pluralize from 'pluralize';
import { NodePlopAPI } from 'plop';
import type { NodePlopAPI } from 'plop';

import generateApi from './plops/api';
import generateController from './plops/controller';
Expand Down
2 changes: 1 addition & 1 deletion packages/generators/generators/src/plops/api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { join } from 'path';
import { NodePlopAPI } from 'plop';
import type { NodePlopAPI } from 'plop';
import fs from 'fs-extra';
import tsUtils from '@strapi/typescript-utils';

Expand Down
3 changes: 2 additions & 1 deletion packages/generators/generators/src/plops/content-type.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { join } from 'path';
import { NodePlopAPI, ActionType } from 'plop';
import type { NodePlopAPI, ActionType } from 'plop';
import slugify from '@sindresorhus/slugify';
import fs from 'fs-extra';
import { strings } from '@strapi/utils';
Expand All @@ -18,6 +18,7 @@ export default (plop: NodePlopAPI) => {
description: 'Generate a content type for an API',
async prompts(inquirer) {
const config = await inquirer.prompt([...ctNamesPrompts, ...kindPrompts]);
// @ts-expect-error issue with deprecated inquirer.prompts attribute to fix with ugprade to inquirer
const attributes = await getAttributesPrompts(inquirer);

const api = await inquirer.prompt([
Expand Down
2 changes: 1 addition & 1 deletion packages/generators/generators/src/plops/controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NodePlopAPI } from 'plop';
import type { NodePlopAPI } from 'plop';
import tsUtils from '@strapi/typescript-utils';

import getDestinationPrompts from './prompts/get-destination-prompts';
Expand Down
2 changes: 1 addition & 1 deletion packages/generators/generators/src/plops/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NodePlopAPI } from 'plop';
import type { NodePlopAPI } from 'plop';
import tsUtils from '@strapi/typescript-utils';

import getDestinationPrompts from './prompts/get-destination-prompts';
Expand Down
2 changes: 1 addition & 1 deletion packages/generators/generators/src/plops/migration.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NodePlopAPI } from 'plop';
import type { NodePlopAPI } from 'plop';
import tsUtils from '@strapi/typescript-utils';
import validateFileNameInput from './utils/validate-file-name-input';
import getFormattedDate from './utils/get-formatted-date';
Expand Down
2 changes: 1 addition & 1 deletion packages/generators/generators/src/plops/policy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NodePlopAPI } from 'plop';
import type { NodePlopAPI } from 'plop';
import tsUtils from '@strapi/typescript-utils';

import getDestinationPrompts from './prompts/get-destination-prompts';
Expand Down
2 changes: 1 addition & 1 deletion packages/generators/generators/src/plops/service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NodePlopAPI } from 'plop';
import type { NodePlopAPI } from 'plop';
import tsUtils from '@strapi/typescript-utils';

import getDestinationPrompts from './prompts/get-destination-prompts';
Expand Down
Loading

0 comments on commit 73dea42

Please sign in to comment.