@fern-api/generator-cli 0.0.9 → 0.0.10-41618efd4
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/dist/cli.cjs +121 -7
- package/package.json +2 -2
package/dist/cli.cjs
CHANGED
|
@@ -5905,14 +5905,14 @@ async function doesPathExist(filepath) {
|
|
|
5905
5905
|
}
|
|
5906
5906
|
|
|
5907
5907
|
// ../../node_modules/.pnpm/@fern-api+fs-utils@0.15.0-rc63/node_modules/@fern-api/fs-utils/lib/resolve.js
|
|
5908
|
-
var import_path = __toESM(require("path"));
|
|
5908
|
+
var import_path = __toESM(require("path"), 1);
|
|
5909
5909
|
function resolve(...paths) {
|
|
5910
5910
|
return import_path.default.resolve(...paths);
|
|
5911
5911
|
}
|
|
5912
5912
|
|
|
5913
5913
|
// src/cli.ts
|
|
5914
5914
|
var import_fs5 = __toESM(require("fs"), 1);
|
|
5915
|
-
var
|
|
5915
|
+
var import_promises5 = require("fs/promises");
|
|
5916
5916
|
var import_path7 = __toESM(require("path"), 1);
|
|
5917
5917
|
|
|
5918
5918
|
// ../../node_modules/.pnpm/yargs@17.7.2/node_modules/yargs/build/lib/yerror.js
|
|
@@ -7512,6 +7512,15 @@ async function loadReadmeConfig({
|
|
|
7512
7512
|
return JSON.parse(rawContents);
|
|
7513
7513
|
}
|
|
7514
7514
|
|
|
7515
|
+
// src/configuration/loadReferenceConfig.ts
|
|
7516
|
+
var import_promises3 = require("fs/promises");
|
|
7517
|
+
async function loadReferenceConfig({
|
|
7518
|
+
absolutePathToConfig
|
|
7519
|
+
}) {
|
|
7520
|
+
const rawContents = await (0, import_promises3.readFile)(absolutePathToConfig, "utf8");
|
|
7521
|
+
return JSON.parse(rawContents);
|
|
7522
|
+
}
|
|
7523
|
+
|
|
7515
7524
|
// ../../node_modules/.pnpm/simple-git@3.24.0/node_modules/simple-git/dist/esm/index.js
|
|
7516
7525
|
var import_file_exists = __toESM(require_dist(), 1);
|
|
7517
7526
|
var import_debug = __toESM(require_src(), 1);
|
|
@@ -12019,7 +12028,7 @@ var esm_default2 = gitInstanceFactory;
|
|
|
12019
12028
|
var import_tmp_promise = __toESM(require_tmp_promise(), 1);
|
|
12020
12029
|
|
|
12021
12030
|
// ../../packages/commons/github/dist/ClonedRepository.js
|
|
12022
|
-
var
|
|
12031
|
+
var import_promises4 = require("fs/promises");
|
|
12023
12032
|
var import_path6 = __toESM(require("path"), 1);
|
|
12024
12033
|
|
|
12025
12034
|
// ../../packages/commons/github/dist/constants.js
|
|
@@ -12042,12 +12051,12 @@ var ClonedRepository = class {
|
|
|
12042
12051
|
if (!await doesPathExist2(absoluteFilePath)) {
|
|
12043
12052
|
return void 0;
|
|
12044
12053
|
}
|
|
12045
|
-
return await (0,
|
|
12054
|
+
return await (0, import_promises4.readFile)(absoluteFilePath, "utf-8");
|
|
12046
12055
|
}
|
|
12047
12056
|
};
|
|
12048
12057
|
async function doesPathExist2(filepath) {
|
|
12049
12058
|
try {
|
|
12050
|
-
await (0,
|
|
12059
|
+
await (0, import_promises4.lstat)(filepath);
|
|
12051
12060
|
return true;
|
|
12052
12061
|
} catch {
|
|
12053
12062
|
return false;
|
|
@@ -13299,6 +13308,84 @@ function sectionNameToID(sectionName) {
|
|
|
13299
13308
|
).toUpperCase();
|
|
13300
13309
|
}
|
|
13301
13310
|
|
|
13311
|
+
// src/reference/ReferenceGenerator.ts
|
|
13312
|
+
var ReferenceGenerator = class {
|
|
13313
|
+
referenceConfig;
|
|
13314
|
+
constructor({ referenceConfig }) {
|
|
13315
|
+
this.referenceConfig = referenceConfig;
|
|
13316
|
+
}
|
|
13317
|
+
async generate({ output }) {
|
|
13318
|
+
const writer = new StreamWriter(output);
|
|
13319
|
+
for (const section of this.referenceConfig.sections) {
|
|
13320
|
+
this.writeSection({ section, writer });
|
|
13321
|
+
}
|
|
13322
|
+
writer.end();
|
|
13323
|
+
}
|
|
13324
|
+
writeSection({ section, writer }) {
|
|
13325
|
+
writer.writeLine(`## ${section.title}`);
|
|
13326
|
+
writer.writeLine(`${section.description}`);
|
|
13327
|
+
for (const endpoint of section.endpoints) {
|
|
13328
|
+
this.writeEndpoint({ endpoint, writer });
|
|
13329
|
+
}
|
|
13330
|
+
}
|
|
13331
|
+
writeEndpoint({ endpoint, writer }) {
|
|
13332
|
+
const stringWriter = new StringWriter();
|
|
13333
|
+
if (endpoint.description !== void 0) {
|
|
13334
|
+
stringWriter.writeLine(
|
|
13335
|
+
`#### \u{1F4DD} Description
|
|
13336
|
+
|
|
13337
|
+
${this.writeIndentedBlock(this.writeIndentedBlock(endpoint.description))}
|
|
13338
|
+
`
|
|
13339
|
+
);
|
|
13340
|
+
}
|
|
13341
|
+
stringWriter.writeLine(
|
|
13342
|
+
`#### \u{1F50C} Usage
|
|
13343
|
+
|
|
13344
|
+
${this.writeIndentedBlock(
|
|
13345
|
+
this.writeIndentedBlock(
|
|
13346
|
+
"```" + this.referenceConfig.language.toLowerCase() + "\n" + endpoint.snippet + "\n```"
|
|
13347
|
+
)
|
|
13348
|
+
)}
|
|
13349
|
+
`
|
|
13350
|
+
);
|
|
13351
|
+
if (endpoint.parameters.length > 0) {
|
|
13352
|
+
stringWriter.writeLine(
|
|
13353
|
+
`#### \u2699\uFE0F Parameters
|
|
13354
|
+
|
|
13355
|
+
${this.writeIndentedBlock(
|
|
13356
|
+
endpoint.parameters.map((parameter) => this.writeIndentedBlock(this.writeParameter(parameter))).join("\n\n")
|
|
13357
|
+
)}
|
|
13358
|
+
`
|
|
13359
|
+
);
|
|
13360
|
+
}
|
|
13361
|
+
writer.writeLine(
|
|
13362
|
+
`<details><summary><code>${this.wrapInLinksAndJoin(endpoint.title.snippetParts)}</code></summary>`
|
|
13363
|
+
);
|
|
13364
|
+
writer.writeLine(this.writeIndentedBlock(stringWriter.toString()));
|
|
13365
|
+
writer.writeLine("</details>\n");
|
|
13366
|
+
}
|
|
13367
|
+
writeParameter(parameter) {
|
|
13368
|
+
const desc = parameter.description?.match(/[^\r\n]+/g)?.length;
|
|
13369
|
+
const containsLineBreak = desc !== void 0 && desc > 1;
|
|
13370
|
+
return `**${parameter.name}:** \`${this.wrapInLink(parameter.type, parameter.location)}\` ${parameter.description !== void 0 ? (containsLineBreak ? "\n\n" : "\u2014 ") + parameter.description : ""}
|
|
13371
|
+
`;
|
|
13372
|
+
}
|
|
13373
|
+
writeIndentedBlock(content) {
|
|
13374
|
+
return `<dl>
|
|
13375
|
+
<dd>
|
|
13376
|
+
|
|
13377
|
+
${content}
|
|
13378
|
+
</dd>
|
|
13379
|
+
</dl>`;
|
|
13380
|
+
}
|
|
13381
|
+
wrapInLinksAndJoin(content) {
|
|
13382
|
+
return content.map(({ text, location }) => this.wrapInLink(text, location)).join("");
|
|
13383
|
+
}
|
|
13384
|
+
wrapInLink(content, link) {
|
|
13385
|
+
return link !== void 0 ? `<a href="${link.path}">${content}</a>` : content;
|
|
13386
|
+
}
|
|
13387
|
+
};
|
|
13388
|
+
|
|
13302
13389
|
// src/cli.ts
|
|
13303
13390
|
void yargs_default(hideBin(process.argv)).scriptName(process.env.CLI_NAME ?? "generator-cli").strict().command(
|
|
13304
13391
|
"generate readme",
|
|
@@ -13325,20 +13412,47 @@ void yargs_default(hideBin(process.argv)).scriptName(process.env.CLI_NAME ?? "ge
|
|
|
13325
13412
|
const generator = new ReadmeGenerator({
|
|
13326
13413
|
readmeParser: new ReadmeParser(),
|
|
13327
13414
|
readmeConfig,
|
|
13328
|
-
originalReadme: argv.originalReadme != null ? await (0,
|
|
13415
|
+
originalReadme: argv.originalReadme != null ? await (0, import_promises5.readFile)(argv.originalReadme, "utf8") : void 0
|
|
13329
13416
|
});
|
|
13330
13417
|
await generator.generateReadme({
|
|
13331
13418
|
output: await createWriteStream(argv.output)
|
|
13332
13419
|
});
|
|
13333
13420
|
process.exit(0);
|
|
13334
13421
|
}
|
|
13422
|
+
).command(
|
|
13423
|
+
"generate-reference",
|
|
13424
|
+
"Generate an SDK reference (`reference.md`) using the provided configuration file.",
|
|
13425
|
+
(argv) => argv.option("config", {
|
|
13426
|
+
string: true,
|
|
13427
|
+
requred: true
|
|
13428
|
+
}).option("output", {
|
|
13429
|
+
string: true,
|
|
13430
|
+
requred: false
|
|
13431
|
+
}),
|
|
13432
|
+
async (argv) => {
|
|
13433
|
+
if (argv.config == null) {
|
|
13434
|
+
process.stderr.write("missing required arguments; please specify the --config flag\n");
|
|
13435
|
+
process.exit(1);
|
|
13436
|
+
}
|
|
13437
|
+
const wd = cwd();
|
|
13438
|
+
const referenceConfig = await loadReferenceConfig({
|
|
13439
|
+
absolutePathToConfig: resolve(wd, argv.config)
|
|
13440
|
+
});
|
|
13441
|
+
const generator = new ReferenceGenerator({
|
|
13442
|
+
referenceConfig
|
|
13443
|
+
});
|
|
13444
|
+
await generator.generate({
|
|
13445
|
+
output: await createWriteStream(argv.output)
|
|
13446
|
+
});
|
|
13447
|
+
process.exit(0);
|
|
13448
|
+
}
|
|
13335
13449
|
).demandCommand().showHelpOnFail(true).parse();
|
|
13336
13450
|
async function createWriteStream(outputPath) {
|
|
13337
13451
|
return outputPath != null ? await createWriteStreamFromFile(resolve(cwd(), outputPath)) : process.stdout;
|
|
13338
13452
|
}
|
|
13339
13453
|
async function createWriteStreamFromFile(filepath) {
|
|
13340
13454
|
if (!doesPathExist(filepath)) {
|
|
13341
|
-
await (0,
|
|
13455
|
+
await (0, import_promises5.mkdir)(import_path7.default.dirname(filepath), { recursive: true });
|
|
13342
13456
|
}
|
|
13343
13457
|
return import_fs5.default.createWriteStream(filepath);
|
|
13344
13458
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fern-api/generator-cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10-41618efd4",
|
|
4
4
|
"files": [
|
|
5
5
|
"dist"
|
|
6
6
|
],
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"execa": "^5.1.1",
|
|
38
38
|
"lodash-es": "^4.17.12",
|
|
39
39
|
"organize-imports-cli": "^0.10.0",
|
|
40
|
-
"prettier": "^3.2
|
|
40
|
+
"prettier": "^3.3.2",
|
|
41
41
|
"tsup": "^8.0.2",
|
|
42
42
|
"typescript": "4.9.5",
|
|
43
43
|
"vitest": "^1.5.0",
|