Skip to content

Commit ccb0cd6

Browse files
committed
fix: fix a couple of templates
1 parent afb94cd commit ccb0cd6

5 files changed

Lines changed: 27 additions & 17 deletions

File tree

lib/templates/template.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export async function getConfig(): Promise<Config> {
6161
pluginName = await input({
6262
message: "What is the name of the plugin class? (use PascalCase)",
6363
required: false,
64-
default: generateDefaultPluginName(name, location),
64+
default: generateDefaultPluginName(name, location, type),
6565
validate: validatePluginName,
6666
});
6767
} else {
@@ -97,8 +97,8 @@ export async function generateTemplate(config: Config) {
9797
packageJSONContent.description = config.description;
9898
if (type === "external") {
9999
// For external plugins, the main entry point is at index.js, instead of the default index.cjs
100-
packageJSONContent.exports["."].import = "./dist/index.js";
101-
packageJSONContent.module = "./dist/index.js";
100+
packageJSONContent.exports["."].require = "./dist/index.js";
101+
packageJSONContent.main = "./dist/index.js";
102102
}
103103
await fs.writeFile(packageJSON, JSON.stringify(packageJSONContent, null, 2));
104104

@@ -113,7 +113,10 @@ export async function generateTemplate(config: Config) {
113113
if (pluginName) {
114114
for await (const file of fs.glob(`${bundlePath.replace(pathlib.sep, "/")}/**/*.{ts,tsx}`)) {
115115
const content = await fs.readFile(file, "utf-8");
116-
const updatedContent = content.replace(/PluginName/g, pluginName);
116+
let updatedContent = content.replace(/PluginName/g, pluginName);
117+
if (type === "external") {
118+
updatedContent = updatedContent.replace(/abstract /g, "");
119+
}
117120
await fs.writeFile(file, updatedContent);
118121
}
119122
}

lib/templates/utils.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@ export function validatePluginName(value: string) {
1515
return true;
1616
}
1717

18-
export function generateDefaultPluginName(name: string, location: string) {
19-
return (
20-
name
21-
.split("-")
22-
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
23-
.join("") +
24-
location.charAt(0).toUpperCase() +
25-
location.slice(1) +
26-
"Plugin"
27-
);
18+
export function generateDefaultPluginName(name: string, location: string, type: string) {
19+
return type == "installable"
20+
? "Base"
21+
: "" +
22+
name
23+
.split("-")
24+
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
25+
.join("") +
26+
location.charAt(0).toUpperCase() +
27+
location.slice(1) +
28+
"Plugin";
2829
}

lib/templates/web/rollup.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import typescript from "@rollup/plugin-typescript";
66
* @type {import('rollup').RollupOptions}
77
*/
88
export default {
9-
input: "src/index.ts",
9+
input: "src/index.tsx",
1010
output: [
1111
{
1212
file: "dist/index.cjs",
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { PluginName } from "..";
2+
import { test, expect } from "vitest";
3+
4+
test("should have a valid channel id", () => {
5+
expect(PluginName.channelAttach).toEqual(["__channel_id"]);
6+
});

lib/templates/web/src/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
} from "@sourceacademy/conductor/conduit";
77
import type { ITabService, Tab } from "@sourceacademy/common-tabs";
88

9-
export abstract class TestPlugin implements IPlugin {
9+
export abstract class PluginName implements IPlugin {
1010
readonly id: string = "__plugin_id";
1111
static readonly channelAttach = ["__channel_id"];
1212
private readonly __testChannel: IChannel<string>;
@@ -32,4 +32,4 @@ export abstract class TestPlugin implements IPlugin {
3232
tabService.showTab(tab.id);
3333
}
3434
}
35-
checkIsPluginClass(TestPlugin);
35+
checkIsPluginClass(PluginName);

0 commit comments

Comments
 (0)