diff --git a/.eslintrc.js b/.eslintrc.js index 8770a01..8bd11d7 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,16 +1,14 @@ module.exports = { "env": { - "node": true, - "es6": true + "node": true, + "es6": true }, - "extends": "eslint:recommended", - "globals": { - "Atomics": "readonly", - "SharedArrayBuffer": "readonly" - }, - "parserOptions": { + "extends": [ + "plugin:prettier/recommended" + ], + "parserOptions": { "ecmaVersion": 2018 }, - "rules": { - } + "rules": { + } }; diff --git a/build.js b/build.js index 2766996..0ca7abe 100644 --- a/build.js +++ b/build.js @@ -18,17 +18,17 @@ * THE SOFTWARE. */ +"use strict"; + const { ArgumentParser } = require("argparse"); const fs = require("fs"); const { spawn, exec } = require("child_process"); const { resolve } = require("path"); function execAndPrint(fun, args) { - const child = spawn(fun, args.split(" "), {stdio: "inherit"}); - return new Promise((resolve) => { - child.on("close", () => { - resolve(); - }); + const child = spawn(fun, args.split(" "), { stdio: "inherit" }); + return new Promise((res) => { + child.on("close", res); }); } @@ -37,10 +37,13 @@ function create() { } function build(path) { - const workingDir = resolve("."); - const uid = process.getuid(); - const gid = process.getgid(); - return execAndPrint("docker", `run -t -v ${path}:/js -v ${workingDir}:/code --rm --user ${uid}:${gid} qjs-sandbox`); + const workingDir = resolve("."), + uid = process.getuid(), + gid = process.getgid(); + return execAndPrint( + "docker", + `run -t -v ${path}:/js -v ${workingDir}:/code --rm --user ${uid}:${gid} qjs-sandbox` + ); } function compile(path) { @@ -51,7 +54,10 @@ function compile(path) { return; } exec("docker images qjs-sandbox", (err, stdout) => { - const output = stdout.split("\n").map(line => line.trim()).filter(line => !!line); + const output = stdout + .split("\n") + .map((line) => line.trim()) + .filter((line) => Boolean(line)); if (output.length === 1) { create().then(() => { build(path); @@ -60,42 +66,33 @@ function compile(path) { build(path); } }); - }) + }); } const parser = new ArgumentParser({ - description: "Build sandbox" + description: "Build sandbox", }); -parser.add_argument( - "-C", - "--create", - { - help: "Create the docker image", - action: "store_true", - } -); -parser.add_argument( - "-c", - "--compile", - { - help: "Compile the sandbox and output a js file", - action: "store_true", - } -); -parser.add_argument( - "-o", - "--output", - { - help: "Output directory", - default: ".", - } -); +parser.add_argument("-C", "--create", { + help: "Create the docker image", + action: "store_true", +}); +parser.add_argument("-c", "--compile", { + help: "Compile the sandbox and output a js file", + action: "store_true", +}); +parser.add_argument("-o", "--output", { + help: "Output directory", + default: ".", +}); -const args = parser.parse_args() +const args = parser.parse_args(); if (args.create) { - create() -} -if (args.compile) { - compile(args.output) + create().then(() => { + if (args.compile) { + compile(args.output); + } + }); +} else if (args.compile) { + compile(args.output); } diff --git a/package-lock.json b/package-lock.json index 5c712d0..18536d5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -313,6 +313,24 @@ "v8-compile-cache": "^2.0.3" } }, + "eslint-config-prettier": { + "version": "6.15.0", + "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-6.15.0.tgz", + "integrity": "sha512-a1+kOYLR8wMGustcgAjdydMsQ2A/2ipRPwRKUmfYaSxc9ZPcrku080Ctl6zrZzZNs/U82MjSv+qKREkoq3bJaw==", + "dev": true, + "requires": { + "get-stdin": "^6.0.0" + } + }, + "eslint-plugin-prettier": { + "version": "3.1.4", + "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-3.1.4.tgz", + "integrity": "sha512-jZDa8z76klRqo+TdGDTFJSavwbnWK2ZpqGKNZ+VvweMW516pDUMmQ2koXvxEE4JhzNvTv+radye/bWGBmA6jmg==", + "dev": true, + "requires": { + "prettier-linter-helpers": "^1.0.0" + } + }, "eslint-scope": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz", @@ -423,6 +441,12 @@ "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", "dev": true }, + "fast-diff": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/fast-diff/-/fast-diff-1.2.0.tgz", + "integrity": "sha512-xJuoT5+L99XlZ8twedaRf6Ax2TgQVxvgZOYoPKqZufmJib0tL2tegPBOZb1pVNgIhlqDlA0eO0c3wBvQcmzx4w==", + "dev": true + }, "fast-json-stable-stringify": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", @@ -473,6 +497,12 @@ "integrity": "sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=", "dev": true }, + "get-stdin": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-6.0.0.tgz", + "integrity": "sha512-jp4tHawyV7+fkkSKyvjuLZswblUtz+SQKzSWnBbii16BuZksJlU1wuBYXY75r+duh/llF1ur6oNwi+2ZzjKZ7g==", + "dev": true + }, "glob": { "version": "7.1.6", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz", @@ -717,6 +747,21 @@ "integrity": "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==", "dev": true }, + "prettier": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.2.0.tgz", + "integrity": "sha512-yYerpkvseM4iKD/BXLYUkQV5aKt4tQPqaGW6EsZjzyu0r7sVZZNPJW4Y8MyKmicp6t42XUPcBVA+H6sB3gqndw==", + "dev": true + }, + "prettier-linter-helpers": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz", + "integrity": "sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w==", + "dev": true, + "requires": { + "fast-diff": "^1.1.2" + } + }, "progress": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/progress/-/progress-2.0.3.tgz", diff --git a/package.json b/package.json index 529f40f..bb55f55 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,10 @@ "version": "2.0.0", "devDependencies": { "argparse": "^2.0.1", - "eslint": "^7.13.0" + "eslint": "^7.13.0", + "eslint-plugin-prettier": "^3.1.4", + "prettier": "^2.1.2", + "eslint-config-prettier": "^6.15.0" }, "license": "Apache-2.0" }