liquidsoap-prettier 1.4.5

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/dune-project ADDED
@@ -0,0 +1,2 @@
1
+ (lang dune 3.11)
2
+ (name prettier_plugin_liquidsoap)
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "liquidsoap-prettier",
3
+ "version": "1.4.5",
4
+ "description": "Liquidsoap language prettier CLI and plugin",
5
+ "type": "module",
6
+ "main": "src/index.js",
7
+ "bin": {
8
+ "liquidsoap-prettier": "src/cli.js"
9
+ },
10
+ "scripts": {
11
+ "build:web": "webpack --config webpack.web.cjs",
12
+ "release": "dune build && npm run build:web && npm publish",
13
+ "liquidsoap-prettier": "node ./src/cli.js"
14
+ },
15
+ "prettier": {
16
+ "plugins": [
17
+ "./src/index.js"
18
+ ]
19
+ },
20
+ "author": "",
21
+ "license": "ISC",
22
+ "dependencies": {
23
+ "bluebird": "^3.7.2",
24
+ "glob": "^10.3.10",
25
+ "minimist": "^1.2.8",
26
+ "prettier": "^3.0.0"
27
+ },
28
+ "devDependencies": {
29
+ "webpack": "^5.89.0",
30
+ "webpack-cli": "^5.1.4"
31
+ }
32
+ }
package/src/cli.js ADDED
@@ -0,0 +1,72 @@
1
+ #!/usr/bin/env node
2
+
3
+ import parseArgs from "minimist";
4
+ import prettier from "prettier";
5
+ import fs from "node:fs";
6
+ import { glob } from "glob";
7
+ import BluebirdPromise from "bluebird";
8
+ import * as prettierPluginLiquidsoap from "./index.js";
9
+
10
+ const run = async () => {
11
+ try {
12
+ const {
13
+ _: [filename],
14
+ write,
15
+ w,
16
+ } = parseArgs(process.argv.slice(2), { boolean: ["w", "write"] });
17
+
18
+ if (!filename) {
19
+ console.error("No filename passed!");
20
+ process.exit(1);
21
+ }
22
+
23
+ const files = await glob(filename);
24
+
25
+ if (files.length > 1 && !w && !write) {
26
+ console.error(
27
+ "-w or --write must be used when formatting more than one file at a time!",
28
+ );
29
+ process.exit(1);
30
+ }
31
+
32
+ if (files.length === 0) {
33
+ console.error("No file passed!");
34
+ process.exit(1);
35
+ }
36
+
37
+ let exitCode = 0;
38
+
39
+ await BluebirdPromise.each(files, async (file) => {
40
+ if (!fs.existsSync(file)) {
41
+ console.error(`File ${file} does not exist!`);
42
+ exitCode = 1;
43
+ }
44
+
45
+ const code = "" + fs.readFileSync(file);
46
+
47
+ try {
48
+ const formattedCode = await prettier.format(code, {
49
+ parser: "liquidsoap",
50
+ plugins: [prettierPluginLiquidsoap],
51
+ });
52
+
53
+ if (write || w) {
54
+ console.log(`Writting formatted ${file}`);
55
+ fs.writeFileSync(file, formattedCode);
56
+ } else {
57
+ process.stdout.write(formattedCode);
58
+ }
59
+ } catch (err) {
60
+ console.error(`Error while processing file ${file}: ${err}`);
61
+ exitCode = 1;
62
+ }
63
+ });
64
+
65
+ process.exit(exitCode);
66
+ } catch (err) {
67
+ console.error(`Error while running liquidsoap-prettier: ${err}`);
68
+ process.exit(1);
69
+ }
70
+ };
71
+
72
+ run();
package/src/dune ADDED
@@ -0,0 +1,8 @@
1
+ (executable
2
+ (name liquidsoap_js)
3
+ (optional)
4
+ (modes js)
5
+ (modules regexp_js liquidsoap_js)
6
+ (preprocess
7
+ (pps js_of_ocaml-ppx))
8
+ (libraries js_of_ocaml liquidsoap-lang liquidsoap-lang.tooling))