Skip to content

Commit

Permalink
Fix create-plugin command
Browse files Browse the repository at this point in the history
  • Loading branch information
yoannmoinet committed May 29, 2024
1 parent 812e2b4 commit 8ffac17
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 23 deletions.
15 changes: 4 additions & 11 deletions packages/tools/src/commands/create-plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,8 @@ class CreatePlugin extends Command {
}

async execute() {
const { updateFiles } = await import('../integrity/files');
const { updateReadmes } = await import('../integrity/readme');
const { askName, askFilesToInclude } = await import('./ask');
const { runAutoFixes } = await import('../../helpers');
const { execute, green } = await import('../../helpers');

const name = await askName(this.name);
const filesToInclude = await askFilesToInclude({
Expand All @@ -74,14 +72,9 @@ class CreatePlugin extends Command {
// Create all the necessary files.
await this.createFiles(context);

// Update our documentations.
await updateReadmes([plugin]);

// Update the shared files.
updateFiles([plugin]);

// Run all the autofixes.
await runAutoFixes();
// Run the integrity check.
console.log(`Running ${green('yarn cli integrity')}.`);
await execute('yarn', ['cli', 'integrity']);
}
}

Expand Down
20 changes: 10 additions & 10 deletions packages/tools/src/commands/create-plugin/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@ const getTemplates = (context: Context): File[] => {
const testRoot = `packages/tests/src/plugins/${plugin.slug}`;
const title = getTitle(plugin.slug);
const pascalCase = getPascalCase(plugin.slug);
const camelCase = pascalCase[0].toLowerCase() + pascalCase.slice(1);
const pkg = getPackageJsonData();
const webpackPeerVersions = getPackageJsonData('webpack').peerDependencies.webpack;
const esbuildPeerVersions = getPackageJsonData('esbuild').peerDependencies.esbuild;
const webpackPeerVersions = getPackageJsonData('webpack-plugin').peerDependencies.webpack;
const esbuildPeerVersions = getPackageJsonData('esbuild-plugin').peerDependencies.esbuild;

return [
{
name: `${plugin.location}/src/constants.ts`,
content: (ctx) => {
return outdent`
export const CONFIG_KEY = '${ctx.plugin.slug}' as const;
export const CONFIG_KEY = '${camelCase}' as const;
export const PLUGIN_NAME = 'datadog-${ctx.plugin.slug}-plugin' as const;
`;
},
Expand All @@ -31,7 +32,7 @@ const getTemplates = (context: Context): File[] => {
name: `${plugin.location}/src/index.ts`,
content: (ctx) => {
return outdent`
import type { GetPlugins } from '@datadog/build-plugins-core/types';
import type { GetPlugins } from '@dd/core/types';
import { PLUGIN_NAME } from './constants';
${ctx.esbuild ? `import { getEsbuildPlugin } from './esbuild-plugin';` : ''}
Expand Down Expand Up @@ -68,7 +69,7 @@ const getTemplates = (context: Context): File[] => {
name: `${plugin.location}/src/types.ts`,
content: () => {
return outdent`
import type { GetPluginsOptionsWithCWD } from '@datadog/build-plugins-core/types';
import type { GetPluginsOptionsWithCWD } from '@dd/core/types';
import type { CONFIG_KEY } from './constants';
Expand Down Expand Up @@ -113,15 +114,14 @@ const getTemplates = (context: Context): File[] => {
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@datadog/build-plugins-core": "${pkg.dependencies['@datadog/build-plugins-core']}",
"@dd/core": "workspace:*",
${ctx.esbuild ? `"esbuild": "${pkg.dependencies.esbuild}",` : ''}
${ctx.webpack ? `"webpack": "${pkg.dependencies.webpack}",` : ''}
"unplugin": "${pkg.dependencies.unplugin}"
},
"peerDependencies": {
${ctx.esbuild ? `"esbuild": "${esbuildPeerVersions}",` : ''}
${ctx.webpack ? `"webpack": "${webpackPeerVersions}",` : ''}
"@datadog/build-plugins-core": "${pkg.peerDependencies['@datadog/build-plugins-core']}"
}
}
`;
Expand All @@ -147,7 +147,7 @@ const getTemplates = (context: Context): File[] => {
## Configuration
\`\`\`ts
${plugin.slug}: {
${camelCase}: {
disabled?: boolean;
}
\`\`\`
Expand Down Expand Up @@ -193,7 +193,7 @@ const getTemplates = (context: Context): File[] => {
const plugin = datadogWebpackPlugin({
...mockOptions,
'${ctx.plugin.slug}': {
'${camelCase}': {
disabled: true,
},
});
Expand All @@ -219,7 +219,7 @@ const getTemplates = (context: Context): File[] => {
test('It should not execute if disabled', () => {
const plugin = datadogEsbuildPlugin({
...mockOptions,
'${ctx.plugin.slug}': { disabled: true },
'${camelCase}': { disabled: true },
});
plugin.setup(mockBuild);
Expand Down
2 changes: 1 addition & 1 deletion packages/tools/src/commands/integrity/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const updateFactory = (plugins: Workspace[]) => {
// Prepare content.
importContent += outdent`
import type { OptionsWith${pascalCase}Enabled, ${pascalCase}Options } from '${plugin.name}/types';
import{
import {
helpers as ${camelCase}Helpers,
getPlugins as get${pascalCase}Plugins,
CONFIG_KEY as ${upperCase}_CONFIG_KEY,
Expand Down
2 changes: 1 addition & 1 deletion packages/tools/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const slugify = (string: string) => {
.replace(/[\u0300-\u036f]/g, '') // Remove all previously split accents
.toLowerCase()
.trim()
.replace(/[^a-z0-9 ]/g, '') // Remove all chars not letters, numbers and spaces
.replace(/[^a-z0-9 -]/g, '') // Remove all chars not letters, numbers and spaces
.replace(/\s+/g, '-'); // Collapse whitespace and replace by -
};

Expand Down

0 comments on commit 8ffac17

Please sign in to comment.