endpoints-sdk-cli 3.0.0-alpha-2.0 → 3.0.0

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.
package/README.md ADDED
@@ -0,0 +1,84 @@
1
+ # matsuri-tech/endpoints-sdk-cli (mes)
2
+
3
+ Endpoints SDK for JavaScript
4
+
5
+ ## Usage
6
+
7
+ ```shell
8
+ pnpm add -D endpoints-sdk-cli
9
+ npx mes --help
10
+ ```
11
+
12
+ ## Commands
13
+
14
+ - [`mes init`](#mes-init)
15
+ - [`mes add [REPOSITORY]`](#mes-add-repository)
16
+ - [`mes install`](#mes-install)
17
+ - [`mes update [SERVICE]`](#mes-update-service)
18
+
19
+ ### `mes init`
20
+
21
+ initialize endpoints.config.json
22
+
23
+ ```shell
24
+ npx mes init
25
+ ```
26
+
27
+ ### `mes add [REPOSITORY]`
28
+
29
+ add service to dependencies & make endpoints files.
30
+
31
+ ```shell
32
+ npx mes add [REPOSITORY]
33
+ ```
34
+
35
+ Examples:
36
+
37
+ ```shell
38
+ mes add [username/repository_name]
39
+ mes add [username/repository_name] -b [branch_name]
40
+ mes add [username/repository_name] -w [workspace_name]
41
+ mes add [username/repository_name] -e [period_name]
42
+ ```
43
+
44
+ ### `mes install`
45
+
46
+ generate endpoints files based on endpoints.config.json
47
+
48
+ ```shell
49
+ npx mes install
50
+ ```
51
+
52
+ ### `mes update [SERVICE]`
53
+
54
+ update service version & regenerate endpoints files
55
+
56
+ ```shell
57
+ npx mes update [SERVICE]
58
+ ```
59
+
60
+ ## Support of `create-react-app`
61
+
62
+ ```json
63
+ {
64
+ "environment_identifier": "process.env.REACT_APP_ENV"
65
+ }
66
+ ```
67
+
68
+ ## Override root url
69
+
70
+ ```json
71
+ {
72
+ "dependencies": {
73
+ "my-service": {
74
+ "version": "ba832b61d0319f42b3cbb30c815cbdecfece959a",
75
+ "repository": "git@github.com:hoge/my-service.git",
76
+ "roots": {
77
+ "dev": "https://dev.hoge.com",
78
+ "prod": "https://hoge.com",
79
+ "local": "http://localhost:3000"
80
+ }
81
+ }
82
+ }
83
+ }
84
+ ```
package/dist/index.cjs ADDED
@@ -0,0 +1,541 @@
1
+ #! /usr/bin/env node
2
+ "use strict";
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
18
+ // If the importer is in node compatibility mode or this is not an ESM
19
+ // file that has been converted to a CommonJS file using a Babel-
20
+ // compatible transform (i.e. "__esModule" has not been set), then set
21
+ // "default" to the CommonJS "module.exports" for node compatibility.
22
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
23
+ mod
24
+ ));
25
+
26
+ // package.json
27
+ var package_default = {
28
+ name: "endpoints-sdk-cli",
29
+ description: "endpoints sdk cli",
30
+ version: "3.0.0",
31
+ type: "module",
32
+ author: "hrdtbs",
33
+ bin: {
34
+ mes: "./dist/index.cjs"
35
+ },
36
+ files: [
37
+ "dist"
38
+ ],
39
+ scripts: {
40
+ test: "vitest",
41
+ lint: "eslint .",
42
+ postlint: "prettier --check .",
43
+ format: "eslint . --fix",
44
+ postformat: "prettier --write .",
45
+ coverage: "vitest --coverage",
46
+ build: "tsup src/index.ts --out-dir dist",
47
+ typecheck: "tsc --noEmit"
48
+ },
49
+ devDependencies: {
50
+ "@types/node": "22.7.8",
51
+ "@vitest/coverage-v8": "2.1.3",
52
+ eslint: "9.17.0",
53
+ "eslint-config-matsuri": "5.4.0",
54
+ prettier: "3.4.2",
55
+ tsup: "8.4.0",
56
+ typescript: "^5.6.3",
57
+ vitest: "2.1.9"
58
+ },
59
+ dependencies: {
60
+ "@apidevtools/json-schema-ref-parser": "11.7.3",
61
+ commander: "12.1.0",
62
+ "json-schema-to-typescript": "15.0.3"
63
+ }
64
+ };
65
+
66
+ // src/index.ts
67
+ var import_commander = require("commander");
68
+
69
+ // src/model/config.ts
70
+ var createConfigOption = () => {
71
+ return {
72
+ output: "./endpoints/",
73
+ environment_identifier: "process.env.NODE_ENV",
74
+ dependencies: {}
75
+ };
76
+ };
77
+ var Config = class {
78
+ $schema;
79
+ output;
80
+ environment_identifier;
81
+ dependencies;
82
+ constructor(option = createConfigOption()) {
83
+ this.$schema = "https://matsuri-tech.github.io/endpoints-sdk-cli/schema.json";
84
+ this.output = option.output;
85
+ this.environment_identifier = option.environment_identifier;
86
+ this.dependencies = option.dependencies;
87
+ }
88
+ push(name, service) {
89
+ this.dependencies[name] = service;
90
+ }
91
+ json() {
92
+ return JSON.stringify(this, null, 2);
93
+ }
94
+ };
95
+
96
+ // src/executers/config.ts
97
+ var import_promises = __toESM(require("fs/promises"), 1);
98
+ var CONFIG_FILE_NAME = "endpoints.config.json";
99
+ var writeConfigFile = async (config) => {
100
+ await import_promises.default.writeFile(CONFIG_FILE_NAME, config.json());
101
+ };
102
+ var createConfigFile = async () => {
103
+ const config = new Config();
104
+ await writeConfigFile(config);
105
+ };
106
+ var readConfigFile = async () => {
107
+ const content = await import_promises.default.readFile(CONFIG_FILE_NAME, "utf-8");
108
+ return new Config(JSON.parse(content));
109
+ };
110
+
111
+ // src/commands/init.ts
112
+ var init = async () => {
113
+ await createConfigFile();
114
+ };
115
+
116
+ // src/executers/repository/getHeadCommitHash.ts
117
+ var import_child_process = require("child_process");
118
+ function getHeadCommitHash(repositoryPath) {
119
+ const output = (0, import_child_process.execSync)("git rev-parse HEAD", { cwd: repositoryPath });
120
+ return output.toString().trim();
121
+ }
122
+
123
+ // src/executers/repository/detectMainBranch.ts
124
+ var import_child_process2 = require("child_process");
125
+ function detectMainBranch(repositoryPath) {
126
+ const output = (0, import_child_process2.execSync)("git rev-parse --abbrev-ref HEAD", {
127
+ cwd: repositoryPath
128
+ });
129
+ return output.toString().trim();
130
+ }
131
+
132
+ // src/executers/repository/cloneRepository.ts
133
+ var import_child_process3 = require("child_process");
134
+ function cloneRepository(sshPath) {
135
+ console.info(`git clone ${sshPath}...`);
136
+ const cache = `node_modules/.endpoints-tmp/${(/* @__PURE__ */ new Date()).getTime()}`;
137
+ const result = (0, import_child_process3.spawnSync)("git", [
138
+ "clone",
139
+ "--no-checkout",
140
+ "--quiet",
141
+ sshPath,
142
+ cache
143
+ ]);
144
+ const error = result.stderr.toString();
145
+ if (error) {
146
+ throw new Error(`Failed to clone repository: ${error}`);
147
+ }
148
+ console.info(`git clone ${sshPath} done!`);
149
+ return cache;
150
+ }
151
+
152
+ // src/executers/repository/getRepositoryData.ts
153
+ var import_child_process4 = require("child_process");
154
+ var fs2 = __toESM(require("fs"), 1);
155
+
156
+ // src/executers/repository/parseJsonSchema.ts
157
+ var import_json_schema_ref_parser = __toESM(require("@apidevtools/json-schema-ref-parser"), 1);
158
+ async function parseJsonSchema(data) {
159
+ const parsed = await import_json_schema_ref_parser.default.dereference(data);
160
+ if ("$defs" in parsed) {
161
+ delete parsed.$defs;
162
+ }
163
+ return parsed;
164
+ }
165
+
166
+ // src/executers/repository/getRepositoryData.ts
167
+ async function getRepositoryData(repositoryPath, branchName, workspace, commitHash) {
168
+ const endpointsFile = workspace !== void 0 ? `./${workspace}/.endpoints.json` : "./.endpoints.json";
169
+ const checkoutResult = (0, import_child_process4.spawnSync)(
170
+ "git",
171
+ ["checkout", branchName, "--", endpointsFile],
172
+ { cwd: repositoryPath }
173
+ );
174
+ if (checkoutResult.status !== 0) {
175
+ console.error(checkoutResult.stderr.toString());
176
+ throw new Error("Failed to checkout");
177
+ }
178
+ if (commitHash !== void 0) {
179
+ const resetResult = (0, import_child_process4.spawnSync)("git", ["reset", "--hard", commitHash], {
180
+ cwd: repositoryPath
181
+ });
182
+ if (resetResult.status !== 0) {
183
+ console.error(resetResult.stderr.toString());
184
+ throw new Error("Failed to git reset");
185
+ }
186
+ }
187
+ const targetFile = workspace !== void 0 ? `${repositoryPath}/${workspace}/.endpoints.json` : `${repositoryPath}/.endpoints.json`;
188
+ const contents = fs2.readFileSync(targetFile, "utf-8");
189
+ const setting = JSON.parse(contents);
190
+ return parseJsonSchema(setting);
191
+ }
192
+
193
+ // src/utils/toCamelCase.ts
194
+ var toCamelCase = (str) => {
195
+ let first = false;
196
+ let result = "";
197
+ for (const s of str) {
198
+ if (first) {
199
+ result += s.toUpperCase();
200
+ first = false;
201
+ } else if (s === "-" || s === "_") {
202
+ first = true;
203
+ } else {
204
+ result += s;
205
+ }
206
+ }
207
+ return result;
208
+ };
209
+
210
+ // src/templates/functions/endpoint/parsePathParams.ts
211
+ var parsePathParams = (path2) => {
212
+ return path2.split("/").filter((segment) => segment.startsWith(":")).map((param) => {
213
+ return {
214
+ name: param.slice(1),
215
+ param_type: "string"
216
+ };
217
+ });
218
+ };
219
+
220
+ // src/templates/functions/endpoint/detectParamType.ts
221
+ var detectParamType = (example) => {
222
+ if (!isNaN(Number(example))) {
223
+ return "number";
224
+ } else {
225
+ return "string";
226
+ }
227
+ };
228
+
229
+ // src/templates/functions/endpoint/parseQueryParams.ts
230
+ var parseQueryParams = (query) => {
231
+ return query.split("&").map((param) => {
232
+ const [name, example] = param.split("=");
233
+ return {
234
+ name,
235
+ example,
236
+ param_type: example !== void 0 ? detectParamType(example) : "string"
237
+ };
238
+ });
239
+ };
240
+
241
+ // src/templates/functions/endpoint/createEndpoint.ts
242
+ var import_json_schema_to_typescript = require("json-schema-to-typescript");
243
+ async function createEndpoint(name, endpoint) {
244
+ const pv = endpoint.path.split("?");
245
+ const endpointPath = pv[0];
246
+ const queryParams = pv.length > 1 ? parseQueryParams(pv[1]) : [];
247
+ const pathParams = parsePathParams(endpointPath);
248
+ const paramNames = [];
249
+ const queryParamNames = [];
250
+ const params = [];
251
+ for (const param of queryParams) {
252
+ if (!paramNames.includes(param.name)) {
253
+ paramNames.push(param.name);
254
+ queryParamNames.push(param.name);
255
+ params.push(param);
256
+ }
257
+ }
258
+ const pathParamNames = [];
259
+ for (const param of pathParams) {
260
+ if (!paramNames.includes(param.name)) {
261
+ paramNames.push(param.name);
262
+ pathParamNames.push(param.name);
263
+ params.push(param);
264
+ }
265
+ }
266
+ const description = endpoint.desc;
267
+ const queryParamsComment = queryParams.length > 0 ? queryParams.map(
268
+ (param) => `@param {${param.param_type}} ${param.name} ${param.example ?? ""}`
269
+ ).join("\n * ") : "";
270
+ const hasPrameters = paramNames.length > 0;
271
+ const parameters = paramNames.join(", ");
272
+ const parameterTypes = params.map(
273
+ (param) => `${param.name}${pathParamNames.includes(param.name) ? "" : "?"}: ${param.param_type}`
274
+ ).join(", ");
275
+ const queryParamNamesStr = queryParamNames.join(", ");
276
+ const pathTemplate = pathParams.reduce(
277
+ (template, param) => template.replace(`:${param.name}`, `\${${param.name}}`),
278
+ endpointPath
279
+ );
280
+ const request = endpoint.request ? await (0, import_json_schema_to_typescript.compile)(endpoint.request, `${name}Request`) : void 0;
281
+ const response = endpoint.response ? await (0, import_json_schema_to_typescript.compile)(endpoint.response, `${name}Response`) : void 0;
282
+ const func = `
283
+ /**
284
+ * ${description}
285
+ * ${queryParamsComment}
286
+ */
287
+ export const ${name} = (${hasPrameters ? `{${parameters}}: {${parameterTypes}}` : ``}) => {
288
+ const __root = root();
289
+ const __queries = Object.entries({${queryParamNamesStr}})
290
+ .filter(([_, value]) => value !== undefined)
291
+ .map(([key, value]) => \`\${key}=\${value}\`)
292
+ .join("&");
293
+ const __path = \`\${__root}${pathTemplate}\`;
294
+ return __queries ? \`\${__path}?\${__queries}\` : __path;
295
+ };`;
296
+ const method = endpoint.method !== void 0 ? `${name}.method = "${endpoint.method}" as const;` : false;
297
+ const authSchema = endpoint.authSchema !== void 0 ? `${name}.authSchema = ${JSON.stringify(endpoint.authSchema)} as const;` : false;
298
+ return [request, response, func, method, authSchema].filter(Boolean).join("\n");
299
+ }
300
+
301
+ // src/templates/functions/root/createRoot.ts
302
+ var normalizeName = (name) => {
303
+ switch (name) {
304
+ case "dev": {
305
+ return "development";
306
+ }
307
+ case "prod": {
308
+ return "production";
309
+ }
310
+ default: {
311
+ return name;
312
+ }
313
+ }
314
+ };
315
+ var normalizePath = (path2) => {
316
+ if (path2.endsWith("/")) {
317
+ return path2.slice(0, -1);
318
+ } else {
319
+ return path2;
320
+ }
321
+ };
322
+ var createRoot = (environment_identifier, env, overrides) => {
323
+ const content = Object.entries(env).map(([key, value]) => {
324
+ const name = normalizeName(key);
325
+ const path2 = normalizePath(overrides?.[key] ?? value);
326
+ return `
327
+ if (${environment_identifier} === "${name}") {
328
+ __root = "${path2}";
329
+ }`;
330
+ }).join("\n");
331
+ return `
332
+ /**
333
+ * A function that returns the URL part common to the endpoints.
334
+ */
335
+ export const root = () => {
336
+ let __root = "";
337
+ ${content}
338
+ return __root
339
+ }`;
340
+ };
341
+
342
+ // src/templates/files/endpoints/createEndpointsContent.ts
343
+ var createEndpointsContent = async (repositoryAlias, service, period, environmentIdentifier, version) => {
344
+ const names = [];
345
+ const functions = [];
346
+ const root = createRoot(environmentIdentifier, period.env, service.roots);
347
+ functions.push(root);
348
+ for (const [name, endpoint] of Object.entries(period.api)) {
349
+ const camelCaseName = toCamelCase(name);
350
+ names.push(camelCaseName);
351
+ const endpointFunc = await createEndpoint(camelCaseName, endpoint);
352
+ functions.push(endpointFunc);
353
+ }
354
+ const exports2 = `export const ${toCamelCase(repositoryAlias)}_${toCamelCase(
355
+ version
356
+ )} = {${names.join(",")}};`;
357
+ return `${functions.join("\n")}
358
+ ${exports2}`;
359
+ };
360
+
361
+ // src/executers/endpoint/getEndpointFilepath.ts
362
+ function getEndpointFilepath(repositoryName, workspace, version, hasExtension = false) {
363
+ let baseName = repositoryName;
364
+ if (workspace !== void 0) {
365
+ baseName += `.${workspace}`;
366
+ }
367
+ if (version !== void 0) {
368
+ baseName += `.${version}`;
369
+ }
370
+ if (hasExtension) {
371
+ baseName += ".ts";
372
+ }
373
+ return baseName;
374
+ }
375
+
376
+ // src/utils/createFile.ts
377
+ var fs3 = __toESM(require("fs"), 1);
378
+ var path = __toESM(require("path"), 1);
379
+ function createFile(output, filename, contents) {
380
+ if (!fs3.existsSync(output)) {
381
+ fs3.mkdirSync(output, { recursive: true });
382
+ }
383
+ const filePath = path.join(output, filename);
384
+ fs3.writeFileSync(filePath, contents);
385
+ }
386
+
387
+ // src/templates/files/index/createIndexContent.ts
388
+ var createIndexContent = (repositoryAlias, filesMetadata) => {
389
+ const [indexImports, indexExportNames] = filesMetadata.reduce(
390
+ (acc, { version, filepath }) => {
391
+ const filepathWithoutExt = filepath.replace(/\.ts$/, "");
392
+ acc[0].push(
393
+ `import * as ${toCamelCase(version)} from './${filepathWithoutExt}';`
394
+ );
395
+ acc[1].push(toCamelCase(version));
396
+ return acc;
397
+ },
398
+ [[], []]
399
+ );
400
+ const importsClause = indexImports.join("\n");
401
+ const exportsClause = indexExportNames.join(",\n ");
402
+ return `${importsClause}
403
+ export const ${toCamelCase(repositoryAlias)} = {
404
+ ${exportsClause}
405
+ };`;
406
+ };
407
+
408
+ // src/executers/endpoint/createEndpointFiles.ts
409
+ async function createEndpointFiles(repositoryAlias, service, environmentIdentifier, output) {
410
+ const clonedRepositoryPath = cloneRepository(service.repository);
411
+ const commitHash = service.version ?? getHeadCommitHash(clonedRepositoryPath);
412
+ const branchName = service.branch ?? detectMainBranch(clonedRepositoryPath);
413
+ const workspace = service.workspaces ? service.workspaces[0] : void 0;
414
+ const repositoryData = await getRepositoryData(
415
+ clonedRepositoryPath,
416
+ branchName,
417
+ workspace,
418
+ service.version
419
+ );
420
+ const filesMetadata = [];
421
+ console.info(`generate endpoint files...`);
422
+ for (const [version, period] of Object.entries(repositoryData)) {
423
+ if (service.exclude_periods?.includes(version)) {
424
+ continue;
425
+ }
426
+ if (period.env === void 0 || period.api === void 0) continue;
427
+ const filepath = getEndpointFilepath(
428
+ repositoryAlias,
429
+ workspace,
430
+ version,
431
+ true
432
+ );
433
+ filesMetadata.push({
434
+ version,
435
+ filepath
436
+ });
437
+ const content = await createEndpointsContent(
438
+ repositoryAlias,
439
+ service,
440
+ period,
441
+ environmentIdentifier,
442
+ version
443
+ );
444
+ createFile(output, filepath, content);
445
+ }
446
+ createFile(
447
+ output,
448
+ getEndpointFilepath(repositoryAlias, void 0, void 0, true),
449
+ createIndexContent(repositoryAlias, filesMetadata)
450
+ );
451
+ console.info(`generate endpoint files done!`);
452
+ return {
453
+ ...service,
454
+ version: commitHash,
455
+ branch: branchName,
456
+ workspaces: workspace !== void 0 ? [workspace] : void 0
457
+ };
458
+ }
459
+
460
+ // src/commands/install.ts
461
+ var install = async () => {
462
+ const config = await readConfigFile();
463
+ for (const [alias, service] of Object.entries(config.dependencies)) {
464
+ await createEndpointFiles(
465
+ alias,
466
+ service,
467
+ config.environment_identifier,
468
+ config.output
469
+ );
470
+ }
471
+ };
472
+
473
+ // src/commands/update.ts
474
+ var update = async (alias) => {
475
+ const config = await readConfigFile();
476
+ const service = config.dependencies[alias];
477
+ const updated = await createEndpointFiles(
478
+ alias,
479
+ {
480
+ ...service,
481
+ version: void 0
482
+ },
483
+ config.environment_identifier,
484
+ config.output
485
+ );
486
+ config.push(alias, updated);
487
+ await writeConfigFile(config);
488
+ };
489
+
490
+ // src/executers/repository/getRepositoryPath.ts
491
+ function getRepositoryPath(repositoryName) {
492
+ return `https://github.com/${repositoryName}`;
493
+ }
494
+
495
+ // src/executers/repository/getRepositoryAlias.ts
496
+ function getRepositoryAlias(repositoryName) {
497
+ const alias = repositoryName.split("/").pop();
498
+ return alias ?? "";
499
+ }
500
+
501
+ // src/commands/add.ts
502
+ var add = async (repositoryName, workspaces, branch, exclduePeriods) => {
503
+ const config = await readConfigFile();
504
+ const alias = getRepositoryAlias(repositoryName);
505
+ const repositoryPath = getRepositoryPath(repositoryName);
506
+ const service = await createEndpointFiles(
507
+ alias,
508
+ {
509
+ version: void 0,
510
+ repository: repositoryPath,
511
+ workspaces,
512
+ branch,
513
+ exclude_periods: exclduePeriods
514
+ },
515
+ config.environment_identifier,
516
+ config.output
517
+ );
518
+ config.push(alias, service);
519
+ await writeConfigFile(config);
520
+ };
521
+
522
+ // src/index.ts
523
+ var program = new import_commander.Command();
524
+ program.name(package_default.name).description(package_default.description).version(package_default.version);
525
+ program.command("init").action(init);
526
+ program.command("add").description("Add a new service").argument("<repository>", "Repository of the service").option("-w, --workspaces <workspaces...>", "Workspaces of the service").option("-b, --branch <branch>", "Branch of the service").option(
527
+ "-e, --exclude-periods <excludePeriods...>",
528
+ "Periods to exclude from the service"
529
+ ).action(
530
+ (repository, options) => {
531
+ void add(
532
+ repository,
533
+ options.workspaces,
534
+ options.branch,
535
+ options.excludePeriods
536
+ );
537
+ }
538
+ );
539
+ program.command("install").action(install);
540
+ program.command("update").description("Update the endpoint files").argument("<alias>", "Alias of the service to update").action(update);
541
+ program.parse();
package/package.json CHANGED
@@ -1,15 +1,38 @@
1
1
  {
2
2
  "name": "endpoints-sdk-cli",
3
+ "description": "endpoints sdk cli",
4
+ "version": "3.0.0",
5
+ "type": "module",
3
6
  "author": "hrdtbs",
4
- "version": "3.0.0-alpha-2.0",
5
- "main": "binary.js",
7
+ "bin": {
8
+ "mes": "./dist/index.cjs"
9
+ },
10
+ "files": [
11
+ "dist"
12
+ ],
6
13
  "scripts": {
7
- "postinstall": "node ./install.js"
14
+ "test": "vitest",
15
+ "lint": "eslint .",
16
+ "postlint": "prettier --check .",
17
+ "format": "eslint . --fix",
18
+ "postformat": "prettier --write .",
19
+ "coverage": "vitest --coverage",
20
+ "build": "tsup src/index.ts --out-dir dist",
21
+ "typecheck": "tsc --noEmit"
8
22
  },
9
- "bin": {
10
- "mes": "./run.js"
23
+ "devDependencies": {
24
+ "@types/node": "22.7.8",
25
+ "@vitest/coverage-v8": "2.1.3",
26
+ "eslint": "9.17.0",
27
+ "eslint-config-matsuri": "5.4.0",
28
+ "prettier": "3.4.2",
29
+ "tsup": "8.4.0",
30
+ "typescript": "^5.6.3",
31
+ "vitest": "2.1.9"
11
32
  },
12
33
  "dependencies": {
13
- "binary-install": "^1.0.1"
34
+ "@apidevtools/json-schema-ref-parser": "11.7.3",
35
+ "commander": "12.1.0",
36
+ "json-schema-to-typescript": "15.0.3"
14
37
  }
15
38
  }
package/binary.js DELETED
@@ -1,56 +0,0 @@
1
- const { Binary } = require("binary-install");
2
- const os = require("os");
3
-
4
- const windows = "x86_64-pc-windows-msvc";
5
-
6
- const getPlatform = () => {
7
- const type = os.type();
8
- const arch = os.arch();
9
-
10
- // https://github.com/nodejs/node/blob/c3664227a83cf009e9a2e1ddeadbd09c14ae466f/deps/uv/src/win/util.c#L1566-L1573
11
- if (
12
- (type === "Windows_NT" || type.startsWith("MINGW32_NT-")) &&
13
- arch === "x64"
14
- ) {
15
- return windows;
16
- }
17
- if (type === "Linux" && arch === "x64") {
18
- return "x86_64-unknown-linux-musl";
19
- }
20
- if (type === "Linux" && arch === "arm64") {
21
- return "aarch64-unknown-linux-musl";
22
- }
23
- if (type === "Darwin" && (arch === "x64" || arch === "arm64")) {
24
- return "x86_64-apple-darwin";
25
- }
26
-
27
- throw new Error(`Unsupported platform: ${type} ${arch}`);
28
- };
29
-
30
- const getBinary = () => {
31
- const platform = getPlatform();
32
- const pkg = require("./package.json");
33
- const version = pkg.version;
34
- const org = "matsuri-tech";
35
- const name = pkg.name;
36
- const url = `https://github.com/${org}/${name}/releases/download/v${version}/${name}-v${version}-${platform}.tar.gz`;
37
- return new Binary(
38
- platform === windows ? "literate-disco.exe" : "literate-disco",
39
- url
40
- );
41
- };
42
-
43
- const install = () => {
44
- const binary = getBinary();
45
- binary.install();
46
- };
47
-
48
- const run = () => {
49
- const binary = getBinary();
50
- binary.run();
51
- };
52
-
53
- module.exports = {
54
- install,
55
- run,
56
- };
package/install.js DELETED
@@ -1,4 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const { install } = require("./binary");
4
- install();
package/run.js DELETED
@@ -1,4 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const { run } = require("./binary");
4
- run();