@fern-api/generator-cli 0.0.9 → 0.0.11-9ad75c8f6
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 +137 -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,100 @@ 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
|
+
writer.writeLine("# Reference");
|
|
13320
|
+
if (this.referenceConfig.rootSection !== void 0) {
|
|
13321
|
+
this.writeRootSection({ section: this.referenceConfig.rootSection, writer });
|
|
13322
|
+
}
|
|
13323
|
+
for (const section of this.referenceConfig.sections) {
|
|
13324
|
+
this.writeSection({ section, writer });
|
|
13325
|
+
}
|
|
13326
|
+
writer.end();
|
|
13327
|
+
}
|
|
13328
|
+
writeRootSection({ section, writer }) {
|
|
13329
|
+
if (section.description !== void 0) {
|
|
13330
|
+
writer.writeLine(`${section.description}`);
|
|
13331
|
+
}
|
|
13332
|
+
for (const endpoint of section.endpoints) {
|
|
13333
|
+
this.writeEndpoint({ endpoint, writer });
|
|
13334
|
+
}
|
|
13335
|
+
}
|
|
13336
|
+
writeSection({ section, writer }) {
|
|
13337
|
+
writer.writeLine(`## ${section.title}`);
|
|
13338
|
+
if (section.description !== void 0) {
|
|
13339
|
+
writer.writeLine(`${section.description}`);
|
|
13340
|
+
}
|
|
13341
|
+
for (const endpoint of section.endpoints) {
|
|
13342
|
+
this.writeEndpoint({ endpoint, writer });
|
|
13343
|
+
}
|
|
13344
|
+
}
|
|
13345
|
+
writeEndpoint({ endpoint, writer }) {
|
|
13346
|
+
const stringWriter = new StringWriter();
|
|
13347
|
+
if (endpoint.description !== void 0) {
|
|
13348
|
+
stringWriter.writeLine(
|
|
13349
|
+
`#### \u{1F4DD} Description
|
|
13350
|
+
|
|
13351
|
+
${this.writeIndentedBlock(this.writeIndentedBlock(endpoint.description))}
|
|
13352
|
+
`
|
|
13353
|
+
);
|
|
13354
|
+
}
|
|
13355
|
+
stringWriter.writeLine(
|
|
13356
|
+
`#### \u{1F50C} Usage
|
|
13357
|
+
|
|
13358
|
+
${this.writeIndentedBlock(
|
|
13359
|
+
this.writeIndentedBlock(
|
|
13360
|
+
"```" + this.referenceConfig.language.toLowerCase() + "\n" + endpoint.snippet + "\n```"
|
|
13361
|
+
)
|
|
13362
|
+
)}
|
|
13363
|
+
`
|
|
13364
|
+
);
|
|
13365
|
+
if (endpoint.parameters.length > 0) {
|
|
13366
|
+
stringWriter.writeLine(
|
|
13367
|
+
`#### \u2699\uFE0F Parameters
|
|
13368
|
+
|
|
13369
|
+
${this.writeIndentedBlock(
|
|
13370
|
+
endpoint.parameters.map((parameter) => this.writeIndentedBlock(this.writeParameter(parameter))).join("\n\n")
|
|
13371
|
+
)}
|
|
13372
|
+
`
|
|
13373
|
+
);
|
|
13374
|
+
}
|
|
13375
|
+
let linkedSnippet = this.wrapInLinksAndJoin(endpoint.title.snippetParts);
|
|
13376
|
+
if (endpoint.title.returnValue != null) {
|
|
13377
|
+
linkedSnippet += ` -> ${this.wrapInLink(endpoint.title.returnValue.text, endpoint.title.returnValue.location)}`;
|
|
13378
|
+
}
|
|
13379
|
+
writer.writeLine(`<details><summary><code>${linkedSnippet}</code></summary>`);
|
|
13380
|
+
writer.writeLine(this.writeIndentedBlock(stringWriter.toString()));
|
|
13381
|
+
writer.writeLine("</details>\n");
|
|
13382
|
+
}
|
|
13383
|
+
writeParameter(parameter) {
|
|
13384
|
+
const desc = parameter.description?.match(/[^\r\n]+/g)?.length;
|
|
13385
|
+
const containsLineBreak = desc !== void 0 && desc > 1;
|
|
13386
|
+
return `**${parameter.name}:** \`${this.wrapInLink(parameter.type, parameter.location)}\` ${parameter.description !== void 0 ? (containsLineBreak ? "\n\n" : "\u2014 ") + parameter.description : ""}
|
|
13387
|
+
`;
|
|
13388
|
+
}
|
|
13389
|
+
writeIndentedBlock(content) {
|
|
13390
|
+
return `<dl>
|
|
13391
|
+
<dd>
|
|
13392
|
+
|
|
13393
|
+
${content}
|
|
13394
|
+
</dd>
|
|
13395
|
+
</dl>`;
|
|
13396
|
+
}
|
|
13397
|
+
wrapInLinksAndJoin(content) {
|
|
13398
|
+
return content.map(({ text, location }) => this.wrapInLink(text, location)).join("");
|
|
13399
|
+
}
|
|
13400
|
+
wrapInLink(content, link) {
|
|
13401
|
+
return link !== void 0 ? `<a href="${link.path}">${content}</a>` : content;
|
|
13402
|
+
}
|
|
13403
|
+
};
|
|
13404
|
+
|
|
13302
13405
|
// src/cli.ts
|
|
13303
13406
|
void yargs_default(hideBin(process.argv)).scriptName(process.env.CLI_NAME ?? "generator-cli").strict().command(
|
|
13304
13407
|
"generate readme",
|
|
@@ -13325,20 +13428,47 @@ void yargs_default(hideBin(process.argv)).scriptName(process.env.CLI_NAME ?? "ge
|
|
|
13325
13428
|
const generator = new ReadmeGenerator({
|
|
13326
13429
|
readmeParser: new ReadmeParser(),
|
|
13327
13430
|
readmeConfig,
|
|
13328
|
-
originalReadme: argv.originalReadme != null ? await (0,
|
|
13431
|
+
originalReadme: argv.originalReadme != null ? await (0, import_promises5.readFile)(argv.originalReadme, "utf8") : void 0
|
|
13329
13432
|
});
|
|
13330
13433
|
await generator.generateReadme({
|
|
13331
13434
|
output: await createWriteStream(argv.output)
|
|
13332
13435
|
});
|
|
13333
13436
|
process.exit(0);
|
|
13334
13437
|
}
|
|
13438
|
+
).command(
|
|
13439
|
+
"generate-reference",
|
|
13440
|
+
"Generate an SDK reference (`reference.md`) using the provided configuration file.",
|
|
13441
|
+
(argv) => argv.option("config", {
|
|
13442
|
+
string: true,
|
|
13443
|
+
requred: true
|
|
13444
|
+
}).option("output", {
|
|
13445
|
+
string: true,
|
|
13446
|
+
requred: false
|
|
13447
|
+
}),
|
|
13448
|
+
async (argv) => {
|
|
13449
|
+
if (argv.config == null) {
|
|
13450
|
+
process.stderr.write("missing required arguments; please specify the --config flag\n");
|
|
13451
|
+
process.exit(1);
|
|
13452
|
+
}
|
|
13453
|
+
const wd = cwd();
|
|
13454
|
+
const referenceConfig = await loadReferenceConfig({
|
|
13455
|
+
absolutePathToConfig: resolve(wd, argv.config)
|
|
13456
|
+
});
|
|
13457
|
+
const generator = new ReferenceGenerator({
|
|
13458
|
+
referenceConfig
|
|
13459
|
+
});
|
|
13460
|
+
await generator.generate({
|
|
13461
|
+
output: await createWriteStream(argv.output)
|
|
13462
|
+
});
|
|
13463
|
+
process.exit(0);
|
|
13464
|
+
}
|
|
13335
13465
|
).demandCommand().showHelpOnFail(true).parse();
|
|
13336
13466
|
async function createWriteStream(outputPath) {
|
|
13337
13467
|
return outputPath != null ? await createWriteStreamFromFile(resolve(cwd(), outputPath)) : process.stdout;
|
|
13338
13468
|
}
|
|
13339
13469
|
async function createWriteStreamFromFile(filepath) {
|
|
13340
13470
|
if (!doesPathExist(filepath)) {
|
|
13341
|
-
await (0,
|
|
13471
|
+
await (0, import_promises5.mkdir)(import_path7.default.dirname(filepath), { recursive: true });
|
|
13342
13472
|
}
|
|
13343
13473
|
return import_fs5.default.createWriteStream(filepath);
|
|
13344
13474
|
}
|
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.11-9ad75c8f6",
|
|
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",
|