Skip to content

Commit

Permalink
v1.0.0! refractoring the watch mode which dragged a lot of changes :(
Browse files Browse the repository at this point in the history
* v1.0.0
* refractofing watch mode
* downgrade chokidar version due to paulmillr/chokidar#888
* added option to stop auto error check (the detaulf is ON)
  • Loading branch information
countnazgul committed Sep 30, 2019
1 parent b2ac489 commit 0713f2b
Show file tree
Hide file tree
Showing 10 changed files with 234 additions and 184 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,18 @@ Run one of the following commands from CMD/PowerShell
* saves the `qvs` files into `src` folder


* `qlbuilder watch [env]` - enters in watch mode. The default behavior is to build and check the script syntax on any `*.qvs` file inside `src` folder. Can accept two additional flags:
* `qlbuilder watch [env]` - enters in watch mode. The default behavior is to build and check the script syntax on any `*.qvs` file inside `src` folder. Can accept three additional flags:

* `-r` - reloads the script on any `qvs` file change
* `-s` - sets the script (and save the app) on any `qvs` file change
* `-d` - disable the auto check for syntax errors. By default the script will check for syntax errors on each save (connects to QS and checks the script for errors against session/temp app)

Inside `watch` mode the console is active and the developer can perform additional actions. Just type one of the letters/commands below in the console to trigger them:

* `s` or `set` - build, syntax check and set script
* `r` or `rl` - build and set the script, reload the app and save. If any syntax error (during the build and set) the reload is not triggered
* `c` or `clr` - clear console
* `e` or `err` - check for syntax errors (**useful only if the watch mode is started with `-d` argument**)
* `?` - print these commands
* `x` - exit

Expand Down
4 changes: 3 additions & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ Other:
✔ jwt @done(19-09-29 21:08)
☐ cert
☐ @low validate JSON schema - config.yml?
☐ Update readme with the latest changes related to jwt and cert env variables
✔ Update readme with the latest changes related to jwt and cert env variables @done(19-09-30 07:13)
✔ add option to not check script on save. The default will check on save as usual @done(19-09-30 08:22)
✔ all realine logic should be in separate module. Handling errors is not nice if left as it is @done(19-09-30 14:54)

Testing:
✔ @high re-test the communication errors - if QS is not reachable ... seems that qlik-auth module is failing there (for now) @done(19-09-30 03:10)
Expand Down
51 changes: 16 additions & 35 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "qlbuilder",
"version": "0.1.37",
"version": "1.0.0",
"description": "CLI helper tool for Qlik Sense developers to allow write script locally and update in remote app",
"author": "Stefan Stoichev <@countnazgul> (https://sstoichev.eu)",
"main": "./src/index.js",
Expand All @@ -27,7 +27,7 @@
"dependencies": {
"axios": "^0.19.0",
"chalk": "^2.4.2",
"chokidar": "^3.1.0",
"chokidar": "^3.0.2",
"cli-spinner": "^0.2.10",
"commander": "^2.20.0",
"compare-versions": "^3.5.1",
Expand Down
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0;
.description('Start qlBuilder in watch mode')
.option('-r', 'Reload and save on each file change')
.option('-s', 'Set script and save app on each file change')
.option('-d', 'Disable the auto syntax error check')
.action(async function (envName, options) {
let checks = initialChecks.combined(envName)
if (checks.error) common.writeLog('err', checks.message, true)
Expand All @@ -72,6 +73,7 @@ process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0;
args: {
reload: options.R || false,
setScript: options.S || false,
disableChecks: options.D || false,
}
})
});
Expand All @@ -80,9 +82,7 @@ process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0;
.command('build')
.description('Combine the tab script files into one')
.action(async function () {
// the full initial checks are not required
// just check if src and dist folders are present
let checks = helpers.initialChecks.short()
let checks = initialChecks.short()
if (checks.error) common.writeLog('err', checks.message, true)

let buildScript = await argsFunctions.buildScript()
Expand Down
111 changes: 111 additions & 0 deletions src/packages/argHelpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
const Spinner = require('cli-spinner').Spinner;
Spinner.setDefaultSpinnerDelay(200);

const fs = require('fs');

const helpers = require('./helpers');
const qlikComm = require('./qlik-comm');

const buildScript = async function () {
let loadScript = helpers.buildLoadScript()

let writeScript = helpers.writeLoadScript(loadScript)
if (writeScript.error) return writeScript

return ({ error: false, message: loadScript })
}

const checkScript = async function ({ environment, variables, script }) {
let spinner = new Spinner('Checking for syntax errors ...');
spinner.setSpinnerString('☱☲☴');
spinner.start();

let loadScript = ''

if (script) {
let script = await buildScript()
if (script.error) return script

loadScript = script.message
}

let scriptResult = await qlikComm.checkScriptSyntax({ environment, variables, script: loadScript })
if (scriptResult.error) {
spinner.stop(true)
return scriptResult
}

spinner.stop(true)

if (scriptResult.message.length > 0) {
displayScriptErrors(scriptResult.message)
return { error: true, message: 'Syntax errors found!' }
}

return { error: false, message: 'No syntax errors were found' }
}

const setScript = async function ({ environment, variables }) {
let script = await buildScript()
if (script.error) return script

let setScript = await qlikComm.setScript({ environment, variables, script: script.message })
if (setScript.error) return setScript

return { error: false, message: setScript.message }
}

function displayScriptErrors(scriptResultObj) {
let scriptFiles = fs.readdirSync(`./src`).filter(function (f) {
return f.indexOf('.qvs') > -1
})

let scriptErrorsPrimary = scriptResultObj.filter(function (e) {
return !e.qSecondaryFailure
})

for (let scriptError of scriptErrorsPrimary) {
let tabScript = fs.readFileSync(`./src/${scriptFiles[scriptError.qTabIx]}`).toString().split('\n')

console.log(`
Tab : ${scriptFiles[scriptError.qTabIx]}
Line: ${scriptError.qLineInTab}
Code: ${tabScript[scriptError.qLineInTab - 1]}`)
}
}

const onFileChange = async function ({ environment, variables, args }) {
let script = await buildScript()
if (script.error) return script

let checkLoadScript = await checkScript({ environment, variables, script: script.message })
if (checkLoadScript.error) return checkLoadScript

// if only SetScript is set
if (!args.reload && args.setScript) {
let setScript = await qlikComm.setScript({ environment, variables, script: script.message })
if (setScript.error) return { error: true, message: setScript.message }

return { error: false, message: setScript.message }
}

// if Reload is set AND/OR SetScript is set
if (args.reload) {
let reload = await qlikComm.reloadApp({ environment, variables, script: script.message })
if (reload.error) return { error: true, message: reload.message }

return { error: false, message: reload.message }
}

return checkLoadScript
}



module.exports = {
buildScript,
checkScript,
displayScriptErrors,
setScript,
onFileChange
}
Loading

0 comments on commit 0713f2b

Please sign in to comment.