Skip to content

Commit 21825d1

Browse files
committed
add plugin template
1 parent dc5b509 commit 21825d1

12 files changed

Lines changed: 208 additions & 0 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# {{PLUGIN_DISPLAY_NAME}}
2+
3+
## Overview
4+
5+
{{PLUGIN_DESCRIPTION}}
6+
7+
## Domain
8+
9+
{{PLUGIN_DOMAIN}}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"name": "@amplication/plugin-{{PLUGIN_KEBAB_CASE_NAME}}",
3+
"version": "0.0.1",
4+
"description": "{{PLUGIN_DESCRIPTION}}",
5+
"main": "dist/index.js",
6+
"scripts": {
7+
"prepublishOnly": "npm run build",
8+
"dev": "webpack --watch",
9+
"build": "webpack",
10+
"prebuild": "rimraf dist",
11+
"lint": "eslint . --ext .ts,.js",
12+
"lint:fix": "eslint . --ext .ts,.js --fix",
13+
"format": "prettier --write \"src/**/*.{ts,js,json,md}\"",
14+
"format:check": "prettier --check \"src/**/*.{ts,js,json,md}\""
15+
},
16+
"author": "{{PLUGIN_AUTHOR}}",
17+
"license": "{{PLUGIN_LICENSE}}",
18+
"devDependencies": {
19+
"@amplication/code-gen-types": "^3.2.1",
20+
"@amplication/code-gen-utils": "^0.0.9",
21+
"@amplication/csharp-ast": "^0.0.7",
22+
"@babel/parser": "^7.23.0",
23+
"@babel/types": "^7.23.0",
24+
"@types/lodash": "^4.14.200",
25+
"@typescript-eslint/eslint-plugin": "^6.21.0",
26+
"@typescript-eslint/parser": "^6.21.0",
27+
"copy-webpack-plugin": "^12.0.2",
28+
"eslint": "^8.57.1",
29+
"eslint-config-prettier": "^9.1.0",
30+
"eslint-plugin-prettier": "^5.2.1",
31+
"jest-mock-extended": "^3.0.5",
32+
"lodash": "^4.17.21",
33+
"prettier": "^3.3.3",
34+
"rimraf": "^5.0.5",
35+
"ts-loader": "^9.5.0",
36+
"typescript": "^5.2.2",
37+
"webpack": "^5.89.0",
38+
"webpack-cli": "^5.1.4",
39+
"pascal-case": "^3.1.2"
40+
}
41+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const PLUGIN_ID = "{{PLUGIN_KEBAB_CASE_NAME}}";
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import {
2+
blueprintPluginEventsParams as blueprint,
3+
blueprintPluginEventsTypes,
4+
blueprintTypes,
5+
IFile,
6+
} from "@amplication/code-gen-types";
7+
import { CodeBlock } from "@amplication/csharp-ast";
8+
import { resolve } from "path";
9+
import { pascalCase } from "pascal-case";
10+
11+
class PluginName implements blueprintTypes.AmplicationPlugin {
12+
register(): blueprintPluginEventsTypes.BlueprintEvents {
13+
return {
14+
createBlueprint: {
15+
before: this.beforeCreateBlueprint,
16+
},
17+
};
18+
}
19+
async beforeCreateBlueprint(
20+
context: blueprintTypes.DsgContext,
21+
eventParams: blueprint.CreateBlueprintParams,
22+
): Promise<blueprint.CreateBlueprintParams> {
23+
context.logger.info("Generating Files from PluginName...");
24+
25+
const params = {} as Record<string, string>;
26+
27+
params.SERVICE_DISPLAY_NAME = context.resourceInfo?.name || "Service Name";
28+
params.SERVICE_NAME = pascalCase(params.SERVICE_DISPLAY_NAME);
29+
30+
//resource catalog properties
31+
const resourceCatalogProperties = (context.resourceInfo?.properties ||
32+
{}) as Record<string, string>;
33+
const resourceSetting = (context.resourceSettings?.properties ||
34+
({} as Record<string, string>)) as Record<string, string>;
35+
36+
//all catalog and resource settings are available for use in the template
37+
const placeholders = {
38+
...params,
39+
...resourceCatalogProperties,
40+
...resourceSetting,
41+
};
42+
43+
const stringReplacements = {
44+
ServiceName: params.SERVICE_NAME,
45+
};
46+
47+
// set the path to the static files and fetch them for manipulation
48+
const staticPath = resolve(__dirname, "./static");
49+
const files = await context.utils.importStaticFilesWithReplacements(
50+
staticPath,
51+
".",
52+
placeholders,
53+
stringReplacements,
54+
);
55+
56+
for (const file of files.getAll()) {
57+
const codeBlock: IFile<CodeBlock> = {
58+
path: file.path,
59+
code: new CodeBlock({
60+
code: file.code,
61+
}),
62+
};
63+
context.files.set(codeBlock);
64+
}
65+
return eventParams;
66+
}
67+
}
68+
69+
export default PluginName;

