liquidsoap-prettier 1.5.2 → 1.5.4
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/README.md +23 -0
- package/dist/liquidsoap.cjs +55508 -10192
- package/dist/web.mjs +1 -1
- package/package.json +7 -2
- package/scripts/download-parser.js +46 -0
- package/src/cli.js +23 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "liquidsoap-prettier",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.4",
|
|
4
4
|
"description": "Liquidsoap language prettier CLI and plugin",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"scripts": {
|
|
11
11
|
"build:web": "webpack --config webpack.web.cjs",
|
|
12
12
|
"release": "dune build && npm run build:web && npm publish",
|
|
13
|
+
"dev:prepare": "node ./scripts/download-parser.js",
|
|
13
14
|
"liquidsoap-prettier": "node ./src/cli.js"
|
|
14
15
|
},
|
|
15
16
|
"prettier": {
|
|
@@ -23,9 +24,13 @@
|
|
|
23
24
|
"bluebird": "^3.7.2",
|
|
24
25
|
"glob": "^10.3.10",
|
|
25
26
|
"minimist": "^1.2.8",
|
|
26
|
-
"prettier": "^3.0.0"
|
|
27
|
+
"prettier": "^3.0.0",
|
|
28
|
+
"tmp": "^0.2.3"
|
|
27
29
|
},
|
|
28
30
|
"devDependencies": {
|
|
31
|
+
"gunzip-maybe": "^1.4.2",
|
|
32
|
+
"nodejs-file-downloader": "^4.13.0",
|
|
33
|
+
"tar-fs": "^3.0.6",
|
|
29
34
|
"webpack": "^5.89.0",
|
|
30
35
|
"webpack-cli": "^5.1.4"
|
|
31
36
|
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { Downloader } from "nodejs-file-downloader";
|
|
4
|
+
import { exec } from "node:child_process";
|
|
5
|
+
import { finished } from "node:stream/promises";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import fs from "node:fs";
|
|
8
|
+
import tmp from "tmp";
|
|
9
|
+
import gunzip from "gunzip-maybe";
|
|
10
|
+
import tar from "tar-fs";
|
|
11
|
+
|
|
12
|
+
tmp.setGracefulCleanup();
|
|
13
|
+
|
|
14
|
+
const archive = "archive.tgz";
|
|
15
|
+
|
|
16
|
+
const liqFile = "dist/liquidsoap.cjs";
|
|
17
|
+
|
|
18
|
+
const destFile = path.resolve(path.dirname(process.argv[1]), "..", liqFile);
|
|
19
|
+
|
|
20
|
+
if (fs.existsSync(destFile)) {
|
|
21
|
+
console.log("Liquidsoap parser file present!");
|
|
22
|
+
process.exit();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
exec("npm view liquidsoap-prettier dist.tarball", async (_, stdout) => {
|
|
26
|
+
console.log("Downloading liquidsoap parser file..");
|
|
27
|
+
|
|
28
|
+
const { name: tmpdir } = tmp.dirSync();
|
|
29
|
+
|
|
30
|
+
const downloader = new Downloader({
|
|
31
|
+
url: stdout.trim(),
|
|
32
|
+
directory: tmpdir,
|
|
33
|
+
fileName: archive,
|
|
34
|
+
cloneFiles: false,
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
await downloader.download();
|
|
38
|
+
|
|
39
|
+
await finished(
|
|
40
|
+
fs
|
|
41
|
+
.createReadStream(path.join(tmpdir, archive))
|
|
42
|
+
.pipe(gunzip())
|
|
43
|
+
.pipe(tar.extract(tmpdir)),
|
|
44
|
+
);
|
|
45
|
+
await fs.promises.rename(path.join(tmpdir, "package", liqFile), destFile);
|
|
46
|
+
});
|
package/src/cli.js
CHANGED
|
@@ -13,7 +13,11 @@ const run = async () => {
|
|
|
13
13
|
_: [filename],
|
|
14
14
|
write,
|
|
15
15
|
w,
|
|
16
|
-
|
|
16
|
+
check,
|
|
17
|
+
c,
|
|
18
|
+
} = parseArgs(process.argv.slice(2), {
|
|
19
|
+
boolean: ["w", "write", "c", "check"],
|
|
20
|
+
});
|
|
17
21
|
|
|
18
22
|
if (!filename) {
|
|
19
23
|
console.error("No filename passed!");
|
|
@@ -24,7 +28,7 @@ const run = async () => {
|
|
|
24
28
|
|
|
25
29
|
if (files.length > 1 && !w && !write) {
|
|
26
30
|
console.error(
|
|
27
|
-
"-w
|
|
31
|
+
"-w|--write must be used when formatting more than one file at a time!",
|
|
28
32
|
);
|
|
29
33
|
process.exit(1);
|
|
30
34
|
}
|
|
@@ -45,16 +49,24 @@ const run = async () => {
|
|
|
45
49
|
const code = "" + fs.readFileSync(file);
|
|
46
50
|
|
|
47
51
|
try {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
console.log(`Writting formatted ${file}`);
|
|
55
|
-
fs.writeFileSync(file, formattedCode);
|
|
52
|
+
if (check || c) {
|
|
53
|
+
const isFormatted = await prettier.check(code, {
|
|
54
|
+
parser: "liquidsoap",
|
|
55
|
+
plugins: [prettierPluginLiquidsoap],
|
|
56
|
+
});
|
|
57
|
+
exitCode = isFormatted ? 0 : 2;
|
|
56
58
|
} else {
|
|
57
|
-
|
|
59
|
+
const formattedCode = await prettier.format(code, {
|
|
60
|
+
parser: "liquidsoap",
|
|
61
|
+
plugins: [prettierPluginLiquidsoap],
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
if (write || w) {
|
|
65
|
+
console.log(`Writting formatted ${file}`);
|
|
66
|
+
fs.writeFileSync(file, formattedCode);
|
|
67
|
+
} else {
|
|
68
|
+
process.stdout.write(formattedCode);
|
|
69
|
+
}
|
|
58
70
|
}
|
|
59
71
|
} catch (err) {
|
|
60
72
|
console.error(`Error while processing file ${file}: ${err}`);
|