Skip to content

Commit

Permalink
feat: remove hooks from plugin generate
Browse files Browse the repository at this point in the history
  • Loading branch information
shetzel committed Jun 20, 2023
1 parent adfe3ed commit 1942ed6
Show file tree
Hide file tree
Showing 19 changed files with 6 additions and 519 deletions.
16 changes: 0 additions & 16 deletions command-snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,6 @@
"flagChars": ["d"],
"flagAliases": ["dryrun"]
},
{
"command": "dev:generate:hook",
"plugin": "@salesforce/plugin-dev",
"flags": ["event", "force"],
"alias": [],
"flagChars": [],
"flagAliases": []
},
{
"command": "dev:generate:library",
"plugin": "@salesforce/plugin-dev",
Expand All @@ -78,13 +70,5 @@
"alias": ["plugins:generate"],
"flagChars": [],
"flagAliases": []
},
{
"command": "dev:hook",
"plugin": "@salesforce/plugin-dev",
"flags": ["json", "plugin"],
"alias": [],
"flagChars": ["p"],
"flagAliases": []
}
]
29 changes: 0 additions & 29 deletions messages/dev.generate.hook.md

This file was deleted.

7 changes: 0 additions & 7 deletions messages/dev.hook.md

This file was deleted.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@salesforce/plugin-dev",
"description": "commands for sf plugin development",
"version": "0.7.11",
"version": "1.0.0",
"author": "Salesforce",
"bugs": "https://github.com/forcedotcom/cli/issues",
"dependencies": {
Expand All @@ -13,7 +13,6 @@
"@salesforce/ts-types": "^2.0.3",
"change-case": "^4.1.2",
"fast-glob": "^3.2.12",
"got": "^11.8.5",
"graphology": "^0.25.1",
"graphology-types": "^0.24.7",
"js-yaml": "^4.1.0",
Expand Down
40 changes: 0 additions & 40 deletions src/commands/dev/generate/hook.ts

This file was deleted.

68 changes: 0 additions & 68 deletions src/commands/dev/hook.ts

This file was deleted.

49 changes: 0 additions & 49 deletions src/generators/hook.ts

This file was deleted.

26 changes: 3 additions & 23 deletions src/generators/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ import * as Generator from 'yeoman-generator';
import yosay = require('yosay');
import { exec } from 'shelljs';
import replace = require('replace-in-file');
import { camelCase } from 'change-case';
import { Messages } from '@salesforce/core';
import { Hook, NYC, PackageJson } from '../types';
import { addHookToPackageJson, readJson, validatePluginName } from '../util';
import { NYC, PackageJson } from '../types';
import { readJson, validatePluginName } from '../util';

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/plugin-dev', 'plugin.generator');
Expand All @@ -26,7 +25,6 @@ type PluginAnswers = {
internal: boolean;
name: string;
description: string;
hooks?: Hook[];
author?: string;
codeCoverage?: string;
};
Expand Down Expand Up @@ -95,13 +93,6 @@ export default class Plugin extends Generator {
choices: ['0%', '25%', '50%', '75%', '90%', '100%'],
when: (answers: { internal: boolean }): boolean => !answers.internal,
},
{
type: 'checkbox',
name: 'hooks',
message: messages.getMessage('question.hooks'),
choices: Object.values(Hook),
when: (answers: { internal: boolean }): boolean => answers.internal,
},
]);

const directory = path.resolve(this.answers.name);
Expand All @@ -123,20 +114,9 @@ export default class Plugin extends Generator {
}

public writing(): void {
let pjson = readJson<PackageJson>(path.join(this.env.cwd, 'package.json'));
const pjson = readJson<PackageJson>(path.join(this.env.cwd, 'package.json'));

this.sourceRoot(path.join(__dirname, '../../templates'));
const hooks = (this.answers.hooks ?? []).map((h) => h.split(' ').join(':')) as Hook[];
for (const hook of hooks) {
const filename = camelCase(hook.replace('sf:', ''));
this.fs.copyTpl(
this.templatePath(`src/hooks/${hook.replace(/:/g, '.')}.ts.ejs`),
this.destinationPath(`src/hooks/${filename}.ts`),
{ year: new Date().getFullYear() }
);

pjson = addHookToPackageJson(hook, filename, pjson);
}

const updated: Partial<PackageJson> = this.answers.internal
? {
Expand Down
8 changes: 0 additions & 8 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export type PackageJson = {
oclif: {
bin: string;
dirname: string;
hooks: Record<string, string | string[]>;
topics: Record<string, Topic>;
};
repository: string;
Expand All @@ -52,13 +51,6 @@ export type PackageJson = {
};
};

export enum Hook {
'sf:env:list' = 'sf env list',
'sf:env:display' = 'sf env display',
'sf:deploy' = 'sf deploy',
'sf:logout' = 'sf logout',
}

export type FlagAnswers = {
char?: string;
type: keyof typeof Flags;
Expand Down
14 changes: 1 addition & 13 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
import * as fs from 'fs';
import * as os from 'os';
import { createEnv } from 'yeoman-environment';
import { ensureArray } from '@salesforce/kit';
import { FlagAnswers, Hook, PackageJson } from './types';
import { FlagAnswers } from './types';

export function generate(type: string, generatorOptions: Record<string, unknown> = {}): Promise<void> {
const env = createEnv();
Expand All @@ -21,17 +20,6 @@ export function readJson<T>(filePath: string): T {
return JSON.parse(pjsonRaw) as T;
}

export function addHookToPackageJson(hook: Hook, filename: string, pjson: PackageJson): PackageJson {
pjson.oclif.hooks = pjson.oclif.hooks || {};
const p = `./lib/hooks/${filename}`;
if (pjson.oclif.hooks[hook]) {
pjson.oclif.hooks[hook] = [...ensureArray(pjson.oclif.hooks[hook]), p];
} else {
pjson.oclif.hooks[hook] = p;
}
return pjson;
}

export async function fileExists(file: string): Promise<boolean> {
try {
await fs.promises.access(file);
Expand Down
Loading

0 comments on commit 1942ed6

Please sign in to comment.