Minor changes

This commit is contained in:
fkereki
2018-04-11 15:29:50 -03:00
parent 52b5ee812d
commit 28fb419475
5 changed files with 24 additions and 59 deletions
+9 -28
View File
@@ -5,7 +5,8 @@
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"build": "flow-remove-types src/ -d out/", "build": "flow-remove-types src/ -d out/",
"buildWithMaps": "flow-remove-types src/ -d out/ --pretty --sourcemaps", "buildWithMaps":
"flow-remove-types src/ -d out/ --pretty --sourcemaps",
"start": "npm run build && node out/doroundmath.js", "start": "npm run build && node out/doroundmath.js",
"start-db": "npm run build && node out/dbaccess.js", "start-db": "npm run build && node out/dbaccess.js",
"nodemon": "nodemon --watch src --delay 1 --exec npm start", "nodemon": "nodemon --watch src --delay 1 --exec npm start",
@@ -19,10 +20,7 @@
"author": "Federico Kereki", "author": "Federico Kereki",
"license": "ISC", "license": "ISC",
"babel": { "babel": {
"presets": [ "presets": ["env", "flow"]
"env",
"flow"
]
}, },
"eslintConfig": { "eslintConfig": {
"parserOptions": { "parserOptions": {
@@ -31,41 +29,24 @@
}, },
"parser": "babel-eslint", "parser": "babel-eslint",
"env": { "env": {
"browser": true,
"node": true, "node": true,
"es6": true "es6": true
}, },
"extends": [ "extends": ["eslint:recommended", "plugin:flowtype/recommended"],
"eslint:recommended", "plugins": ["babel", "flowtype"],
"plugin:flowtype/recommended"
],
"plugins": [
"babel",
"flowtype"
],
"rules": { "rules": {
"no-console": "off", "no-console": "off",
"no-var": "error", "no-var": "error",
"prefer-const": "error" "prefer-const": "error"
} }
}, },
"eslintIgnore": [ "eslintIgnore": ["**/out/*.js"],
"**/out/*.js"
],
"flow-coverage-report": { "flow-coverage-report": {
"concurrentFiles": 1, "concurrentFiles": 1,
"excludeGlob": [ "excludeGlob": ["node_modules/**"],
"node_modules/**" "includeGlob": ["src/**/*.js"],
],
"includeGlob": [
"src/**/*.js"
],
"threshold": 90, "threshold": 90,
"type": [ "type": ["text", "html", "json"]
"text",
"html",
"json"
]
}, },
"prettier": { "prettier": {
"tabWidth": 4, "tabWidth": 4,
+6 -20
View File
@@ -1,22 +1,15 @@
/* @flow */ /* @flow */
"use strict";
const child_process = require("child_process"); const child_process = require("child_process");
const { promisify } = require("util"); const { promisify } = require("util");
child_process.exec = promisify(child_process.exec); child_process.exec = promisify(child_process.exec);
async function getDirectory(path: ?string) { async function getDirectoryJs(path: string) {
try { try {
const cmd = "ls -ld -1 *.js"; const cmd = "ls -ld -1 *.js";
const stdout = await child_process.exec(cmd, { cwd: path });
let stdout;
if (typeof path === "undefined") {
({ stdout } = await child_process.exec(cmd));
} else {
// $FlowFixMe: Flow doesn't understand "promisify()"
({ stdout } = await child_process.exec(cmd, { cwd: path }));
}
console.log("OUT", path || ""); console.log("OUT", path || "");
console.log(stdout); console.log(stdout);
} catch (e) { } catch (e) {
@@ -24,19 +17,12 @@ async function getDirectory(path: ?string) {
} }
} }
getDirectory(); getDirectoryJs("/boot");
/* /*
OUT ERR ls: cannot access '*.js': No such file or directory
-rw-r--r-- 1 fkereki users 3336 Apr 10 13:12 dbaccess.js
-rw-r--r-- 1 fkereki users 319 Apr 10 13:12 doroundmath.js
-rw-r--r-- 1 fkereki users 890 Apr 10 13:12 flowcomments.js
-rw-r--r-- 1 fkereki users 293 Apr 10 13:12 miniserver.js
-rw-r--r-- 1 fkereki users 751 Apr 10 13:12 process_exec.js
-rw-r--r-- 1 fkereki users 1311 Apr 10 13:12 promisify.js
-rw-r--r-- 1 fkereki users 828 Apr 10 13:12 roundmath.js
*/ */
getDirectory("/home/fkereki/MODERNJS/chapter03/flow-typed/npm"); getDirectoryJs("/home/fkereki/MODERNJS/chapter03/flow-typed/npm");
/* /*
OUT /home/fkereki/MODERNJS/chapter03/flow-typed/npm OUT /home/fkereki/MODERNJS/chapter03/flow-typed/npm
-rw-r--r-- 1 fkereki users 4791 Apr 9 12:52 axios_v0.18.x.js -rw-r--r-- 1 fkereki users 4791 Apr 9 12:52 axios_v0.18.x.js
+3 -5
View File
@@ -1,14 +1,12 @@
"use strict";
const fs = require("fs"); const fs = require("fs");
process.on("message", obj => { process.on("message", obj => {
console.log("GOT!", obj);
// Received a path to process // Received a path to process
fs fs
.readdirSync(obj.path) .readdirSync(obj.path)
.sort((a, b) => a.toLowerCase().localeCompare(b.toLowerCase())) .sort((a, b) => a.toLowerCase().localeCompare(b.toLowerCase()))
.filter(file => !file.startsWith(".")) .filter(file => !file.startsWith("."))
.forEach(file => { .forEach(file => process.send(file));
process.send(file);
});
}); });
+2 -3
View File
@@ -1,12 +1,11 @@
/* @flow */ /* @flow */
"use strict";
const path = require("path"); const path = require("path");
const { spawn } = require("child_process"); const { spawn } = require("child_process");
const child = spawn("node", [path.resolve("out/process_spawn_dir.js")]); const child = spawn("node", [path.resolve("out/process_spawn_dir.js")]);
const filePath = "/home/fkereki"; child.stdin.write("/home/fkereki");
child.stdin.write(filePath);
child.stdout.on("data", data => { child.stdout.on("data", data => {
console.log(String(data)); console.log(String(data));
+4 -3
View File
@@ -1,3 +1,6 @@
/* @flow */
"use strict";
const fs = require("fs"); const fs = require("fs");
process.stdin.resume(); process.stdin.resume();
@@ -8,9 +11,7 @@ process.stdin.on("data", path => {
.readdirSync(path) .readdirSync(path)
.sort((a, b) => a.toLowerCase().localeCompare(b.toLowerCase())) .sort((a, b) => a.toLowerCase().localeCompare(b.toLowerCase()))
.filter(file => !file.startsWith(".")) .filter(file => !file.startsWith("."))
.forEach(file => { .forEach(file => process.stdout.write(file + "\n"));
process.stdout.write(file + "\n");
});
process.stdout.end(); process.stdout.end();
}); });