diff --git a/lib/blank.js b/lib/blank.js index 5de176e..6f64099 100644 --- a/lib/blank.js +++ b/lib/blank.js @@ -18,14 +18,15 @@ blankJson.read(configPath); switch (argv._[0]) { case "server": - require("./server")(false); - break; case "one": if (!process.env.BLANK_SERVICE_REGISTRY_PORT) { process.env.BLANK_SERVICE_REGISTRY_PORT = "2345"; } + if (!process.env.BLANK_FILE_STORE_PORT) { + process.env.BLANK_FILE_STORE_PORT = "8082"; + } - require("./server")(true); + require("./server")(); break; case "init": require("./init")(argv._[1], force); diff --git a/lib/buildConfig.js b/lib/buildConfig.js index 13be8e8..2c8b9e7 100644 --- a/lib/buildConfig.js +++ b/lib/buildConfig.js @@ -33,24 +33,14 @@ let lessVars = null; let scripts = null; let commit = "no git"; let buildTime = new Date(); -// let loadModule = false; const gitShort = () => { - return new Promise(resolve => { - git.short(res => resolve(res)); + return new Promise((resolve) => { + git.short((res) => resolve(res)); }); }; -// const isWinSep = path.sep === "\\"; -// const normalizePath = path => { -// if (isWinSep) { -// return path.replace(/\\/g, "/"); -// } - -// return path; -// }; - -module.exports = function(configPath, watch, oneServer) { +module.exports = function (configPath, watch) { babelRegister({ only: [new RegExp(path.resolve(configPath))], plugins: [reactJSX], @@ -68,7 +58,7 @@ module.exports = function(configPath, watch, oneServer) { } usedModules = Object.keys(require.cache); - settings = loadSettings(configPath, oneServer); + settings = loadSettings(configPath); console.log(`Building blank from: ${configPath}`); return prepareConfig(configPath) @@ -80,7 +70,7 @@ module.exports = function(configPath, watch, oneServer) { return createWatchers(configPath); } }) - .catch(err => { + .catch((err) => { console.error(err); throw new Error(err); }); @@ -104,7 +94,7 @@ module.exports.makeConfig = function makeConfig(configPath, output) { .then(() => { return postLib(); }) - .catch(err => { + .catch((err) => { console.error(err); throw new Error("[makeConfig]: " + err); }); @@ -121,24 +111,26 @@ function createWatchers(configPath) { ignoreInitial: true, ignored: [/var\//, /tests\//, /lib\//, /interfaces\//, /assets\//, /dist\//], }); - configWatcher.on("change", function() { + configWatcher.on("change", function () { clearTimeout(configTimer); configTimer = setTimeout(() => prepareConfig(configPath), 500); }); const libWatcher = chokidar.watch(settings.libPaths, { persistent: true, ignoreInitial: true }); - libWatcher.on("change", function(_path) { + libWatcher.on("change", function (_path) { clearTimeout(libTimer); libTimer = setTimeout(() => postLib(), 500); }); - const assetsWatchPaths = settings.assetsPaths.map(p => p.path || (typeof p === "string" && p) || "").filter(p => p); + const assetsWatchPaths = settings.assetsPaths + .map((p) => p.path || (typeof p === "string" && p) || "") + .filter((p) => p); console.log("[assetsWatchPaths]", assetsWatchPaths); const assetsWatcher = chokidar.watch(assetsWatchPaths, { persistent: true, ignoreInitial: true, }); - assetsWatcher.on("change", function(_path) { + assetsWatcher.on("change", function (_path) { console.log("[assetsWatcher] change"); clearTimeout(assetsTimer); assetsTimer = setTimeout(() => postAssets(), 500); @@ -170,7 +162,7 @@ function prepareConfig(configPath) { const config = {}; buildTime = new Date(); return gitShort() - .then(res => { + .then((res) => { commit = res; console.log("Loading default config"); loadFromFolder(config, defaultConfigPath); @@ -183,7 +175,7 @@ function prepareConfig(configPath) { babelifyConfig(config); return ship(config); }) - .catch(err => { + .catch((err) => { throw new Error("[buildConfig:prepareConfig]: " + err); }); } @@ -230,11 +222,11 @@ function updateAssets(config) { console.log("Building LESS..."); lessVars = _lessVars; const p = buildLess(lessVars, webAppPath).then( - r => { + (r) => { console.log("LESS build OK"); less = r.css; }, - err => { + (err) => { console.warn("LESS build error:", err); } ); @@ -244,7 +236,7 @@ function updateAssets(config) { const _scripts = config._commonSettings.entries.scripts || []; if (JSON.stringify(_scripts) !== JSON.stringify(scripts)) { scripts = _scripts; - const p = loadIndex().then(_html => { + const p = loadIndex().then((_html) => { let scriptsHtml = ""; for (let s of scripts) { scriptsHtml += `\n`; @@ -287,7 +279,7 @@ function ship(config) { Object.assign(srUrl, { method: "POST", }), - res => { + (res) => { console.log("Post 'config' to service registry result: ", res.statusCode, "/", res.statusMessage); } ); @@ -296,7 +288,7 @@ function ship(config) { } else { const confOutput = path.resolve(settings.output); return new Promise((resolve, reject) => { - mkdirp(confOutput, function(err) { + mkdirp(confOutput, function (err) { if (err) { console.error(err); return reject(err); @@ -310,7 +302,7 @@ function ship(config) { const outputFile = path.normalize(confOutput + path.sep + "config.json"); console.log(new Date(), "Writing config to: ", outputFile); - fs.writeFile(outputFile, configString, function(err) { + fs.writeFile(outputFile, configString, function (err) { if (err) { console.log(err); return reject(err); @@ -321,7 +313,7 @@ function ship(config) { }); }); }) - .catch(err => { + .catch((err) => { throw new Error("[buildConfig:ship]: " + err); }); } @@ -330,7 +322,7 @@ function ship(config) { function stringifyConfig(config) { return JSON.stringify( config, - function(key, val) { + function (key, val) { return stringifyFunction(val); }, " " @@ -412,7 +404,7 @@ function loadFromFolder(config, configPath, recursive) { } } -function loadSettings(configPath, oneServer) { +function loadSettings(configPath) { const settings = blankJson.read(configPath); settings.libPaths = Array.isArray(settings.lib.path) ? settings.lib.path : ["./lib"]; settings.assetsPaths = Array.isArray(settings.assets.path) ? settings.assets.path : ["./assets"]; @@ -446,23 +438,6 @@ function loadSettings(configPath, oneServer) { return settings; } -// function findLoadModuleConfig(config) { -// for (let key of Object.keys(config)) { -// if (key === "loadModule") { -// loadModule = true; -// break; -// } -// try { -// let value = config[key]; -// if (value && typeof value == "object") { -// findLoadModuleConfig(value); -// } -// } catch (error) { -// console.error("key", key, config[key], error); -// } -// } -// } - function loadIndex() { const indexPath = path.join(webAppPath, "src", "html", "index.html"); diff --git a/lib/downloadBin.js b/lib/downloadBin.js index fe630a6..8e59c12 100644 --- a/lib/downloadBin.js +++ b/lib/downloadBin.js @@ -4,13 +4,12 @@ const mkdirp = require("mkdirp"); const { goPackageNames } = require("./packageNames"); const fetch = require("node-fetch"); -module.exports = function(packageDirname, update) { +module.exports = function (packageDirname, update) { let binExists = true; const binPath = path.join(packageDirname, "bin"); try { binExists = binExists && fs.statSync(binPath).isDirectory(); - binExists = binExists && fs.statSync(path.join(binPath, "blank-sr")).isFile(); - binExists = binExists && fs.statSync(path.join(binPath, "blank-router")).isFile(); + binExists = binExists && fs.statSync(path.join(binPath, "blank-one")).isFile(); } catch (err) { binExists = false; } @@ -38,17 +37,19 @@ module.exports = function(packageDirname, update) { }); }; +const getArch = () => { + const machineArch = process.arch; + if (machineArch === "x64") return "amd64"; + return process.arch; +}; + function downloadPackage(binPath, name) { - if (process.arch !== "x64") { - throw new Error(`unsupported platform ${process.platform}/${process.arch}`); - } + const arch = getArch(); const ext = process.platform === "win32" ? ".exe" : ""; return getLastVersionOfPackage(name) - .then(version => { - const downloadUrl = `https://github.com/getblank/${name}/releases/download/${version}/${name}-${ - process.platform - }-amd64${ext}`; + .then((version) => { + const downloadUrl = `https://github.com/getblank/${name}/releases/download/${version}/${name}-${process.platform}-${arch}${ext}`; console.info(downloadUrl); return download(downloadUrl, path.join(binPath, `${name}${ext}`)); @@ -56,27 +57,24 @@ function downloadPackage(binPath, name) { .then(() => { console.log("Download complete:", `${name}${ext}`); }) - .catch(err => { + .catch((err) => { console.log("Download failed:", `${name}${ext}`, err); }); } function download(url, dest) { return fetch(url) - .then(res => { + .then((res) => { const file = fs.createWriteStream(dest, { mode: 0o776, }); - return new Promise(resolve => { + return new Promise((resolve) => { res.body.on("end", resolve); - res.body.pipe( - file, - { end: false } - ); + res.body.pipe(file, { end: false }); }); }) - .catch(err => { + .catch((err) => { fs.unlink(dest); throw err; @@ -85,10 +83,10 @@ function download(url, dest) { function getLastVersionOfPackage(packageName) { return fetch(`https://api.github.com/repos/getblank/${packageName}/releases/latest`) - .then(res => { + .then((res) => { return res.json(); }) - .then(json => { + .then((json) => { return json.tag_name; }); } diff --git a/lib/packageNames.js b/lib/packageNames.js index 009489d..74f4f1b 100644 --- a/lib/packageNames.js +++ b/lib/packageNames.js @@ -1,2 +1,2 @@ -module.exports.goPackageNames = ["blank-sr", "blank-router", "blank-cron", "blank-fs", "blank-queue", "blank-one"]; -module.exports.nodePackageNames = ["blank-node-worker"]; \ No newline at end of file +module.exports.goPackageNames = ["blank-one", "blank-fs"]; +module.exports.nodePackageNames = ["blank-node-worker"]; diff --git a/lib/server.js b/lib/server.js index bb2af6b..e6feefa 100644 --- a/lib/server.js +++ b/lib/server.js @@ -12,7 +12,7 @@ const configPath = argv.dir || argv.d || process.cwd(); const _goPackageNames = filterPackageNames(goPackageNames); const _nodePackageNames = filterPackageNames(nodePackageNames); -module.exports = function(oneServer = false) { +module.exports = function () { if (!argv.dkp) { for (const pName of _goPackageNames.concat(_nodePackageNames)) { try { @@ -24,18 +24,6 @@ module.exports = function(oneServer = false) { } } - if (oneServer) { - _goPackageNames.length = 0; - _goPackageNames.push("blank-one", "blank-fs"); - } else { - for (let i = 0; i < _goPackageNames.length; i++) { - if (_goPackageNames[i] === "blank-one") { - _goPackageNames.splice(i, 1); - break; - } - } - } - console.log("Starting services..."); run() .then(() => { @@ -43,14 +31,14 @@ module.exports = function(oneServer = false) { return buildConfig(); }) - .catch(e => { + .catch((e) => { console.log(e); }); }; -function buildConfig(oneServer = false) { +function buildConfig() { const build = require("./buildConfig"); - build(configPath, true, oneServer); + build(configPath, true); return Promise.resolve(); } @@ -89,7 +77,7 @@ function run() { p.on("close", () => { throw new Error(`Child Node process ${packageName} closed!`); }); - p.on("error", err => { + p.on("error", (err) => { console.error(err); throw err; }); @@ -99,13 +87,13 @@ function run() { } function filterPackageNames(names) { - const include = (argv.i || argv.include || "").split(",").filter(n => n); - const exclude = (argv.e || argv.exclude || "").split(",").filter(n => n); + const include = (argv.i || argv.include || "").split(",").filter((n) => n); + const exclude = (argv.e || argv.exclude || "").split(",").filter((n) => n); return names.filter( - n => - (include.length === 0 || include.filter(i => n.indexOf(i) >= 0).length > 0) && - (exclude.length === 0 || exclude.filter(e => n.indexOf(e) >= 0).length === 0) + (n) => + (include.length === 0 || include.filter((i) => n.indexOf(i) >= 0).length > 0) && + (exclude.length === 0 || exclude.filter((e) => n.indexOf(e) >= 0).length === 0) ); } @@ -124,7 +112,7 @@ function runGoPackage(cwd, goPackageName) { p.on("close", (code, signal) => { throw new Error(`Child Go process ${goPackageName} closed with code ${code}. Close signal: ${signal}!`); }); - p.on("error", err => { + p.on("error", (err) => { console.error(err); throw err; }); diff --git a/lib/webpackCompile.js b/lib/webpackCompile.js index f723c5e..d63eee2 100644 --- a/lib/webpackCompile.js +++ b/lib/webpackCompile.js @@ -9,10 +9,10 @@ try { } catch (error) { console.log("======NPM INSTALL IN BLANK-WEB-APP======"); spawnSync("npm", ["install"], { stdio: "inherit", cwd: webAppPath }); - console.log("======FINISH NPM INSTALL======"); + console.log("===========FINISH NPM INSTALL==========="); } -module.exports = configPath => { +module.exports = (configPath) => { const APP_DIR = path.resolve(webAppPath, "src"); console.log("webAppPath", webAppPath); console.log("APP_DIR", APP_DIR); @@ -21,6 +21,7 @@ module.exports = configPath => { const config = { mode: "production", entry: ["whatwg-fetch", path.resolve(webAppPath, "./src/js/app.js")], + devtool: "source-map", output: { path: path.resolve(configPath, "dist"), filename: "bundle.js", @@ -48,7 +49,7 @@ module.exports = configPath => { rules: [ { test: /\.jsx?$/, - exclude: m => { + exclude: (m) => { return m.includes("/blank-web-app/node_modules/"); }, use: { diff --git a/package-lock.json b/package-lock.json index 85c0473..668276f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "blank-cli", - "version": "0.1.95", + "version": "0.1.96-5", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index ef5f81d..324dc9f 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "blank-cli", - "version": "0.1.95", - "description": "Blank is a microservices platform for rapid CRUD applicaitons developing", + "version": "0.1.96-5", + "description": "Blank is a microservice platform for rapid CRUD applications developing", "main": "index.js", "scripts": { "postinstall": "node ./postinstall.js", @@ -27,7 +27,7 @@ "mongodb" ], "author": { - "email": "info+blank@sclif.pro", + "email": "ivahaev+blank@gmail.com", "name": "Evgeniy Kuvshinov & Evgeniy Ivakha" }, "homepage": "https://getblank.github.io/site/", @@ -58,8 +58,8 @@ "@babel/preset-env": "^7.0.0", "@babel/preset-react": "^7.0.0", "@babel/register": "^7.0.0", - "blank-node-worker": "latest", - "blank-web-app": "latest", + "blank-node-worker": "next", + "blank-web-app": "next", "chokidar": "^1.5.0", "dotenv": "^4.0.0", "form-data": "^2.1.2",