From 9052aa68d0a00ff2dcf1645e919a314f79f9dece Mon Sep 17 00:00:00 2001 From: Tom Enden Date: Sun, 8 Mar 2020 15:13:52 +0200 Subject: [PATCH] initial version, with `publish` command --- .../corvid-cli/src/commands/open-editor.js | 36 +++++++++---------- packages/corvid-cli/src/utils/electron.js | 13 +++++-- .../src/socket-api/index.js | 1 - packages/corvid-local-site/src/sitePaths.js | 3 -- 4 files changed, 28 insertions(+), 25 deletions(-) diff --git a/packages/corvid-cli/src/commands/open-editor.js b/packages/corvid-cli/src/commands/open-editor.js index 112bfe9d..118bd857 100644 --- a/packages/corvid-cli/src/commands/open-editor.js +++ b/packages/corvid-cli/src/commands/open-editor.js @@ -10,34 +10,34 @@ const { readCorvidConfig } = require("../utils/corvid-config"); const getMessage = require("../messages"); const { UserError } = require("corvid-local-logger"); const commandWithDefaults = require("../utils/commandWithDefaults"); -const prompts = require('prompts'); +const prompts = require("prompts"); const { versions: { readFileSystemLayoutVersion } } = require("corvid-local-site"); - -let userCommandIndex = 0 +let userCommandIndex = 0; const promptForCommand = async () => { const response = await prompts({ type: "text", message: "Type a command", - name: 'command' - }) - const [cp] = getRunningProcesses() - cp.send({...response, i: userCommandIndex}) - await new Promise((resolve) => { + name: "command" + }); + const [cp] = getRunningProcesses(); + cp.send({ ...response, i: userCommandIndex }); + await new Promise(resolve => { function listener(msg) { - const {result, i} = msg + const { result, i } = msg; if (i === userCommandIndex) { - userCommandIndex++ - cp.removeListener('message', listener) - resolve(result) + userCommandIndex++; + cp.removeListener("message", listener); + resolve(result); } } - cp.on('message', listener) - }).then(x => console.log(x)) - await promptForCommand() -} + cp.on("message", listener); + // eslint-disable-next-line no-console + }).then(result => console.log(result)); + await promptForCommand(); +}; const ensureLocalFileSystemVersion = async siteRootPath => { const existingFileSystemLayoutVersion = await readFileSystemLayoutVersion( @@ -89,7 +89,7 @@ async function openEditorHandler(args) { // background once the local server can be spawned in the background as // well //detached: true, - stdio: ['pipe', 'pipe', 'pipe', 'ipc'], + stdio: ["pipe", "pipe", "pipe", "ipc"], cwd: siteDirectory, env: { ...process.env, @@ -109,7 +109,7 @@ async function openEditorHandler(args) { spinner.succeed( chalk.grey(getMessage("OpenEditor_Command_Connected")) ); - promptForCommand() + promptForCommand(); }, error: error => { spinner.fail(); diff --git a/packages/corvid-cli/src/utils/electron.js b/packages/corvid-cli/src/utils/electron.js index 650a7ce5..d5043c18 100644 --- a/packages/corvid-cli/src/utils/electron.js +++ b/packages/corvid-cli/src/utils/electron.js @@ -37,7 +37,7 @@ function launch(file, options = {}, callbacks = {}, args = []) { const cp = childProcess.spawn( electron, - [path.resolve(path.join(file)), ...args, '--inspect-brk'], + [path.resolve(path.join(file)), ...args], { ...options } @@ -177,12 +177,19 @@ async function openLocalEditorAndServer(app, windowOptions = {}) { .executeJavaScript( ` new Promise((resolve, reject) => { - rendered.props.store.getState().editorAPI.localMode.publish(resolve, reject) + rendered.props.store.getState().editorAPI.savePublish.save(false, 'CLI', {}).then(() => { + rendered.props.store.getState().editorAPI.localMode.publish(resolve, reject) + }).catch(reject) }) ` ) .then(() => process.send({ i, result: "Publish sucess!" })) - .catch((e) => process.send({ i, result: `Publish failed :(\n Error: ${e} ` })); + .catch(e => + process.send({ + i, + result: `Publish failed :(\n Error: ${JSON.stringify(e)} ` + }) + ); } // win.webContents.executeJavaScript(`console.log("${msg}")`) }); diff --git a/packages/corvid-local-server/src/socket-api/index.js b/packages/corvid-local-server/src/socket-api/index.js index bf8fda68..08a4ffa2 100644 --- a/packages/corvid-local-server/src/socket-api/index.js +++ b/packages/corvid-local-server/src/socket-api/index.js @@ -58,7 +58,6 @@ const initServerApi = ( const updateSiteDocument = withCloneModeNotification( async updatedDocument => { - debugger const result = await localSite.updateSiteDocument(updatedDocument); notifyAdmin("document-updated"); wasSiteDocumentUpdated = true; diff --git a/packages/corvid-local-site/src/sitePaths.js b/packages/corvid-local-site/src/sitePaths.js index 3781d0c2..41e2a665 100644 --- a/packages/corvid-local-site/src/sitePaths.js +++ b/packages/corvid-local-site/src/sitePaths.js @@ -157,9 +157,6 @@ const removeSpaces = string => string.replace(/\s/g, "_"); const sanitizePageTitle = pageTitle => sanitize(removeSpaces(pageTitle)); const pageFilePath = ({ pageId, title, isPopup, extension, fileName }) => { - if (!title) { - debugger - } const pageOrLightboxRoot = isPopup ? ROOT_PATHS.LIGHTBOXES : ROOT_PATHS.PAGES; const sanitizedFolderTitle = sanitizePageTitle(title); const sanitizedFilename = sanitizePageTitle(fileName || title);