plugin-templates/blueprint/src/tests/.keep

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export interface Settings {}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { PluginInstallation } from "@amplication/code-gen-types";
2+
import { Settings } from "./types";
3+
import defaultSettings from "../.amplicationrc.json";
4+
import { PLUGIN_ID } from "./constants";
5+
6+
export const getPluginSettings = (
7+
pluginInstallations: PluginInstallation[],
8+
): Settings => {
9+
const plugin = pluginInstallations.find(
10+
(plugin) => plugin.pluginId === PLUGIN_ID,
11+
);
12+
13+
const userSettings = plugin?.settings ?? {};
14+
15+
const settings: Settings = {
16+
...defaultSettings.settings,
17+
...userSettings,
18+
};
19+
20+
return settings;
21+
};

plugin-templates/blueprint/static/.keep

Whitespace-only changes.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES2021", // Latest features supported by Node.js
4+
"module": "CommonJS", // CommonJS for Node.js compatibility
5+
"lib": ["ES2021"], // Use modern ECMAScript features
6+
"strict": true, // Enable strict type-checking
7+
"esModuleInterop": true, // Allow default imports from CommonJS modules
8+
"skipLibCheck": true, // Skip type checks for declaration files
9+
"forceConsistentCasingInFileNames": true, // Enforce consistent casing
10+
"outDir": "dist", // Output directory for compiled files
11+
"rootDir": "src", // Root directory for source files
12+
"declaration": true, // Generate .d.ts files for TypeScript definitions
13+
"moduleResolution": "node", // Resolve modules in Node.js style
14+
"resolveJsonModule": true, // Support importing JSON files
15+
"allowSyntheticDefaultImports": true, // Allow default imports with interop
16+
"noImplicitAny": true, // Disallow `any` unless explicitly stated
17+
"noUnusedLocals": true, // Warn about unused local variables
18+
"noFallthroughCasesInSwitch": true // Prevent fallthrough in switch statements
19+
},
20+
"include": ["src/**/*"], // Include all files in the src directory
21+
"exclude": ["node_modules", "dist", "src/static", "static"] // Exclude unnecessary and template files
22+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
const path = require("path");
2+
const webpack = require("webpack");
3+
const CopyWebpackPlugin = require("copy-webpack-plugin");
4+
5+
/** @type {import("webpack").Configuration} */
6+
module.exports = {
7+
mode: "production",
8+
target: "node",
9+
entry: "./src/index.ts",
10+
externals: ["@amplication/code-gen-utils"],
11+
plugins: [
12+
new webpack.SourceMapDevToolPlugin({
13+
filename: "[name].js.map",
14+
}),
15+
new CopyWebpackPlugin({
16+
patterns: [
17+
{ from: "static", to: "static", noErrorOnMissing: true },
18+
{ from: "src/static", to: "static", noErrorOnMissing: true },
19+
{ from: "src/templates", to: "templates", noErrorOnMissing: true },
20+
],
21+
}),
22+
],
23+
module: {
24+
rules: [
25+
{
26+
test: /\.tsx?$/,
27+
use: "ts-loader",
28+
exclude: /node_modules/,
29+
},
30+
],
31+
},
32+
resolve: {
33+
extensions: [".ts", ".js", ".json"],
34+
},
35+
optimization: {
36+
minimize: false,
37+
},
38+
output: {
39+
filename: "index.js",
40+
path: path.resolve(__dirname, "dist"),
41+
libraryTarget: "commonjs2",
42+
clean: true,
43+
},
44+
};

0 commit comments

Comments
 (0)