Skip to content

Commit

Permalink
chore: disable yaml folding (projen#1546)
Browse files Browse the repository at this point in the history
Upgrade the bundled `yaml` dependency to `yaml@2` and disable line folding by default (can be changed through `YamlFile.lineWidth`.

---
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
  • Loading branch information
Chriscbr authored Jan 20, 2022
1 parent 7b5d5fc commit e7d7a5c
Show file tree
Hide file tree
Showing 27 changed files with 364 additions and 1,127 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/auto-approve.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 6 additions & 12 deletions .github/workflows/build.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 10 additions & 23 deletions .github/workflows/release.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 4 additions & 16 deletions .github/workflows/stale.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 4 additions & 13 deletions .github/workflows/upgrade-main.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .projen/deps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .projenrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const project = new cdk.JsiiProject({

bundledDeps: [
"conventional-changelog-config-spec",
"yaml",
"yaml@next",
"fs-extra",
"yargs",
"case",
Expand Down
10 changes: 10 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -2888,8 +2888,17 @@ new YamlFile(project: Project, filePath: string, options: YamlFileOptions)
* **marker** (<code>boolean</code>) Adds the projen marker to the file. __*Default*__: true
* **obj** (<code>any</code>) The object that will be serialized. __*Default*__: {} an empty object (use `file.obj` to mutate).
* **omitEmpty** (<code>boolean</code>) Omits empty objects and arrays. __*Default*__: false
* **lineWidth** (<code>number</code>) Maximum line width (set to 0 to disable folding). __*Default*__: 0



### Properties


Name | Type | Description
-----|------|-------------
**lineWidth**🔹 | <code>number</code> | Maximum line width (set to 0 to disable folding).

### Methods


Expand Down Expand Up @@ -11005,6 +11014,7 @@ Name | Type | Description
**committed**?🔹 | <code>boolean</code> | Indicates whether this file should be committed to git or ignored.<br/>__*Default*__: true
**editGitignore**?🔹 | <code>boolean</code> | Update the project's .gitignore file.<br/>__*Default*__: true
**executable**?🔹 | <code>boolean</code> | Whether the generated file should be marked as executable.<br/>__*Default*__: false
**lineWidth**?🔹 | <code>number</code> | Maximum line width (set to 0 to disable folding).<br/>__*Default*__: 0
**marker**?🔹 | <code>boolean</code> | Adds the projen marker to the file.<br/>__*Default*__: true
**obj**?🔹 | <code>any</code> | The object that will be serialized.<br/>__*Default*__: {} an empty object (use `file.obj` to mutate).
**omitEmpty**?🔹 | <code>boolean</code> | Omits empty objects and arrays.<br/>__*Default*__: false
Expand Down
2 changes: 1 addition & 1 deletion package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 18 additions & 2 deletions src/yaml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,27 @@ import { Project } from "./project";
/**
* Options for `JsonFile`.
*/
export interface YamlFileOptions extends ObjectFileOptions {}
export interface YamlFileOptions extends ObjectFileOptions {
/**
* Maximum line width (set to 0 to disable folding).
*
* @default - 0
*/
readonly lineWidth?: number;
}

/**
* Represents a YAML file.
*/
export class YamlFile extends ObjectFile {
/**
* Maximum line width (set to 0 to disable folding).
*/
public lineWidth: number;

constructor(project: Project, filePath: string, options: YamlFileOptions) {
super(project, filePath, options);
this.lineWidth = options.lineWidth ?? 0;
}

protected synthesizeContent(resolver: IResolver): string | undefined {
Expand All @@ -25,7 +38,10 @@ export class YamlFile extends ObjectFile {
return [
...(this.marker ? [`# ${YamlFile.PROJEN_MARKER}`] : []),
"",
YAML.stringify(JSON.parse(json), { indent: 2 }),
YAML.stringify(JSON.parse(json), {
indent: 2,
lineWidth: this.lineWidth,
}),
].join("\n");
}
}
Loading

0 comments on commit e7d7a5c

Please sign in to comment.