@lars_hagemann/mediaserver-create-plugin 1.0.3 → 1.1.1-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +235 -157
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,46 +1,44 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
- return new (P || (P = Promise))(function (resolve, reject) {
6
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
7
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
8
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
9
- step((generator = generator.apply(thisArg, _arguments || [])).next());
10
- });
11
- };
12
- var __generator = (this && this.__generator) || function (thisArg, body) {
13
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
14
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
15
- function verb(n) { return function (v) { return step([n, v]); }; }
16
- function step(op) {
17
- if (f) throw new TypeError("Generator is already executing.");
18
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
19
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
20
- if (y = 0, t) op = [op[0] & 2, t.value];
21
- switch (op[0]) {
22
- case 0: case 1: t = op; break;
23
- case 4: _.label++; return { value: op[1], done: false };
24
- case 5: _.label++; y = op[1]; op = [0]; continue;
25
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
26
- default:
27
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
28
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
29
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
30
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
31
- if (t[2]) _.ops.pop();
32
- _.trys.pop(); continue;
33
- }
34
- op = body.call(thisArg, _);
35
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
36
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
37
8
  }
38
- };
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || (function () {
20
+ var ownKeys = function(o) {
21
+ ownKeys = Object.getOwnPropertyNames || function (o) {
22
+ var ar = [];
23
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
+ return ar;
25
+ };
26
+ return ownKeys(o);
27
+ };
28
+ return function (mod) {
29
+ if (mod && mod.__esModule) return mod;
30
+ var result = {};
31
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
+ __setModuleDefault(result, mod);
33
+ return result;
34
+ };
35
+ })();
39
36
  Object.defineProperty(exports, "__esModule", { value: true });
