Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add plop plugin #851

Merged
merged 3 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/knip/fixtures/plugins/plop/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "@fixtures/plop",
"version": "*",
"type": "module",
"scripts": {
"plop": "plop"
},
"dependencies": {
"plop": "*"
}
}
27 changes: 27 additions & 0 deletions packages/knip/fixtures/plugins/plop/plopfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const page = {
description: 'Create a documentation page',

prompts: [
{
type: 'input',
name: 'name',
message: 'What is the page name',
},
],

actions(prompts) {
return [
{
type: 'add',
path: `./doc/{{ dashCase name }}.md`,
templateFile: 'template.hbs',
},
];
},
};

function plopConfig(plop) {
plop.setGenerator('Page', page);
}

export default plopConfig;
1 change: 1 addition & 0 deletions packages/knip/fixtures/plugins/plop/template.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# {{ name }}
2 changes: 2 additions & 0 deletions packages/knip/src/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { default as oclif } from './oclif/index.js';
import { default as playwrightCt } from './playwright-ct/index.js';
import { default as playwrightTest } from './playwright-test/index.js';
import { default as playwright } from './playwright/index.js';
import { default as plop } from './plop/index.js';
import { default as postcss } from './postcss/index.js';
import { default as preconstruct } from './preconstruct/index.js';
import { default as prettier } from './prettier/index.js';
Expand Down Expand Up @@ -132,6 +133,7 @@ export const Plugins = {
playwright,
'playwright-ct': playwrightCt,
'playwright-test': playwrightTest,
plop,
postcss,
preconstruct,
prettier,
Expand Down
19 changes: 19 additions & 0 deletions packages/knip/src/plugins/plop/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { IsPluginEnabled, Plugin } from '../../types/config.js';
import { hasDependency } from '../../util/plugin.js';

// https://github.com/plopjs/plop/blob/main/README.md

const title = 'Plop';

const enablers = ['plop'];

const isEnabled: IsPluginEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);

const config = ['plopfile.{cjs,mjs,js,ts}'];

export default {
title,
enablers,
isEnabled,
config,
} satisfies Plugin;
1 change: 1 addition & 0 deletions packages/knip/src/schema/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export const pluginsSchema = z.object({
playwright: pluginSchema,
'playwright-ct': pluginSchema,
'playwright-test': pluginSchema,
plop: pluginSchema,
postcss: pluginSchema,
preconstruct: pluginSchema,
prettier: pluginSchema,
Expand Down
2 changes: 2 additions & 0 deletions packages/knip/src/types/PluginNames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export type PluginName =
| 'playwright'
| 'playwright-ct'
| 'playwright-test'
| 'plop'
| 'postcss'
| 'preconstruct'
| 'prettier'
Expand Down Expand Up @@ -133,6 +134,7 @@ export const pluginNames = [
'playwright',
'playwright-ct',
'playwright-test',
'plop',
'postcss',
'preconstruct',
'prettier',
Expand Down
23 changes: 23 additions & 0 deletions packages/knip/test/plugins/plop.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { test } from 'bun:test';
import assert from 'node:assert/strict';
import { main } from '../../src/index.js';
import { resolve } from '../../src/util/path.js';
import baseArguments from '../helpers/baseArguments.js';
import baseCounters from '../helpers/baseCounters.js';

const cwd = resolve('fixtures/plugins/plop');

test('Find dependencies with the plop plugin', async () => {
const { counters } = await main({
...baseArguments,
cwd,
});

assert.deepEqual(counters, {
...baseCounters,
binaries: 1,
dependencies: 1,
processed: 1,
total: 1,
});
});