@langri-sha/projen-prettier 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/CHANGELOG.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "@langri-sha/projen-prettier",
3
+ "entries": [
4
+ {
5
+ "date": "Mon, 27 May 2024 03:22:54 GMT",
6
+ "version": "0.1.0",
7
+ "tag": "@langri-sha/projen-prettier_v0.1.0",
8
+ "comments": {
9
+ "minor": [
10
+ {
11
+ "author": "filip.dupanovic@gmail.com",
12
+ "package": "@langri-sha/projen-prettier",
13
+ "commit": "46f1a1df1a3c4e63293027640c917472274d082e",
14
+ "comment": "feat(prettier): Add support for configuring Prettier"
15
+ }
16
+ ]
17
+ }
18
+ }
19
+ ]
20
+ }
package/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ # Change Log - @langri-sha/projen-prettier
2
+
3
+ This log was last generated on Mon, 27 May 2024 03:22:54 GMT and should not be manually modified.
4
+
5
+ <!-- Start content -->
6
+
7
+ ## 0.1.0
8
+
9
+ Mon, 27 May 2024 03:22:54 GMT
10
+
11
+ ### Minor changes
12
+
13
+ - feat(prettier): Add support for configuring Prettier (filip.dupanovic@gmail.com)
package/lib/index.d.ts ADDED
@@ -0,0 +1,33 @@
1
+ import type { Config } from 'prettier';
2
+ import { FileBase, IResolver, IgnoreFile, Project } from 'projen';
3
+ /**
4
+ * Options for configuring Prettier.
5
+ */
6
+ export interface PrettierOptions {
7
+ /**
8
+ * Name of the Prettier config module.
9
+ *
10
+ * @default 'prettier.config.js'
11
+ */
12
+ filename?: string;
13
+ /**
14
+ * Name of the Prettier configuration package to extend from.
15
+ */
16
+ extends?: string;
17
+ /**
18
+ * Ignore patterns.
19
+ */
20
+ ignorePatterns?: string[];
21
+ /**
22
+ * Prettier configuration object.
23
+ */
24
+ config?: Config;
25
+ }
26
+ export declare class Prettier extends FileBase {
27
+ #private;
28
+ ignore: IgnoreFile;
29
+ config: Config;
30
+ constructor(project: Project, options?: PrettierOptions);
31
+ protected synthesizeContent(_: IResolver): string | undefined;
32
+ }
33
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACtC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AAEjE;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IAEjB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAEhB;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,EAAE,CAAA;IAEzB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,qBAAa,QAAS,SAAQ,QAAQ;;IAEpC,MAAM,EAAE,UAAU,CAAA;IAClB,MAAM,EAAE,MAAM,CAAA;gBAEF,OAAO,EAAE,OAAO,EAAE,OAAO,GAAE,eAAoB;cAexC,iBAAiB,CAAC,CAAC,EAAE,SAAS,GAAG,MAAM,GAAG,SAAS;CAevE"}
package/lib/index.js ADDED
@@ -0,0 +1,44 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _Prettier_extends;
13
+ import serialize from 'serialize-javascript';
14
+ import { FileBase, IgnoreFile } from 'projen';
15
+ export class Prettier extends FileBase {
16
+ constructor(project, options = {}) {
17
+ const filename = options.filename ?? 'prettier.config.js';
18
+ super(project, filename, {
19
+ readonly: true,
20
+ marker: true,
21
+ });
22
+ _Prettier_extends.set(this, void 0);
23
+ __classPrivateFieldSet(this, _Prettier_extends, options.extends, "f");
24
+ this.config = options.config ?? {};
25
+ this.ignore = new IgnoreFile(project, '.prettierignore', {
26
+ ignorePatterns: options.ignorePatterns,
27
+ });
28
+ }
29
+ synthesizeContent(_) {
30
+ const config = {
31
+ ...this.config,
32
+ };
33
+ const serialized = serialize(config);
34
+ return `${__classPrivateFieldGet(this, _Prettier_extends, "f") ? `import defaults from '${__classPrivateFieldGet(this, _Prettier_extends, "f")}'\n\n` : ''}/** @type {import("prettier").Config} */
35
+ const config = {
36
+ ${__classPrivateFieldGet(this, _Prettier_extends, "f") ? `...defaults,` : ''}
37
+ ${serialized.slice(1)}
38
+
39
+ export default config
40
+ `;
41
+ }
42
+ }
43
+ _Prettier_extends = new WeakMap();
44
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,SAAS,MAAM,sBAAsB,CAAA;AAE5C,OAAO,EAAE,QAAQ,EAAa,UAAU,EAAW,MAAM,QAAQ,CAAA;AA6BjE,MAAM,OAAO,QAAS,SAAQ,QAAQ;IAKpC,YAAY,OAAgB,EAAE,UAA2B,EAAE;QACzD,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,oBAAoB,CAAA;QAEzD,KAAK,CAAC,OAAO,EAAE,QAAQ,EAAE;YACvB,QAAQ,EAAE,IAAI;YACd,MAAM,EAAE,IAAI;SACb,CAAC,CAAA;QAVJ,oCAAiB;QAYf,uBAAA,IAAI,qBAAY,OAAO,CAAC,OAAO,MAAA,CAAA;QAC/B,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,EAAE,CAAA;QAClC,IAAI,CAAC,MAAM,GAAG,IAAI,UAAU,CAAC,OAAO,EAAE,iBAAiB,EAAE;YACvD,cAAc,EAAE,OAAO,CAAC,cAAc;SACvC,CAAC,CAAA;IACJ,CAAC;IAEkB,iBAAiB,CAAC,CAAY;QAC/C,MAAM,MAAM,GAAW;YACrB,GAAG,IAAI,CAAC,MAAM;SACf,CAAA;QAED,MAAM,UAAU,GAAG,SAAS,CAAC,MAAM,CAAC,CAAA;QAEpC,OAAO,GAAG,uBAAA,IAAI,yBAAS,CAAC,CAAC,CAAC,yBAAyB,uBAAA,IAAI,yBAAS,OAAO,CAAC,CAAC,CAAC,EAAE;;QAExE,uBAAA,IAAI,yBAAS,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE;QACnC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;;;KAGtB,CAAA;IACH,CAAC;CACF"}
package/license ADDED
@@ -0,0 +1,10 @@
1
+
2
+ MIT License
3
+
4
+ Copyright (c) 2024 Filip Dupanović <filip.dupanovic@gmail.com> (https://langri-sha.com)
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7
+
8
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9
+
10
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@langri-sha/projen-prettier",
3
+ "version": "0.1.0",
4
+ "license": "MIT",
5
+ "author": {
6
+ "name": "Filip Dupanović",
7
+ "email": "filip.dupanovic@gmail.com",
8
+ "url": "https://langri-sha.com",
9
+ "organization": false
10
+ },
11
+ "type": "module",
12
+ "main": "lib/index.js",
13
+ "scripts": {
14
+ "prepublishOnly": "rm -rf lib; tsc --project tsconfig.build.json"
15
+ },
16
+ "dependencies": {
17
+ "serialize-javascript": "6.0.2"
18
+ },
19
+ "devDependencies": {
20
+ "@langri-sha/jest-test": "0.7.1",
21
+ "@langri-sha/tsconfig": "0.9.0",
22
+ "@types/serialize-javascript": "5.0.4",
23
+ "prettier": "3.0.0",
24
+ "projen": "0.81.15"
25
+ },
26
+ "peerDependencies": {
27
+ "prettier": "^3.0.0",
28
+ "projen": "^0.81.15"
29
+ },
30
+ "engines": {
31
+ "node": ">= 20.12.0"
32
+ },
33
+ "publishConfig": {
34
+ "access": "public"
35
+ },
36
+ "//": "~~ Generated by projen. To modify, edit .projenrc.mts and run \"npx projen\".",
37
+ "types": "lib/index.d.ts"
38
+ }
package/readme ADDED
@@ -0,0 +1,32 @@
1
+ # @langri-sha/projen-prettier
2
+
3
+ A [projen] component for configuring [Prettier].
4
+
5
+ ## Usage
6
+
7
+ Install dependencies:
8
+
9
+ ```sh
10
+ npm install -D projen @langri-sha/projen-prettier
11
+ ```
12
+
13
+ Then, create an `Prettier` component for your project:
14
+
15
+ ```js
16
+ import { Project } from 'projen'
17
+ import { License } from '@langri-sha/projen-prettier'
18
+
19
+ const project = new Project({
20
+ name: 'my-project',
21
+ })
22
+
23
+ new Prettier(project, {
24
+ filename: '',
25
+ spdx: 'MIT',
26
+ copyrightHolder: 'John Smith <john.smith@example.com>',
27
+ copyrightYear: '2000',
28
+ })
29
+ ```
30
+
31
+ [prettier]: https://prettier.io/docs/en/
32
+ [projen]: https://projen.io/
package/src/index.ts ADDED
@@ -0,0 +1,67 @@
1
+ import serialize from 'serialize-javascript'
2
+ import type { Config } from 'prettier'
3
+ import { FileBase, IResolver, IgnoreFile, Project } from 'projen'
4
+
5
+ /**
6
+ * Options for configuring Prettier.
7
+ */
8
+ export interface PrettierOptions {
9
+ /**
10
+ * Name of the Prettier config module.
11
+ *
12
+ * @default 'prettier.config.js'
13
+ */
14
+ filename?: string
15
+
16
+ /**
17
+ * Name of the Prettier configuration package to extend from.
18
+ */
19
+ extends?: string
20
+
21
+ /**
22
+ * Ignore patterns.
23
+ */
24
+ ignorePatterns?: string[]
25
+
26
+ /**
27
+ * Prettier configuration object.
28
+ */
29
+ config?: Config
30
+ }
31
+
32
+ export class Prettier extends FileBase {
33
+ #extends?: string
34
+ ignore: IgnoreFile
35
+ config: Config
36
+
37
+ constructor(project: Project, options: PrettierOptions = {}) {
38
+ const filename = options.filename ?? 'prettier.config.js'
39
+
40
+ super(project, filename, {
41
+ readonly: true,
42
+ marker: true,
43
+ })
44
+
45
+ this.#extends = options.extends
46
+ this.config = options.config ?? {}
47
+ this.ignore = new IgnoreFile(project, '.prettierignore', {
48
+ ignorePatterns: options.ignorePatterns,
49
+ })
50
+ }
51
+
52
+ protected override synthesizeContent(_: IResolver): string | undefined {
53
+ const config: Config = {
54
+ ...this.config,
55
+ }
56
+
57
+ const serialized = serialize(config)
58
+
59
+ return `${this.#extends ? `import defaults from '${this.#extends}'\n\n` : ''}/** @type {import("prettier").Config} */
60
+ const config = {
61
+ ${this.#extends ? `...defaults,` : ''}
62
+ ${serialized.slice(1)}
63
+
64
+ export default config
65
+ `
66
+ }
67
+ }