40
- var readline = require("readline");
41
- var fs = require("fs/promises");
42
- var child_process_1 = require("child_process");
43
- var frontendTsConfig = {
37
+ const readline = __importStar(require("readline"));
38
+ const fs = __importStar(require("fs/promises"));
39
+ const path = __importStar(require("path"));
40
+ const child_process_1 = require("child_process");
41
+ const frontendTsConfig = {
44
42
  compilerOptions: {
45
43
  target: "ES2023",
46
44
  lib: ["ES2023", "DOM"],
@@ -61,8 +59,9 @@ var frontendTsConfig = {
61
59
  noFallthroughCasesInSwitch: true,
62
60
  noUncheckedSideEffectImports: true,
63
61
  },
62
+ include: ["src/**/*.ts"],
64
63
  };
65
- var backendTsConfig = {
64
+ const backendTsConfig = {
66
65
  compilerOptions: {
67
66
  target: "ES2023",
68
67
  lib: ["ES2023"],
@@ -79,21 +78,124 @@ var backendTsConfig = {
79
78
  noFallthroughCasesInSwitch: true,
80
79
  noUncheckedSideEffectImports: true,
81
80
  },
81
+ include: ["src/**/*.ts"],
82
82
  };
83
- var backendDependencies = [
83
+ const backendDependencies = [
84
84
  "@types/node",
85
85
  "typescript",
86
86
  "@lars_hagemann/mediaserver-backend-plugin-types",
87
87
  ];
88
- var frontendDependencies = [
88
+ const frontendDependencies = [
89
89
  "typescript",
90
90
  "@types/react",
91
91
  "@types/react-dom",
92
92
  "@lars_hagemann/mediaserver-frontend-plugin-types",
93
93
  ];
94
- var backendSkeleton = "\nimport { FileTypePlugin } from \"@lars_hagemann/mediaserver-backend-plugin-types\";\n\nexport const plugin: FileTypePlugin = {\n matcher: (file) => /* Your implementation here */ false,\n thumbnailCreator: async (context) => {\n throw new Error(\"Not implemented\");\n },\n};\n\nexport default plugin;\n";
95
- var frontendSkeleton = "\nimport type { FileTypePlugin } from \"@lars_hagemann/mediaserver-frontend-plugin-types\";\n\nconst plugin: FileTypePlugin = {\n matcher: (fileType) => /* Your implementation here */ false,\n icon: (ReactIcons) => /* Your implementation here */ ReactIcons.FaFile,\n Render: (context) => {\n context.React.useEffect(() => {\n console.log(\"This worked!\");\n }, []);\n\n return context.React.createElement(\"iframe\", {\n className: \"w-full h-full\",\n src: context.objectUrl,\n });\n },\n Diashow: () => null,\n description: \"Your plugin description here\",\n};\n\nexport default plugin;\n";
96
- var config = {
94
+ const themeDependencies = [
95
+ "typescript",
96
+ "@lars_hagemann/mediaserver-frontend-plugin-types",
97
+ ];
98
+ const themeTsConfig = {
99
+ compilerOptions: {
100
+ target: "ES2023",
101
+ lib: ["ES2023", "DOM"],
102
+ module: "ESNext",
103
+ skipLibCheck: true,
104
+ moduleResolution: "bundler",
105
+ verbatimModuleSyntax: true,
106
+ moduleDetection: "force",
107
+ noEmit: false,
108
+ outDir: "dist",
109
+ strict: true,
110
+ noUnusedLocals: true,
111
+ noUnusedParameters: true,
112
+ erasableSyntaxOnly: true,
113
+ noFallthroughCasesInSwitch: true,
114
+ noUncheckedSideEffectImports: true,
115
+ },
116
+ include: ["src/**/*.ts"],
117
+ };
118
+ const themeSkeleton = `
119
+ import type { ThemePlugin } from "@lars_hagemann/mediaserver-frontend-plugin-types";
120
+
121
+ const theme: ThemePlugin = {
122
+ name: "my-theme",
123
+ description: "My custom theme",
124
+ tokens: {
125
+ "--color-bg-base": "#0f172a",
126
+ "--color-surface-1": "#1e293b",
127
+ "--color-surface-2": "#334155",
128
+ "--color-surface-3": "#475569",
129
+ "--color-overlay": "rgb(0 0 0 / 0.7)",
130
+ "--color-text-primary": "rgba(248, 250, 252, 0.9)",
131
+ "--color-text-secondary": "#cbd5e1",
132
+ "--color-text-muted": "#94a3b8",
133
+ "--color-text-faint": "#64748b",
134
+ "--color-accent": "#7c3aed",
135
+ "--color-accent-hover": "#6d28d9",
136
+ "--color-accent-subtle": "#a78bfa",
137
+ "--color-accent-muted": "#c4b5fd",
138
+ "--color-accent-dim": "rgb(109 40 217 / 0.4)",
139
+ "--color-border": "#334155",
140
+ "--color-border-subtle": "#475569",
141
+ "--color-border-strong": "#64748b",
142
+ "--color-chip-bg": "#334155",
143
+ "--color-chip-text": "#cbd5e1",
144
+ "--color-chip-hover": "#a78bfa",
145
+ "--color-link": "#a78bfa",
146
+ "--color-link-hover": "#c4b5fd",
147
+ },
148
+ preview: {
149
+ accent: "#7c3aed",
150
+ background: "#0f172a",
151
+ },
152
+ };
153
+
154
+ export default theme;
155
+ `;
156
+ const backendSkeleton = `
157
+ import { FileTypePlugin } from "@lars_hagemann/mediaserver-backend-plugin-types";
158
+
159
+ export const plugin: FileTypePlugin = {
160
+ matcher: (file) => /* Your implementation here */ false,
161
+ thumbnailCreator: async (context) => {
162
+ throw new Error("Not implemented");
163
+ },
164
+ initialTags: async (path) => {
165
+ return [];
166
+ },
167
+ description: "Your plugin description here",
168
+ };
169
+
170
+ export default plugin;
171
+ `;
172
+ const frontendSkeleton = `
173
+ import type { FileTypePlugin } from "@lars_hagemann/mediaserver-frontend-plugin-types";
174
+
175
+ const plugin: FileTypePlugin = {
176
+ matcher: (fileType) => /* Your implementation here */ false,
177
+ icon: (ReactIcons) => /* Your implementation here */ ReactIcons.FaFile,
178
+ Render: (context) => {
179
+ context.React.useEffect(() => {
180
+ console.log("This worked!");
181
+ }, []);
182
+
183
+ return context.React.createElement("iframe", {
184
+ className: "w-full h-full",
185
+ src: context.objectUrl,
186
+ });
187
+ },
188
+ Diashow: () => null,
189
+ description: "Your plugin description here",
190
+ };
191
+
192
+ export default plugin;
193
+ `;
194
+ const gitIgnoreContent = `
195
+ **/dist/
196
+ **/node_modules/
197
+ `;
198
+ const config = {
97
199
  frontend: {
98
200
  tsConfig: frontendTsConfig,
99
201
  dependencies: frontendDependencies,
@@ -104,128 +206,104 @@ var config = {
104
206
  dependencies: backendDependencies,
105
207
  skeleton: backendSkeleton,
106
208
  },
209
+ theme: {
210
+ tsConfig: themeTsConfig,
211
+ dependencies: themeDependencies,
212
+ skeleton: themeSkeleton,
213
+ },
107
214
  };
108
- var rl = readline.createInterface({
215
+ const rl = readline.createInterface({
109
216
  input: process.stdin,
110
217
  output: process.stdout,
111
218
  });
112
- var question = function (query) {
113
- return new Promise(function (resolve) { return rl.question(query, resolve); });
219
+ const question = (query) => {
220
+ return new Promise((resolve) => rl.question(query, resolve));
114
221
  };
115
- var questionOrDefault = function (query, defaultValue) { return __awaiter(void 0, void 0, void 0, function () {
116
- var answer;
117
- return __generator(this, function (_a) {
118
- switch (_a.label) {
119
- case 0: return [4 /*yield*/, question("".concat(query, " (default: ").concat(defaultValue, "): "))];
120
- case 1:
121
- answer = _a.sent();
122
- return [2 /*return*/, answer.trim() === "" ? defaultValue : answer.trim()];
123
- }
124
- });
125
- }); };
126
- var validatePluginType = function (type) {
127
- var validTypes = ["frontend", "backend"];
128
- return validTypes.includes(type.toLowerCase());
222
+ const questionOrDefault = async (query, defaultValue) => {
223
+ const answer = await question(`${query} ${defaultValue ? `(${defaultValue})` : ""}: `);
224
+ return answer.trim() === "" ? defaultValue : answer.trim();
129
225
  };
130
- function main() {
131
- return __awaiter(this, void 0, void 0, function () {
132
- var folderPath, pluginType, inputType, pluginName, authorName, validate, pluginFolderPath, pluginSrcPath, packageJsonContent, pluginConfig, tsConfigContent, pluginFileName;
133
- return __generator(this, function (_a) {
134
- switch (_a.label) {
135
- case 0: return [4 /*yield*/, questionOrDefault("Enter the plugin folder path", ".")];
136
- case 1:
137
- folderPath = _a.sent();
138
- pluginType = "";
139
- _a.label = 2;
140
- case 2:
141
- if (!true) return [3 /*break*/, 4];
142
- return [4 /*yield*/, questionOrDefault("Enter the plugin type (frontend/backend)", "frontend")];
143
- case 3:
144
- inputType = _a.sent();
145
- if (validatePluginType(inputType)) {
146
- pluginType = inputType.toLowerCase();
147
- return [3 /*break*/, 4];
148
- }
149
- else {
150
- console.log("Invalid plugin type. Please enter 'frontend' or 'backend'.");
151
- }
152
- return [3 /*break*/, 2];
153
- case 4: return [4 /*yield*/, questionOrDefault("Enter the plugin name", "my-plugin")];
154
- case 5:
155
- pluginName = _a.sent();
156
- return [4 /*yield*/, questionOrDefault("Enter the author name", "Your Name")];
157
- case 6:
158
- authorName = _a.sent();
159
- console.log("\nPlugin Configuration:");
160
- console.log("Folder Path: ".concat(folderPath));
161
- console.log("Plugin Type: ".concat(pluginType));
162
- console.log("Plugin Name: ".concat(pluginName));
163
- console.log("Author Name: ".concat(authorName));
164
- return [4 /*yield*/, questionOrDefault("Create plugin? (yes/no)", "yes")];
165
- case 7:
166
- validate = _a.sent();
167
- rl.close();
168
- if (validate.toLowerCase() !== "yes") {
169
- console.log("Plugin creation cancelled.");
170
- return [2 /*return*/];
171
- }
172
- return [4 /*yield*/, fs.mkdir(folderPath, { recursive: true })];
173
- case 8:
174
- _a.sent();
175
- return [4 /*yield*/, fs.mkdir(folderPath + "/src", { recursive: true })];
176
- case 9:
177
- _a.sent();
178
- return [4 /*yield*/, fs.realpath(folderPath)];
179
- case 10:
180
- pluginFolderPath = _a.sent();
181
- pluginSrcPath = "".concat(pluginFolderPath, "/src");
182
- process.chdir(pluginFolderPath);
183
- packageJsonContent = {
184
- name: "".concat(pluginName),
185
- scripts: {
186
- build: "tsc",
187
- },
188
- };
189
- console.log("Writing package.json");
190
- return [4 /*yield*/, fs.writeFile("".concat(pluginFolderPath, "/package.json"), JSON.stringify(packageJsonContent, null, 2))];
191
- case 11:
192
- _a.sent();
193
- pluginConfig = config[pluginType];
194
- tsConfigContent = pluginConfig.tsConfig;
195
- console.log("Writing tsconfig.json");
196
- return [4 /*yield*/, fs.writeFile("".concat(pluginFolderPath, "/tsconfig.json"), JSON.stringify(tsConfigContent, null, 2))];
197
- case 12:
198
- _a.sent();
199
- console.log("Installing dependencies...");
200
- return [4 /*yield*/, new Promise(function (resolve, reject) {
201
- (0, child_process_1.exec)("npm i -D ".concat(pluginConfig.dependencies.join(" ")), function (error, stdout, stderr) {
202
- if (error) {
203
- console.error("Error installing dependencies: ".concat(error.message));
204
- reject(error);
205
- return;
206
- }
207
- if (stderr) {
208
- console.error("stderr: ".concat(stderr));
209
- return;
210
- }
211
- console.log("stdout: ".concat(stdout));
212
- resolve(null);
213
- });
214
- })];
215
- case 13:
216
- _a.sent();
217
- console.log("Writing skeleton plugin file...");
218
- pluginFileName = "index.ts";
219
- return [4 /*yield*/, fs.writeFile("".concat(pluginSrcPath, "/").concat(pluginFileName), pluginConfig.skeleton)];
220
- case 14:
221
- _a.sent();
222
- console.log("Plugin created successfully.");
223
- return [2 /*return*/];
226
+ const validateYesNo = (input, defaultValue) => {
227
+ if (!input)
228
+ return defaultValue || false;
229
+ const trimmed = input.trim().toLowerCase();
230
+ if (defaultValue) {
231
+ return trimmed.length <= 3 && "yes".startsWith(trimmed);
232
+ }
233
+ return !("no".startsWith(trimmed) && trimmed.length <= 2);
234
+ };
235
+ const doExec = (command) => {
236
+ return new Promise((resolve, reject) => {
237
+ (0, child_process_1.exec)(command, (error, stdout, stderr) => {
238
+ if (error) {
239
+ reject(error);
240
+ return;
241
+ }
242
+ if (stderr) {
243
+ resolve(stderr);
244
+ return;
224
245
  }
246
+ resolve(stdout);
225
247
  });
226
248
  });
249
+ };
250
+ async function main() {
251
+ const folderPath = await questionOrDefault("Enter the plugin folder path", path.resolve("."));
252
+ const pluginName = await questionOrDefault("Enter the plugin name", "my-plugin");
253
+ const authorName = await questionOrDefault("Enter the author name", "Your Name");
254
+ const initGitString = await questionOrDefault("Initialize git? (Yes/no)");
255
+ const initGit = validateYesNo(initGitString, true);
256
+ console.log("\nPlugin Configuration:");
257
+ console.log(`Folder Path: ${path.resolve(folderPath)}`);
258
+ console.log(`Plugin Name: ${pluginName}`);
259
+ console.log(`Author Name: ${authorName}`);
260
+ console.log(`Initialize Git: ${initGit ? "Yes" : "No"}`);
261
+ const validateString = await questionOrDefault("Create plugin? (Yes/no)");
262
+ const validate = validateYesNo(validateString, true);
263
+ rl.close();
264
+ if (!validate) {
265
+ console.log("Plugin creation cancelled.");
266
+ return;
267
+ }
268
+ await fs.mkdir(folderPath + `/${pluginName}`, { recursive: true });
269
+ const basePath = await fs.realpath(folderPath + `/${pluginName}`);
270
+ for (const pluginType of ["frontend", "backend", "theme"]) {
271
+ process.chdir(basePath);
272
+ const path = basePath + `/${pluginType}`;
273
+ await fs.mkdir(path, { recursive: true });
274
+ await fs.mkdir(path + "/src", { recursive: true });
275
+ const pluginFolderPath = await fs.realpath(path);
276
+ const pluginSrcPath = `${pluginFolderPath}/src`;
277
+ process.chdir(pluginFolderPath);
278
+ const packageJsonContent = {
279
+ name: `${pluginName}`,
280
+ scripts: {
281
+ build: "tsc",
282
+ },
283
+ };
284
+ console.log("Writing package.json");
285
+ await fs.writeFile(`${pluginFolderPath}/package.json`, JSON.stringify(packageJsonContent, null, 2));
286
+ const pluginConfig = config[pluginType];
287
+ const tsConfigContent = pluginConfig.tsConfig;
288
+ console.log("Writing tsconfig.json");
289
+ await fs.writeFile(`${pluginFolderPath}/tsconfig.json`, JSON.stringify(tsConfigContent, null, 2));
290
+ console.log("Installing dependencies...");
291
+ await doExec(`npm i -D ${pluginConfig.dependencies.join(" ")}`);
292
+ console.log("Writing skeleton plugin file...");
293
+ const pluginFileName = "index.ts";
294
+ await fs.writeFile(`${pluginSrcPath}/${pluginFileName}`, pluginConfig.skeleton);
295
+ }
296
+ if (initGit) {
297
+ console.log("Initializing git repository...");
298
+ process.chdir(basePath);
299
+ await fs.writeFile(`${basePath}/.gitignore`, gitIgnoreContent);
300
+ await doExec("git init -b main");
301
+ await doExec("git add .");
302
+ await doExec('git commit -m "Initial commit"');
303
+ }
304
+ console.log("Plugin created successfully.");
227
305
  }
228
- main().catch(function (err) {
306
+ main().catch((err) => {
229
307
  console.error("Error:", err);
230
308
  process.exit(1);
231
309
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lars_hagemann/mediaserver-create-plugin",
3
- "version": "1.0.3",
3
+ "version": "1.1.1-beta",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "bin": "dist/index.js",