@fern-api/generator-cli 0.1.8 → 0.3.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/dist/api.cjs +7563 -0
- package/dist/api.d.cts +586 -0
- package/dist/cli.cjs +238 -166
- package/package.json +6 -3
package/dist/cli.cjs
CHANGED
|
@@ -5846,7 +5846,7 @@ function resolve(...paths) {
|
|
|
5846
5846
|
|
|
5847
5847
|
// src/cli.ts
|
|
5848
5848
|
var import_fs6 = __toESM(require("fs"), 1);
|
|
5849
|
-
var
|
|
5849
|
+
var import_promises7 = require("fs/promises");
|
|
5850
5850
|
var import_path7 = __toESM(require("path"), 1);
|
|
5851
5851
|
|
|
5852
5852
|
// ../../node_modules/.pnpm/yargs@17.7.2/node_modules/yargs/build/lib/yerror.js
|
|
@@ -7435,32 +7435,8 @@ Yargs.hideBin = processArgv.hideBin;
|
|
|
7435
7435
|
Yargs.Parser = Parser2;
|
|
7436
7436
|
var yargs_default = Yargs;
|
|
7437
7437
|
|
|
7438
|
-
// src/
|
|
7439
|
-
var
|
|
7440
|
-
async function loadGitHubConfig({
|
|
7441
|
-
absolutePathToConfig
|
|
7442
|
-
}) {
|
|
7443
|
-
const rawContents = await (0, import_promises2.readFile)(absolutePathToConfig, "utf8");
|
|
7444
|
-
return JSON.parse(rawContents);
|
|
7445
|
-
}
|
|
7446
|
-
|
|
7447
|
-
// src/configuration/loadReadmeConfig.ts
|
|
7448
|
-
var import_promises3 = require("fs/promises");
|
|
7449
|
-
async function loadReadmeConfig({
|
|
7450
|
-
absolutePathToConfig
|
|
7451
|
-
}) {
|
|
7452
|
-
const rawContents = await (0, import_promises3.readFile)(absolutePathToConfig, "utf8");
|
|
7453
|
-
return JSON.parse(rawContents);
|
|
7454
|
-
}
|
|
7455
|
-
|
|
7456
|
-
// src/configuration/loadReferenceConfig.ts
|
|
7457
|
-
var import_promises4 = require("fs/promises");
|
|
7458
|
-
async function loadReferenceConfig({
|
|
7459
|
-
absolutePathToConfig
|
|
7460
|
-
}) {
|
|
7461
|
-
const rawContents = await (0, import_promises4.readFile)(absolutePathToConfig, "utf8");
|
|
7462
|
-
return JSON.parse(rawContents);
|
|
7463
|
-
}
|
|
7438
|
+
// src/api/generate-readme.ts
|
|
7439
|
+
var import_node_stream = require("stream");
|
|
7464
7440
|
|
|
7465
7441
|
// ../../node_modules/.pnpm/simple-git@3.24.0/node_modules/simple-git/dist/esm/index.js
|
|
7466
7442
|
var import_file_exists = __toESM(require_dist(), 1);
|
|
@@ -11969,7 +11945,7 @@ var esm_default2 = gitInstanceFactory;
|
|
|
11969
11945
|
var import_tmp_promise = __toESM(require_tmp_promise(), 1);
|
|
11970
11946
|
|
|
11971
11947
|
// ../commons/github/dist/ClonedRepository.js
|
|
11972
|
-
var
|
|
11948
|
+
var import_promises2 = require("fs/promises");
|
|
11973
11949
|
var import_path6 = __toESM(require("path"), 1);
|
|
11974
11950
|
|
|
11975
11951
|
// ../commons/github/dist/constants.js
|
|
@@ -12046,18 +12022,18 @@ var ClonedRepository = class {
|
|
|
12046
12022
|
}
|
|
12047
12023
|
async overwriteLocalContents(sourceDirectoryPath) {
|
|
12048
12024
|
const [sourceContents, destContents] = await Promise.all([
|
|
12049
|
-
(0,
|
|
12050
|
-
(0,
|
|
12025
|
+
(0, import_promises2.readdir)(sourceDirectoryPath),
|
|
12026
|
+
(0, import_promises2.readdir)(this.clonePath)
|
|
12051
12027
|
]);
|
|
12052
12028
|
await Promise.all(destContents.filter((content) => !DEFAULT_IGNORED_FILES.includes(content)).map(async (content) => {
|
|
12053
|
-
await (0,
|
|
12029
|
+
await (0, import_promises2.rm)((0, import_path6.resolve)(this.clonePath, content), {
|
|
12054
12030
|
recursive: true,
|
|
12055
12031
|
force: true
|
|
12056
12032
|
});
|
|
12057
12033
|
}));
|
|
12058
12034
|
await Promise.all(sourceContents.filter((content) => !DEFAULT_IGNORED_FILES.includes(content)).map(async (content) => {
|
|
12059
12035
|
const path4 = (0, import_path6.resolve)(sourceDirectoryPath, content);
|
|
12060
|
-
await (0,
|
|
12036
|
+
await (0, import_promises2.cp)(path4, (0, import_path6.resolve)(this.clonePath, content), { recursive: true });
|
|
12061
12037
|
}));
|
|
12062
12038
|
}
|
|
12063
12039
|
async readFile({ relativeFilePath }) {
|
|
@@ -12065,12 +12041,12 @@ var ClonedRepository = class {
|
|
|
12065
12041
|
if (!await doesPathExist2(absoluteFilePath)) {
|
|
12066
12042
|
return void 0;
|
|
12067
12043
|
}
|
|
12068
|
-
return await (0,
|
|
12044
|
+
return await (0, import_promises2.readFile)(absoluteFilePath, "utf-8");
|
|
12069
12045
|
}
|
|
12070
12046
|
};
|
|
12071
12047
|
async function doesPathExist2(filepath) {
|
|
12072
12048
|
try {
|
|
12073
|
-
await (0,
|
|
12049
|
+
await (0, import_promises2.lstat)(filepath);
|
|
12074
12050
|
return true;
|
|
12075
12051
|
} catch {
|
|
12076
12052
|
return false;
|
|
@@ -12133,115 +12109,6 @@ async function cloneRepository({ githubRepository, installationToken }) {
|
|
|
12133
12109
|
});
|
|
12134
12110
|
}
|
|
12135
12111
|
|
|
12136
|
-
// src/github/GitHub.ts
|
|
12137
|
-
var import_rest = require("@octokit/rest");
|
|
12138
|
-
var GitHub = class {
|
|
12139
|
-
githubConfig;
|
|
12140
|
-
constructor({
|
|
12141
|
-
githubConfig
|
|
12142
|
-
}) {
|
|
12143
|
-
this.githubConfig = githubConfig;
|
|
12144
|
-
}
|
|
12145
|
-
async push() {
|
|
12146
|
-
try {
|
|
12147
|
-
const wd = cwd();
|
|
12148
|
-
const sourceDirectory = resolve(wd, this.githubConfig.sourceDirectory);
|
|
12149
|
-
const repository = await cloneRepository({
|
|
12150
|
-
githubRepository: this.githubConfig.uri,
|
|
12151
|
-
installationToken: this.githubConfig.token
|
|
12152
|
-
});
|
|
12153
|
-
const branch = this.githubConfig.branch ?? await repository.getDefaultBranch();
|
|
12154
|
-
await repository.checkout(branch);
|
|
12155
|
-
await repository.pull(branch);
|
|
12156
|
-
const fernIgnoreFiles = await this.getFernignoreFiles(repository);
|
|
12157
|
-
await repository.overwriteLocalContents(sourceDirectory);
|
|
12158
|
-
await repository.add(".");
|
|
12159
|
-
await this.restoreFiles(repository, fernIgnoreFiles);
|
|
12160
|
-
await repository.commit("SDK Generation");
|
|
12161
|
-
await repository.push();
|
|
12162
|
-
} catch (error) {
|
|
12163
|
-
console.error("Error during GitHub push:", error);
|
|
12164
|
-
throw error;
|
|
12165
|
-
}
|
|
12166
|
-
}
|
|
12167
|
-
async pr() {
|
|
12168
|
-
try {
|
|
12169
|
-
const wd = cwd();
|
|
12170
|
-
const sourceDirectory = resolve(wd, this.githubConfig.sourceDirectory);
|
|
12171
|
-
const repository = await cloneRepository({
|
|
12172
|
-
githubRepository: this.githubConfig.uri,
|
|
12173
|
-
installationToken: this.githubConfig.token
|
|
12174
|
-
});
|
|
12175
|
-
const baseBranch = this.githubConfig.branch ?? await repository.getDefaultBranch();
|
|
12176
|
-
const now = /* @__PURE__ */ new Date();
|
|
12177
|
-
const formattedDate = now.toISOString().replace("T", "_").replace(/:/g, "-").replace(/\..+/, "");
|
|
12178
|
-
const prBranch = `fern-bot/${formattedDate}`;
|
|
12179
|
-
await repository.checkout(baseBranch);
|
|
12180
|
-
await repository.pull(baseBranch);
|
|
12181
|
-
await repository.checkout(prBranch);
|
|
12182
|
-
const fernIgnoreFiles = await this.getFernignoreFiles(repository);
|
|
12183
|
-
await repository.overwriteLocalContents(sourceDirectory);
|
|
12184
|
-
await repository.add(".");
|
|
12185
|
-
await this.restoreFiles(repository, fernIgnoreFiles);
|
|
12186
|
-
await repository.commit("SDK Generation");
|
|
12187
|
-
await repository.push();
|
|
12188
|
-
const octokit = new import_rest.Octokit({
|
|
12189
|
-
auth: this.githubConfig.token
|
|
12190
|
-
});
|
|
12191
|
-
const [owner, repo] = this.githubConfig.uri.split("/");
|
|
12192
|
-
if (!owner || !repo) {
|
|
12193
|
-
throw new Error(`Invalid repository URI: ${this.githubConfig.uri}`);
|
|
12194
|
-
}
|
|
12195
|
-
const head = `${owner}:${prBranch}`;
|
|
12196
|
-
try {
|
|
12197
|
-
await octokit.pulls.create({
|
|
12198
|
-
owner,
|
|
12199
|
-
repo,
|
|
12200
|
-
title: "SDK Generation",
|
|
12201
|
-
body: "Automated SDK generation by Fern",
|
|
12202
|
-
head,
|
|
12203
|
-
base: baseBranch,
|
|
12204
|
-
draft: false
|
|
12205
|
-
});
|
|
12206
|
-
} catch (e) {
|
|
12207
|
-
if (typeof e?.message === "string" && e.message.includes("A pull request already exists for")) {
|
|
12208
|
-
console.error(`A pull request already exists for ${head}`);
|
|
12209
|
-
} else {
|
|
12210
|
-
throw e;
|
|
12211
|
-
}
|
|
12212
|
-
}
|
|
12213
|
-
} catch (error) {
|
|
12214
|
-
console.error("Error during GitHub PR flow:", error);
|
|
12215
|
-
throw error;
|
|
12216
|
-
}
|
|
12217
|
-
}
|
|
12218
|
-
async release() {
|
|
12219
|
-
console.log("TODO: Implement release");
|
|
12220
|
-
}
|
|
12221
|
-
async getFernignoreFiles(repository) {
|
|
12222
|
-
const fernignore = await repository.getFernignore();
|
|
12223
|
-
if (fernignore === void 0) {
|
|
12224
|
-
return [];
|
|
12225
|
-
}
|
|
12226
|
-
const fernignoreLines = fernignore.split("\n");
|
|
12227
|
-
const fernignoreFiles = [];
|
|
12228
|
-
for (const line of fernignoreLines) {
|
|
12229
|
-
const trimmedLine = line.trim();
|
|
12230
|
-
if (!trimmedLine.startsWith("#") && trimmedLine.length > 0 && await repository.fileExists({ relativeFilePath: trimmedLine })) {
|
|
12231
|
-
fernignoreFiles.push(trimmedLine);
|
|
12232
|
-
}
|
|
12233
|
-
}
|
|
12234
|
-
return fernignoreFiles;
|
|
12235
|
-
}
|
|
12236
|
-
async restoreFiles(repository, files) {
|
|
12237
|
-
if (files.length === 0) {
|
|
12238
|
-
return;
|
|
12239
|
-
}
|
|
12240
|
-
await repository.restoreFiles({ files, staged: true });
|
|
12241
|
-
await repository.restoreFiles({ files });
|
|
12242
|
-
}
|
|
12243
|
-
};
|
|
12244
|
-
|
|
12245
12112
|
// src/readme/ReadmeGenerator.ts
|
|
12246
12113
|
var import_compat = require("es-toolkit/compat");
|
|
12247
12114
|
var import_string = require("es-toolkit/string");
|
|
@@ -13491,6 +13358,22 @@ function sectionNameToID(sectionName) {
|
|
|
13491
13358
|
).toUpperCase();
|
|
13492
13359
|
}
|
|
13493
13360
|
|
|
13361
|
+
// src/api/generate-readme.ts
|
|
13362
|
+
async function generateReadmeToStream(params) {
|
|
13363
|
+
const { originalReadmeContent, readmeConfig, outputStream } = params;
|
|
13364
|
+
const generator = new ReadmeGenerator({
|
|
13365
|
+
readmeParser: new ReadmeParser(),
|
|
13366
|
+
readmeConfig,
|
|
13367
|
+
originalReadme: originalReadmeContent
|
|
13368
|
+
});
|
|
13369
|
+
await generator.generateReadme({
|
|
13370
|
+
output: outputStream
|
|
13371
|
+
});
|
|
13372
|
+
}
|
|
13373
|
+
|
|
13374
|
+
// src/api/generate-reference.ts
|
|
13375
|
+
var import_node_stream2 = require("stream");
|
|
13376
|
+
|
|
13494
13377
|
// src/reference/ReferenceGenerator.ts
|
|
13495
13378
|
var ReferenceGenerator = class {
|
|
13496
13379
|
referenceConfig;
|
|
@@ -13595,6 +13478,183 @@ ${content}
|
|
|
13595
13478
|
}
|
|
13596
13479
|
};
|
|
13597
13480
|
|
|
13481
|
+
// src/api/generate-reference.ts
|
|
13482
|
+
async function generateReferenceToStream(params) {
|
|
13483
|
+
const { referenceConfig, outputStream } = params;
|
|
13484
|
+
const generator = new ReferenceGenerator({
|
|
13485
|
+
referenceConfig
|
|
13486
|
+
});
|
|
13487
|
+
await generator.generate({
|
|
13488
|
+
output: outputStream
|
|
13489
|
+
});
|
|
13490
|
+
}
|
|
13491
|
+
|
|
13492
|
+
// src/github/GitHub.ts
|
|
13493
|
+
var import_rest = require("@octokit/rest");
|
|
13494
|
+
var GitHub = class {
|
|
13495
|
+
githubConfig;
|
|
13496
|
+
constructor({
|
|
13497
|
+
githubConfig
|
|
13498
|
+
}) {
|
|
13499
|
+
this.githubConfig = githubConfig;
|
|
13500
|
+
}
|
|
13501
|
+
async push() {
|
|
13502
|
+
try {
|
|
13503
|
+
const wd = cwd();
|
|
13504
|
+
const sourceDirectory = resolve(wd, this.githubConfig.sourceDirectory);
|
|
13505
|
+
const repository = await cloneRepository({
|
|
13506
|
+
githubRepository: this.githubConfig.uri,
|
|
13507
|
+
installationToken: this.githubConfig.token
|
|
13508
|
+
});
|
|
13509
|
+
const branch = this.githubConfig.branch ?? await repository.getDefaultBranch();
|
|
13510
|
+
await repository.checkout(branch);
|
|
13511
|
+
await repository.pull(branch);
|
|
13512
|
+
const fernIgnoreFiles = await this.getFernignoreFiles(repository);
|
|
13513
|
+
await repository.overwriteLocalContents(sourceDirectory);
|
|
13514
|
+
await repository.add(".");
|
|
13515
|
+
await this.restoreFiles(repository, fernIgnoreFiles);
|
|
13516
|
+
await repository.commit("SDK Generation");
|
|
13517
|
+
await repository.push();
|
|
13518
|
+
} catch (error) {
|
|
13519
|
+
console.error("Error during GitHub push:", error);
|
|
13520
|
+
throw error;
|
|
13521
|
+
}
|
|
13522
|
+
}
|
|
13523
|
+
async pr() {
|
|
13524
|
+
try {
|
|
13525
|
+
const wd = cwd();
|
|
13526
|
+
const sourceDirectory = resolve(wd, this.githubConfig.sourceDirectory);
|
|
13527
|
+
const repository = await cloneRepository({
|
|
13528
|
+
githubRepository: this.githubConfig.uri,
|
|
13529
|
+
installationToken: this.githubConfig.token
|
|
13530
|
+
});
|
|
13531
|
+
const baseBranch = this.githubConfig.branch ?? await repository.getDefaultBranch();
|
|
13532
|
+
const now = /* @__PURE__ */ new Date();
|
|
13533
|
+
const formattedDate = now.toISOString().replace("T", "_").replace(/:/g, "-").replace(/\..+/, "");
|
|
13534
|
+
const prBranch = `fern-bot/${formattedDate}`;
|
|
13535
|
+
await repository.checkout(baseBranch);
|
|
13536
|
+
await repository.pull(baseBranch);
|
|
13537
|
+
await repository.checkout(prBranch);
|
|
13538
|
+
const fernIgnoreFiles = await this.getFernignoreFiles(repository);
|
|
13539
|
+
await repository.overwriteLocalContents(sourceDirectory);
|
|
13540
|
+
await repository.add(".");
|
|
13541
|
+
await this.restoreFiles(repository, fernIgnoreFiles);
|
|
13542
|
+
await repository.commit("SDK Generation");
|
|
13543
|
+
await repository.push();
|
|
13544
|
+
const octokit = new import_rest.Octokit({
|
|
13545
|
+
auth: this.githubConfig.token
|
|
13546
|
+
});
|
|
13547
|
+
const [owner, repo] = this.githubConfig.uri.split("/");
|
|
13548
|
+
if (!owner || !repo) {
|
|
13549
|
+
throw new Error(`Invalid repository URI: ${this.githubConfig.uri}`);
|
|
13550
|
+
}
|
|
13551
|
+
const head = `${owner}:${prBranch}`;
|
|
13552
|
+
try {
|
|
13553
|
+
await octokit.pulls.create({
|
|
13554
|
+
owner,
|
|
13555
|
+
repo,
|
|
13556
|
+
title: "SDK Generation",
|
|
13557
|
+
body: "Automated SDK generation by Fern",
|
|
13558
|
+
head,
|
|
13559
|
+
base: baseBranch,
|
|
13560
|
+
draft: false
|
|
13561
|
+
});
|
|
13562
|
+
} catch (e) {
|
|
13563
|
+
if (typeof e?.message === "string" && e.message.includes("A pull request already exists for")) {
|
|
13564
|
+
console.error(`A pull request already exists for ${head}`);
|
|
13565
|
+
} else {
|
|
13566
|
+
throw e;
|
|
13567
|
+
}
|
|
13568
|
+
}
|
|
13569
|
+
} catch (error) {
|
|
13570
|
+
console.error("Error during GitHub PR flow:", error);
|
|
13571
|
+
throw error;
|
|
13572
|
+
}
|
|
13573
|
+
}
|
|
13574
|
+
async release() {
|
|
13575
|
+
console.log("TODO: Implement release");
|
|
13576
|
+
}
|
|
13577
|
+
async getFernignoreFiles(repository) {
|
|
13578
|
+
const fernignore = await repository.getFernignore();
|
|
13579
|
+
if (fernignore === void 0) {
|
|
13580
|
+
return [];
|
|
13581
|
+
}
|
|
13582
|
+
const fernignoreLines = fernignore.split("\n");
|
|
13583
|
+
const fernignoreFiles = [];
|
|
13584
|
+
for (const line of fernignoreLines) {
|
|
13585
|
+
const trimmedLine = line.trim();
|
|
13586
|
+
if (!trimmedLine.startsWith("#") && trimmedLine.length > 0 && await repository.fileExists({ relativeFilePath: trimmedLine })) {
|
|
13587
|
+
fernignoreFiles.push(trimmedLine);
|
|
13588
|
+
}
|
|
13589
|
+
}
|
|
13590
|
+
return fernignoreFiles;
|
|
13591
|
+
}
|
|
13592
|
+
async restoreFiles(repository, files) {
|
|
13593
|
+
if (files.length === 0) {
|
|
13594
|
+
return;
|
|
13595
|
+
}
|
|
13596
|
+
await repository.restoreFiles({ files, staged: true });
|
|
13597
|
+
await repository.restoreFiles({ files });
|
|
13598
|
+
}
|
|
13599
|
+
};
|
|
13600
|
+
|
|
13601
|
+
// src/api/github-pr.ts
|
|
13602
|
+
async function githubPr(params) {
|
|
13603
|
+
const { githubConfig } = params;
|
|
13604
|
+
const github = new GitHub({ githubConfig });
|
|
13605
|
+
await github.pr();
|
|
13606
|
+
}
|
|
13607
|
+
|
|
13608
|
+
// src/api/github-push.ts
|
|
13609
|
+
async function githubPush(params) {
|
|
13610
|
+
const { githubConfig } = params;
|
|
13611
|
+
const github = new GitHub({ githubConfig });
|
|
13612
|
+
await github.push();
|
|
13613
|
+
}
|
|
13614
|
+
|
|
13615
|
+
// src/api/github-release.ts
|
|
13616
|
+
async function githubRelease(params) {
|
|
13617
|
+
const { githubConfig } = params;
|
|
13618
|
+
const github = new GitHub({ githubConfig });
|
|
13619
|
+
await github.release();
|
|
13620
|
+
}
|
|
13621
|
+
|
|
13622
|
+
// src/configuration/loadGitHubConfig.ts
|
|
13623
|
+
var import_promises3 = require("fs/promises");
|
|
13624
|
+
async function loadGitHubConfig({
|
|
13625
|
+
absolutePathToConfig
|
|
13626
|
+
}) {
|
|
13627
|
+
const rawContents = await (0, import_promises3.readFile)(absolutePathToConfig, "utf8");
|
|
13628
|
+
return JSON.parse(rawContents);
|
|
13629
|
+
}
|
|
13630
|
+
|
|
13631
|
+
// src/configuration/loadMetadataConfig.ts
|
|
13632
|
+
var import_promises4 = require("fs/promises");
|
|
13633
|
+
async function loadMetadataConfig({
|
|
13634
|
+
absolutePathToConfig
|
|
13635
|
+
}) {
|
|
13636
|
+
const rawContents = await (0, import_promises4.readFile)(absolutePathToConfig, "utf8");
|
|
13637
|
+
return JSON.parse(rawContents);
|
|
13638
|
+
}
|
|
13639
|
+
|
|
13640
|
+
// src/configuration/loadReadmeConfig.ts
|
|
13641
|
+
var import_promises5 = require("fs/promises");
|
|
13642
|
+
async function loadReadmeConfig({
|
|
13643
|
+
absolutePathToConfig
|
|
13644
|
+
}) {
|
|
13645
|
+
const rawContents = await (0, import_promises5.readFile)(absolutePathToConfig, "utf8");
|
|
13646
|
+
return JSON.parse(rawContents);
|
|
13647
|
+
}
|
|
13648
|
+
|
|
13649
|
+
// src/configuration/loadReferenceConfig.ts
|
|
13650
|
+
var import_promises6 = require("fs/promises");
|
|
13651
|
+
async function loadReferenceConfig({
|
|
13652
|
+
absolutePathToConfig
|
|
13653
|
+
}) {
|
|
13654
|
+
const rawContents = await (0, import_promises6.readFile)(absolutePathToConfig, "utf8");
|
|
13655
|
+
return JSON.parse(rawContents);
|
|
13656
|
+
}
|
|
13657
|
+
|
|
13598
13658
|
// src/cli.ts
|
|
13599
13659
|
void yargs_default(hideBin(process.argv)).scriptName(process.env.CLI_NAME ?? "generator-cli").strict().command(
|
|
13600
13660
|
"generate readme",
|
|
@@ -13618,13 +13678,11 @@ void yargs_default(hideBin(process.argv)).scriptName(process.env.CLI_NAME ?? "ge
|
|
|
13618
13678
|
const readmeConfig = await loadReadmeConfig({
|
|
13619
13679
|
absolutePathToConfig: resolve(wd, argv.config)
|
|
13620
13680
|
});
|
|
13621
|
-
const
|
|
13622
|
-
|
|
13681
|
+
const originalReadmeContent = argv.originalReadme != null ? await (0, import_promises7.readFile)(argv.originalReadme, "utf8") : void 0;
|
|
13682
|
+
await generateReadmeToStream({
|
|
13683
|
+
originalReadmeContent,
|
|
13623
13684
|
readmeConfig,
|
|
13624
|
-
|
|
13625
|
-
});
|
|
13626
|
-
await generator.generateReadme({
|
|
13627
|
-
output: await createWriteStream(argv.output)
|
|
13685
|
+
outputStream: await createWriteStream(argv.output)
|
|
13628
13686
|
});
|
|
13629
13687
|
process.exit(0);
|
|
13630
13688
|
}
|
|
@@ -13647,12 +13705,35 @@ void yargs_default(hideBin(process.argv)).scriptName(process.env.CLI_NAME ?? "ge
|
|
|
13647
13705
|
const referenceConfig = await loadReferenceConfig({
|
|
13648
13706
|
absolutePathToConfig: resolve(wd, argv.config)
|
|
13649
13707
|
});
|
|
13650
|
-
|
|
13651
|
-
referenceConfig
|
|
13708
|
+
await generateReferenceToStream({
|
|
13709
|
+
referenceConfig,
|
|
13710
|
+
outputStream: await createWriteStream(argv.output)
|
|
13652
13711
|
});
|
|
13653
|
-
|
|
13654
|
-
|
|
13712
|
+
process.exit(0);
|
|
13713
|
+
}
|
|
13714
|
+
).command(
|
|
13715
|
+
"write-metadata",
|
|
13716
|
+
"Write metadata to the output directory using the provided configuration file.",
|
|
13717
|
+
(argv) => argv.option("config", {
|
|
13718
|
+
string: true,
|
|
13719
|
+
required: true
|
|
13720
|
+
}).option("output", {
|
|
13721
|
+
string: true,
|
|
13722
|
+
required: false
|
|
13723
|
+
}),
|
|
13724
|
+
async (argv) => {
|
|
13725
|
+
if (argv.config == null) {
|
|
13726
|
+
process.stderr.write("missing required arguments; please specify the --config flag\n");
|
|
13727
|
+
process.exit(1);
|
|
13728
|
+
}
|
|
13729
|
+
const wd = cwd();
|
|
13730
|
+
const metadata = await loadMetadataConfig({
|
|
13731
|
+
absolutePathToConfig: resolve(wd, argv.config)
|
|
13655
13732
|
});
|
|
13733
|
+
const outputPath = argv.output != null ? resolve(wd, argv.output) : resolve(wd, ".fern/metadata.json");
|
|
13734
|
+
const formattedMetadata = JSON.stringify(metadata, null, 2);
|
|
13735
|
+
await (0, import_promises7.mkdir)(import_path7.default.dirname(outputPath), { recursive: true });
|
|
13736
|
+
await (0, import_promises7.writeFile)(outputPath, formattedMetadata, "utf8");
|
|
13656
13737
|
process.exit(0);
|
|
13657
13738
|
}
|
|
13658
13739
|
).command("github", "GitHub operations", (yargs) => {
|
|
@@ -13675,10 +13756,7 @@ void yargs_default(hideBin(process.argv)).scriptName(process.env.CLI_NAME ?? "ge
|
|
|
13675
13756
|
const githubConfig = await loadGitHubConfig({
|
|
13676
13757
|
absolutePathToConfig: resolve(wd, argv.config)
|
|
13677
13758
|
});
|
|
13678
|
-
|
|
13679
|
-
githubConfig
|
|
13680
|
-
});
|
|
13681
|
-
await github.push();
|
|
13759
|
+
await githubPush({ githubConfig });
|
|
13682
13760
|
process.exit(0);
|
|
13683
13761
|
}
|
|
13684
13762
|
).command(
|
|
@@ -13700,10 +13778,7 @@ void yargs_default(hideBin(process.argv)).scriptName(process.env.CLI_NAME ?? "ge
|
|
|
13700
13778
|
const githubConfig = await loadGitHubConfig({
|
|
13701
13779
|
absolutePathToConfig: resolve(wd, argv.config)
|
|
13702
13780
|
});
|
|
13703
|
-
|
|
13704
|
-
githubConfig
|
|
13705
|
-
});
|
|
13706
|
-
await github.pr();
|
|
13781
|
+
await githubPr({ githubConfig });
|
|
13707
13782
|
process.stderr.write(`Creating PR on GitHub with config: ${resolve(wd, argv.config)}
|
|
13708
13783
|
`);
|
|
13709
13784
|
process.exit(0);
|
|
@@ -13725,10 +13800,7 @@ void yargs_default(hideBin(process.argv)).scriptName(process.env.CLI_NAME ?? "ge
|
|
|
13725
13800
|
const githubConfig = await loadGitHubConfig({
|
|
13726
13801
|
absolutePathToConfig: resolve(wd2, argv.config)
|
|
13727
13802
|
});
|
|
13728
|
-
|
|
13729
|
-
githubConfig
|
|
13730
|
-
});
|
|
13731
|
-
await github.release();
|
|
13803
|
+
await githubRelease({ githubConfig });
|
|
13732
13804
|
process.exit(1);
|
|
13733
13805
|
}
|
|
13734
13806
|
const wd = cwd();
|
|
@@ -13743,7 +13815,7 @@ async function createWriteStream(outputPath) {
|
|
|
13743
13815
|
}
|
|
13744
13816
|
async function createWriteStreamFromFile(filepath) {
|
|
13745
13817
|
if (!await doesPathExist(filepath)) {
|
|
13746
|
-
await (0,
|
|
13818
|
+
await (0, import_promises7.mkdir)(import_path7.default.dirname(filepath), { recursive: true });
|
|
13747
13819
|
}
|
|
13748
13820
|
return import_fs6.default.createWriteStream(filepath);
|
|
13749
13821
|
}
|
package/package.json
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fern-api/generator-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/fern-api/fern-platform"
|
|
7
7
|
},
|
|
8
8
|
"type": "module",
|
|
9
|
-
"main": "dist/
|
|
9
|
+
"main": "dist/api.cjs",
|
|
10
10
|
"source": "src/index.ts",
|
|
11
|
+
"types": "dist/api.d.cts",
|
|
11
12
|
"bin": {
|
|
12
13
|
"generator-cli": "dist/cli.cjs"
|
|
13
14
|
},
|
|
14
15
|
"files": ["dist"],
|
|
15
16
|
"scripts": {
|
|
16
17
|
"clean": "rm -rf ./dist && tsc --build --clean",
|
|
17
|
-
"compile": "
|
|
18
|
+
"compile": "pnpm compile:api && pnpm compile:cli",
|
|
19
|
+
"compile:api": "tsup ./src/api.ts --format cjs --dts",
|
|
20
|
+
"compile:cli": "tsup ./src/cli.ts --format cjs && echo '#!/usr/bin/env node' | cat - dist/cli.cjs > dist/tmp && mv dist/tmp dist/cli.cjs",
|
|
18
21
|
"depcheck": "depcheck",
|
|
19
22
|
"format": "prettier --write --ignore-unknown \"**\"",
|
|
20
23
|
"format:check": "prettier --check --ignore-unknown \"**\"",
|