@fern-api/generator-cli 0.0.41 → 0.1.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/cli.cjs +107 -14
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -5148,14 +5148,14 @@ var require_common = __commonJS({
|
|
|
5148
5148
|
}
|
|
5149
5149
|
}
|
|
5150
5150
|
}
|
|
5151
|
-
function matchesTemplate(search,
|
|
5151
|
+
function matchesTemplate(search, template2) {
|
|
5152
5152
|
let searchIndex = 0;
|
|
5153
5153
|
let templateIndex = 0;
|
|
5154
5154
|
let starIndex = -1;
|
|
5155
5155
|
let matchIndex = 0;
|
|
5156
5156
|
while (searchIndex < search.length) {
|
|
5157
|
-
if (templateIndex <
|
|
5158
|
-
if (
|
|
5157
|
+
if (templateIndex < template2.length && (template2[templateIndex] === search[searchIndex] || template2[templateIndex] === "*")) {
|
|
5158
|
+
if (template2[templateIndex] === "*") {
|
|
5159
5159
|
starIndex = templateIndex;
|
|
5160
5160
|
matchIndex = searchIndex;
|
|
5161
5161
|
templateIndex++;
|
|
@@ -5171,10 +5171,10 @@ var require_common = __commonJS({
|
|
|
5171
5171
|
return false;
|
|
5172
5172
|
}
|
|
5173
5173
|
}
|
|
5174
|
-
while (templateIndex <
|
|
5174
|
+
while (templateIndex < template2.length && template2[templateIndex] === "*") {
|
|
5175
5175
|
templateIndex++;
|
|
5176
5176
|
}
|
|
5177
|
-
return templateIndex ===
|
|
5177
|
+
return templateIndex === template2.length;
|
|
5178
5178
|
}
|
|
5179
5179
|
function disable() {
|
|
5180
5180
|
const namespaces = [
|
|
@@ -12833,6 +12833,7 @@ var GitHub = class {
|
|
|
12833
12833
|
};
|
|
12834
12834
|
|
|
12835
12835
|
// src/readme/ReadmeGenerator.ts
|
|
12836
|
+
var import_compat = require("es-toolkit/compat");
|
|
12836
12837
|
var import_string = require("es-toolkit/string");
|
|
12837
12838
|
|
|
12838
12839
|
// src/configuration/generated/api/index.ts
|
|
@@ -12865,6 +12866,7 @@ var StructuredFeatureId = {
|
|
|
12865
12866
|
Streaming: "STREAMING",
|
|
12866
12867
|
Timeouts: "TIMEOUTS",
|
|
12867
12868
|
CustomClient: "CUSTOM_CLIENT",
|
|
12869
|
+
Contributing: "CONTRIBUTING",
|
|
12868
12870
|
_visit: (value, visitor) => {
|
|
12869
12871
|
switch (value) {
|
|
12870
12872
|
case StructuredFeatureId.Authentication:
|
|
@@ -12885,6 +12887,8 @@ var StructuredFeatureId = {
|
|
|
12885
12887
|
return visitor.timeouts();
|
|
12886
12888
|
case StructuredFeatureId.CustomClient:
|
|
12887
12889
|
return visitor.customClient();
|
|
12890
|
+
case StructuredFeatureId.Contributing:
|
|
12891
|
+
return visitor.contributing();
|
|
12888
12892
|
default:
|
|
12889
12893
|
return visitor._other();
|
|
12890
12894
|
}
|
|
@@ -13213,9 +13217,9 @@ var BlockMerger = class {
|
|
|
13213
13217
|
merged.addBlock(originalBlock);
|
|
13214
13218
|
}
|
|
13215
13219
|
}
|
|
13216
|
-
for (const updatedBlock of this.updated) {
|
|
13220
|
+
for (const [index, updatedBlock] of this.updated.reverse().entries()) {
|
|
13217
13221
|
if (!processedUpdated.has(updatedBlock.id)) {
|
|
13218
|
-
merged.
|
|
13222
|
+
merged.insertBlock(updatedBlock, this.updated[index - 1]?.id);
|
|
13219
13223
|
}
|
|
13220
13224
|
}
|
|
13221
13225
|
return merged.getBlocks();
|
|
@@ -13238,6 +13242,33 @@ var BlockList = class {
|
|
|
13238
13242
|
this.ids.add(block.id);
|
|
13239
13243
|
this.blocks.push(block);
|
|
13240
13244
|
}
|
|
13245
|
+
// private addBlockToFront(block: Block): void {
|
|
13246
|
+
// if (this.hasBlock(block.id)) {
|
|
13247
|
+
// throw new Error(`block with id "${block.id}" already exists`);
|
|
13248
|
+
// }
|
|
13249
|
+
// this.ids.add(block.id);
|
|
13250
|
+
// this.blocks.unshift(block);
|
|
13251
|
+
// }
|
|
13252
|
+
insertBlock(block, precedingBlockId) {
|
|
13253
|
+
if (this.hasBlock(block.id)) {
|
|
13254
|
+
throw new Error(`block with id "${block.id}" already exists`);
|
|
13255
|
+
}
|
|
13256
|
+
if (precedingBlockId === void 0) {
|
|
13257
|
+
this.addBlock(block);
|
|
13258
|
+
return;
|
|
13259
|
+
}
|
|
13260
|
+
if (!this.hasBlock(precedingBlockId)) {
|
|
13261
|
+
throw new Error(
|
|
13262
|
+
`preceding block with id "${precedingBlockId}" does not exist`
|
|
13263
|
+
);
|
|
13264
|
+
}
|
|
13265
|
+
this.ids.add(block.id);
|
|
13266
|
+
this.blocks.splice(
|
|
13267
|
+
this.blocks.findIndex((b) => b.id === precedingBlockId),
|
|
13268
|
+
0,
|
|
13269
|
+
block
|
|
13270
|
+
);
|
|
13271
|
+
}
|
|
13241
13272
|
hasBlock(id) {
|
|
13242
13273
|
return this.ids.has(id);
|
|
13243
13274
|
}
|
|
@@ -13259,6 +13290,7 @@ var ReadmeGenerator = class {
|
|
|
13259
13290
|
originalReadme;
|
|
13260
13291
|
languageTitle;
|
|
13261
13292
|
organizationPascalCase;
|
|
13293
|
+
apiName;
|
|
13262
13294
|
constructor({
|
|
13263
13295
|
readmeParser,
|
|
13264
13296
|
readmeConfig,
|
|
@@ -13269,6 +13301,7 @@ var ReadmeGenerator = class {
|
|
|
13269
13301
|
this.originalReadme = originalReadme;
|
|
13270
13302
|
this.languageTitle = languageToTitle(this.readmeConfig.language);
|
|
13271
13303
|
this.organizationPascalCase = pascalCase(this.readmeConfig.organization);
|
|
13304
|
+
this.apiName = this.readmeConfig.apiName ?? this.organizationPascalCase;
|
|
13272
13305
|
}
|
|
13273
13306
|
async generateReadme({
|
|
13274
13307
|
output
|
|
@@ -13312,6 +13345,19 @@ var ReadmeGenerator = class {
|
|
|
13312
13345
|
})
|
|
13313
13346
|
);
|
|
13314
13347
|
}
|
|
13348
|
+
if (this.readmeConfig.customSections != null) {
|
|
13349
|
+
const templateOptions = this.getCustomSectionTemplateOptions();
|
|
13350
|
+
for (const customSection of this.readmeConfig.customSections.filter(
|
|
13351
|
+
(section) => section.language.toLowerCase() === this.readmeConfig.language.type.toLowerCase()
|
|
13352
|
+
)) {
|
|
13353
|
+
blocks.push(
|
|
13354
|
+
await this.generateCustomSection({
|
|
13355
|
+
customSection,
|
|
13356
|
+
templateOptions
|
|
13357
|
+
})
|
|
13358
|
+
);
|
|
13359
|
+
}
|
|
13360
|
+
}
|
|
13315
13361
|
const coreFeatures = this.readmeConfig.features?.filter((feat) => !this.isAdvanced(feat)) ?? [];
|
|
13316
13362
|
const advancedFeatures = this.readmeConfig.features?.filter((feat) => this.isAdvanced(feat)) ?? [];
|
|
13317
13363
|
for (const feature of coreFeatures) {
|
|
@@ -13331,9 +13377,14 @@ var ReadmeGenerator = class {
|
|
|
13331
13377
|
if (advancedFeatureBlock != null) {
|
|
13332
13378
|
blocks.push(advancedFeatureBlock);
|
|
13333
13379
|
}
|
|
13334
|
-
|
|
13380
|
+
if (!this.featureDisabled(api_exports.StructuredFeatureId.Contributing)) {
|
|
13381
|
+
blocks.push(this.generateContributing());
|
|
13382
|
+
}
|
|
13335
13383
|
return blocks;
|
|
13336
13384
|
}
|
|
13385
|
+
featureDisabled(featureId) {
|
|
13386
|
+
return this.readmeConfig.disabledFeatures?.includes(featureId) ?? false;
|
|
13387
|
+
}
|
|
13337
13388
|
isAdvanced(feat) {
|
|
13338
13389
|
if (this.ADVANCED_FEATURES.has(feat.id)) {
|
|
13339
13390
|
return true;
|
|
@@ -13427,9 +13478,7 @@ var ReadmeGenerator = class {
|
|
|
13427
13478
|
}
|
|
13428
13479
|
}
|
|
13429
13480
|
async writeHeader({ writer }) {
|
|
13430
|
-
await writer.writeLine(
|
|
13431
|
-
`# ${this.organizationPascalCase} ${this.languageTitle} Library`
|
|
13432
|
-
);
|
|
13481
|
+
await writer.writeLine(`# ${this.apiName} ${this.languageTitle} Library`);
|
|
13433
13482
|
await writer.writeLine();
|
|
13434
13483
|
if (this.readmeConfig.bannerLink != null) {
|
|
13435
13484
|
await this.writeBanner({
|
|
@@ -13437,7 +13486,9 @@ var ReadmeGenerator = class {
|
|
|
13437
13486
|
bannerLink: this.readmeConfig.bannerLink
|
|
13438
13487
|
});
|
|
13439
13488
|
}
|
|
13440
|
-
|
|
13489
|
+
if (!this.isWhiteLabel()) {
|
|
13490
|
+
await this.writeFernShield({ writer });
|
|
13491
|
+
}
|
|
13441
13492
|
if (this.readmeConfig.language != null) {
|
|
13442
13493
|
await this.writeShield({
|
|
13443
13494
|
writer,
|
|
@@ -13447,6 +13498,9 @@ var ReadmeGenerator = class {
|
|
|
13447
13498
|
await writer.writeLine();
|
|
13448
13499
|
await this.writeIntro({ writer });
|
|
13449
13500
|
}
|
|
13501
|
+
isWhiteLabel() {
|
|
13502
|
+
return this.readmeConfig.whiteLabel ?? false;
|
|
13503
|
+
}
|
|
13450
13504
|
async writeBanner({
|
|
13451
13505
|
writer,
|
|
13452
13506
|
bannerLink
|
|
@@ -13462,7 +13516,7 @@ var ReadmeGenerator = class {
|
|
|
13462
13516
|
}
|
|
13463
13517
|
async writeIntro({ writer }) {
|
|
13464
13518
|
await writer.writeLine(
|
|
13465
|
-
this.readmeConfig.introduction != null ? this.readmeConfig.introduction : `The ${this.
|
|
13519
|
+
this.readmeConfig.introduction != null ? this.readmeConfig.introduction : `The ${this.apiName} ${this.languageTitle} library provides convenient access to the ${this.apiName} APIs from ${this.languageTitle}.`
|
|
13466
13520
|
);
|
|
13467
13521
|
await writer.writeLine();
|
|
13468
13522
|
}
|
|
@@ -13496,6 +13550,42 @@ var ReadmeGenerator = class {
|
|
|
13496
13550
|
content: writer.toString()
|
|
13497
13551
|
});
|
|
13498
13552
|
}
|
|
13553
|
+
getCustomSectionTemplateOptions() {
|
|
13554
|
+
let options = {
|
|
13555
|
+
apiName: this.apiName
|
|
13556
|
+
};
|
|
13557
|
+
if (this.readmeConfig.language.publishInfo != null) {
|
|
13558
|
+
options = {
|
|
13559
|
+
...options,
|
|
13560
|
+
...this.readmeConfig.language.publishInfo
|
|
13561
|
+
};
|
|
13562
|
+
}
|
|
13563
|
+
return options;
|
|
13564
|
+
}
|
|
13565
|
+
applyTemplateOptions(content, options) {
|
|
13566
|
+
try {
|
|
13567
|
+
return (0, import_compat.template)(content, { interpolate: /{{([^}]+)}}/g })(options);
|
|
13568
|
+
} catch (error) {
|
|
13569
|
+
console.error(`[templates] ${JSON.stringify(error)}`);
|
|
13570
|
+
return content;
|
|
13571
|
+
}
|
|
13572
|
+
}
|
|
13573
|
+
async generateCustomSection({
|
|
13574
|
+
customSection,
|
|
13575
|
+
templateOptions
|
|
13576
|
+
}) {
|
|
13577
|
+
const writer = new StringWriter();
|
|
13578
|
+
await writer.writeLine(`## ${customSection.name}`);
|
|
13579
|
+
await writer.writeLine();
|
|
13580
|
+
await writer.writeLine(
|
|
13581
|
+
this.applyTemplateOptions(customSection.content, templateOptions)
|
|
13582
|
+
);
|
|
13583
|
+
await writer.writeLine();
|
|
13584
|
+
return new Block({
|
|
13585
|
+
id: toScreamingSnakeCase(customSection.name),
|
|
13586
|
+
content: writer.toString()
|
|
13587
|
+
});
|
|
13588
|
+
}
|
|
13499
13589
|
async generateRequirements({
|
|
13500
13590
|
requirements
|
|
13501
13591
|
}) {
|
|
@@ -13938,7 +14028,7 @@ On the other hand, contributions to the README are always very welcome!
|
|
|
13938
14028
|
shouldSkipFeature({
|
|
13939
14029
|
feature
|
|
13940
14030
|
}) {
|
|
13941
|
-
return !feature.snippetsAreOptional && (feature.snippets == null || feature.snippets.length === 0);
|
|
14031
|
+
return this.featureDisabled(feature.id) || !feature.snippetsAreOptional && (feature.snippets == null || feature.snippets.length === 0);
|
|
13942
14032
|
}
|
|
13943
14033
|
shouldGenerateFeatures({
|
|
13944
14034
|
features
|
|
@@ -13982,6 +14072,9 @@ function getMajorVersion(version) {
|
|
|
13982
14072
|
function assertNever(x) {
|
|
13983
14073
|
throw new Error(`unexpected value: ${JSON.stringify(x)}`);
|
|
13984
14074
|
}
|
|
14075
|
+
function toScreamingSnakeCase(s) {
|
|
14076
|
+
return s.toUpperCase().replace(/ /g, "_");
|
|
14077
|
+
}
|
|
13985
14078
|
|
|
13986
14079
|
// src/readme/ReadmeParser.ts
|
|
13987
14080
|
var import_string2 = require("es-toolkit/string");
|