Fix formatting of build.js
This commit is contained in:
Родитель
c11e92c8e6
Коммит
f9e34b8679
18
.eslintrc.js
18
.eslintrc.js
|
@ -1,16 +1,14 @@
|
||||||
module.exports = {
|
module.exports = {
|
||||||
"env": {
|
"env": {
|
||||||
"node": true,
|
"node": true,
|
||||||
"es6": true
|
"es6": true
|
||||||
},
|
},
|
||||||
"extends": "eslint:recommended",
|
"extends": [
|
||||||
"globals": {
|
"plugin:prettier/recommended"
|
||||||
"Atomics": "readonly",
|
],
|
||||||
"SharedArrayBuffer": "readonly"
|
"parserOptions": {
|
||||||
},
|
|
||||||
"parserOptions": {
|
|
||||||
"ecmaVersion": 2018
|
"ecmaVersion": 2018
|
||||||
},
|
},
|
||||||
"rules": {
|
"rules": {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
79
build.js
79
build.js
|
@ -18,17 +18,17 @@
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
const { ArgumentParser } = require("argparse");
|
const { ArgumentParser } = require("argparse");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const { spawn, exec } = require("child_process");
|
const { spawn, exec } = require("child_process");
|
||||||
const { resolve } = require("path");
|
const { resolve } = require("path");
|
||||||
|
|
||||||
function execAndPrint(fun, args) {
|
function execAndPrint(fun, args) {
|
||||||
const child = spawn(fun, args.split(" "), {stdio: "inherit"});
|
const child = spawn(fun, args.split(" "), { stdio: "inherit" });
|
||||||
return new Promise((resolve) => {
|
return new Promise((res) => {
|
||||||
child.on("close", () => {
|
child.on("close", res);
|
||||||
resolve();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,10 +37,13 @@ function create() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function build(path) {
|
function build(path) {
|
||||||
const workingDir = resolve(".");
|
const workingDir = resolve("."),
|
||||||
const uid = process.getuid();
|
uid = process.getuid(),
|
||||||
const gid = process.getgid();
|
gid = process.getgid();
|
||||||
return execAndPrint("docker", `run -t -v ${path}:/js -v ${workingDir}:/code --rm --user ${uid}:${gid} qjs-sandbox`);
|
return execAndPrint(
|
||||||
|
"docker",
|
||||||
|
`run -t -v ${path}:/js -v ${workingDir}:/code --rm --user ${uid}:${gid} qjs-sandbox`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function compile(path) {
|
function compile(path) {
|
||||||
|
@ -51,7 +54,10 @@ function compile(path) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
exec("docker images qjs-sandbox", (err, stdout) => {
|
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) {
|
if (output.length === 1) {
|
||||||
create().then(() => {
|
create().then(() => {
|
||||||
build(path);
|
build(path);
|
||||||
|
@ -60,42 +66,33 @@ function compile(path) {
|
||||||
build(path);
|
build(path);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const parser = new ArgumentParser({
|
const parser = new ArgumentParser({
|
||||||
description: "Build sandbox"
|
description: "Build sandbox",
|
||||||
});
|
});
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument("-C", "--create", {
|
||||||
"-C",
|
help: "Create the docker image",
|
||||||
"--create",
|
action: "store_true",
|
||||||
{
|
});
|
||||||
help: "Create the docker image",
|
parser.add_argument("-c", "--compile", {
|
||||||
action: "store_true",
|
help: "Compile the sandbox and output a js file",
|
||||||
}
|
action: "store_true",
|
||||||
);
|
});
|
||||||
parser.add_argument(
|
parser.add_argument("-o", "--output", {
|
||||||
"-c",
|
help: "Output directory",
|
||||||
"--compile",
|
default: ".",
|
||||||
{
|
});
|
||||||
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) {
|
if (args.create) {
|
||||||
create()
|
create().then(() => {
|
||||||
}
|
if (args.compile) {
|
||||||
if (args.compile) {
|
compile(args.output);
|
||||||
compile(args.output)
|
}
|
||||||
|
});
|
||||||
|
} else if (args.compile) {
|
||||||
|
compile(args.output);
|
||||||
}
|
}
|
||||||
|
|
|
@ -313,6 +313,24 @@
|
||||||
"v8-compile-cache": "^2.0.3"
|
"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": {
|
"eslint-scope": {
|
||||||
"version": "5.1.1",
|
"version": "5.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz",
|
||||||
|
@ -423,6 +441,12 @@
|
||||||
"integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==",
|
"integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==",
|
||||||
"dev": true
|
"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": {
|
"fast-json-stable-stringify": {
|
||||||
"version": "2.1.0",
|
"version": "2.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz",
|
||||||
|
@ -473,6 +497,12 @@
|
||||||
"integrity": "sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=",
|
"integrity": "sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=",
|
||||||
"dev": true
|
"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": {
|
"glob": {
|
||||||
"version": "7.1.6",
|
"version": "7.1.6",
|
||||||
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz",
|
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz",
|
||||||
|
@ -717,6 +747,21 @@
|
||||||
"integrity": "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==",
|
"integrity": "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==",
|
||||||
"dev": true
|
"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": {
|
"progress": {
|
||||||
"version": "2.0.3",
|
"version": "2.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/progress/-/progress-2.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/progress/-/progress-2.0.3.tgz",
|
||||||
|
|
|
@ -3,7 +3,10 @@
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"argparse": "^2.0.1",
|
"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"
|
"license": "Apache-2.0"
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче