Code Monkey home page Code Monkey logo

sense-go's Introduction

Validate, package and deploy your Qlik Sense Visualization Extension projects with ease.

NPM version David Codecov CircleCI AppVeyor tests Codacy Badge

Table of Contents

Motivation

sense-go automates typical repetitive tasks when developing a Visualization extension for Qlik Sense, such as:

  • Preparation tasks
    • Import dependencies (like libraries, images, fonts, etc.)
  • Packaging
    • Health checks for your source files
    • Compile your .less files to CSS
  • Deployment
    • to GitHub or your favorite VCS
    • to Qlik Sense Desktop
    • to a Qlik Sense Server
    • to a .zip file to share with others
  • Watching your changes
    • to just rebuild everything automatically

Technically speaking sense-go is just a collection of configurable gulp tasks which can be easily re-used and extended.

Installation

Package installation

Install sense-go as a global node.js package

$ npm install -g sense-go

or use it as a Docker image.

Usage

There are basically three different approaches to use sense-go.

1) CLI with default configuration

Just run sense-go in the command line in the root folder of your project (and follow the conventions). The default configuration will be considered.

2) CLI with custom configuration
Place a .sense-go.yml file in the root folder of your project, then run sense-go in the CLI.

The easiest way to start with your custom configuration is to copy the default configuration file and start modifying it. But keep in mind, following the conventions , you should only need to adapt a few of the default configurations.

3) Programmatic usage
If you want to add custom gulp tasks, this is the way to go.

  • Create a file sense-go.js in the root of your project based on the following skeleton:
'use strict';
var senseGo = require( 'sense-go' );
var gulp = senseGo.gulp; // Get the reference to the gulp instance used in sense-go

senseGo.init( function () {

	// Now all default tasks are loaded, can be modified or new ones can be added
	
	// Run your tasks, e.g. with
	gulp.series(['build']);
	
});

**Note: sense-go is using the beta of Gulp 4 **

Conventions

The entire concept follows conventions (or best practices) being used when setting up a project:

| PROJECT-ROOT
|-- build         <= all builds, including source code or zipped files
    |-- dev       <= target for the development build
    |-- release   <= target for the release build
|-- docs          <= documentation files, then used by verb
|-- src           <= all source files
    |-- lib
    |-- css       <= see below *
        |-- less  <= less files
| .sense-go.yml   <= sense-go configuration file (OPTIONAL)
| .verb.md        <= verbs readme template
| package.json

* If using less files is preferred for a project, I keep this folder empty, otherwise all the .css files will be place here

sense-go works best if you follow these conventions, but everything is configurable, it's just a bit more work to get sense-go running.

Basic workflow

The workflow of the pre-configured tasks can be summarized as follows:

  • You develop in the .src folder
  • Whenever you want to test or deploy, use a one-liner in your command line: sense-go
    • This will
      • Convert .less files to .css files
      • Lint, Minify, Ugilify the output
      • Create a .zip file to distribute your visualization extension
      • ... a lot of other neat tasks ... fully customizable ...
  • Then the extension is automatically being deployed
    • To the local extension directory (Qlik Sense Desktop)
    • Imported to the Qlik Sense Server (using the Qlik Sense Repository API)
    • to other destinations, like via SSH
  • You can test the extension

It is important to mention that you can by 100% re-define the workflow and also all default settings, but the idea of sense-go is really to get something up and running across different projects with as little configuration and development work as possible. So choose custom configurations wisely.

Behind the scenes

Behind the scenes the following happens:

  • All relevant content of the src folder is copied to a temporary folder .tmp
  • Then in the .tmp folder some transformation of existing files happens
  • As soon as this is done, files are copied to a .build folder ( .build/dev in case of the dev strategy, .build/release in case of the release strategy)
  • Then the enabled deployment tasks start
    • Copy all files to the local Qlik Sense Desktop
    • Deployment to any server using the QRS API
    • Deployment to any other server using SSH
  • (All temporary folders (like .tmp) are deleted)

API / Programmatic Usage

Pass in a custom configuration as object

In your sense-go.js pass in a custom configuration object to senseGo.init as follows:

'use strict';
const SenseGo = require('./lib/');
const senseGo = new SenseGo();

var customConfig = {
  deployment: {
    toLocal: {
      enabled: true
    }
  }
}

// customConfig will be used to overwrite existing settings from the default-settings.
// Any setting not being defined in your custom configuration will be taken from the default settings.
senseGo.init( customConfig, function () {
  
  
});

Load configuration from a file:

'use strict';
const SenseGo = require('./lib/');
const senseGo = new SenseGo();

var customConfig = senseGo.loadYml( path.join(__dirname, 'custom-config.yml'));

senseGo.init( customConfig, function () {
  
  
});

Add custom tasks

'use strict';
const SenseGo = require('./lib/');
const senseGo = new SenseGo();
const gulp = senseGo.gulp; // Get the reference to the gulp instance used in sense-go

senseGo.init( function () {

	// Create a new custom task
	gulp.task('custom', function( done ) {
		console.log('Custom Task');
		done();
	});
	
	// Create a custom task chain, re-using 'build'
	gulp.task('customBuild', gulp.series(['custom', 'build']));
	
	// Run it ...
	gulp.series('customBuild')();
	
});

Tasks

There are three categories of tasks:

  • Building: Build the solution (either for debugging or release) before you deploy.
  • Deployment: Deploy the solution to different targets.
  • Publishing & Tools: Some helpers to publish the solution.

Building

Clean

Cleaning and deleting folders.

clean:tmp

  • Delete the entire .tmp directory.
  • Options used:
    • tmpDir

clean:buildDev

  • Deletes all files in the ./build/dev directory.
  • Options used:
    • buildDevDir

clean:buildRelease

  • Deletes all files in the ./build/release directory.
  • Options used:
    • buildReleaseDir

clean:localExtensionDir

  • Deletes all files in the project's local extension folder. Only makes sense if using deployment to a local Qlik Sense Desktop.
  • Disabled if deployment.toLocal.enabled === false.
  • Options used:
    • deployment.toLocal.enabled

clean:tmpIllegal

  • Clean all files in the .tmp directory which are not supposed to be deployed to the extension directory.
  • These are all files, except files with the following file extension:
    • {png,jpg,jpeg,json,qext,txt,js,css,eot,svg,ttf,woff,html,htm,wbl,svg}

Copy

Copy files to a specific directory.

copy:toTmp

  • Copies all files (except the excluded ones) from the src folder to the .tmp folder.
  • Options used:
    • srcDir
    • tmpDir
  • Excluded files:
    • *.less

copy:tmpToDev

  • Copies all files (except the excluded ones) from the .tmp folder to .\build\dev folder.
  • Options used:
    • tmpDir
    • buildDevDir
  • Excluded files:
    • *.less

copy:tmpToRelease

  • Copies all files (except the excluded ones) from the .tmp folder to .\build\release folder.
  • Options used:
    • tmpDir
    • buildReleaseDir
  • Excluded files:
    • *.less

Import

Import files to the deployment.

import:fromLocal The main use-case behind the import:fromLocal task is to be able to import "external" files from external dependencies (e.g. node_modules or bower) into the .tmp directory to use them in the solution.

Define the file you want to import in your .sense-go.yml file as follows:

Example:

import:
  fromLocal:
    enabled: true
    files:
      - ["./node_modules/d3/d3.min.js", "./.tmp/lib/external/d3/d3.min.js"]
      - ["./node_modules/moment/min/moment.min.js", "./.tmp/lib/external/moment/moment.min.js"]

import:fromSsh Import one or more files from a remote sever (with SSH enabled) to your local projects.

Define the sources and targets in your .sense-go.yml or .sense-go.local.yml file as follows:

Example (Import just one file):

import:
  fromSsh:
    enabled: true
    host: "192.168.10.20"
    port: 22
    user: "<username>"
    pwd: "password"
    src: "/remote/path/to/your/file"
    dest: "./tmp/whatever"

Example (Import a collection of files):

import:
  fromSsh:
    enabled: true
    host: "192.168.10.20"
    port: 22
    user: "<username>"
    pwd: "password"
    files:
      - src: "/remote/path/to/your/file"
        dest: "./tmp/whatever"
      - src: "/remote/path/to/your/2nd/file"
        dest: "./tmp/whatever"

Replace

Replaces string patterns in text files across the project.

replace:tmp

  • Use `@@ to prefix the key to be replaced with a given value in the source code
  • Replacements will only be performed in the following file types:
    • .html
    • .js
    • .json
    • .qext
    • .txt
    • .xml
    • .yml

Using data from package.json All keys from your package.json file are available out of the box if you use the prefix pkg

  • To get the version, use @@pkg.version
  • To the get name, use @@pkg.name
  • etc.

Example:

console.log('Extension @@pkg.name, version @@pkg.version');

with the following package.json

{
  "name": "my-extension",
  "version": "0.1.12"
}

will return

Extension my-extension, version 0.1.12

Builtin patterns The following patterns are available out of the box:

  • @@timestamp - Defaults to new Date().getTime()

Adding replacement patterns Add new replacements patterns in your .sense-go.yml file:

replacements:
  custom:
    test1: bla bla
  custom2:
    var1: true
    var2: "Whatever comes here"

Then in your e.g. JavaScript file use the replacements:

console.log('custom.test1', '@@custom.test1');
console.log('custom2.var2', '@@custom2.var1');
console.log('custom2.var2', '@@custom2.var2');

Will return:

bla bla
true
Whatever comes here

Less

Converts .less files to .css files.

All less tasks automatically autoprefix (using gulp-autoprefixer)

less:reduce

  • Uses /src/less/main.less, resolves all its dependencies and creates /.tmp/css/main.css
  • Options used:
    • lessReduce.src
    • lessReduce.dest

less:each

  • Converts every .less file from the source directory to a corresponding .css file in the .tmp directory.
  • Options used:
    • lessEach.src
    • lessEach.dest

Uglify

Uglify & minifies JavaScript files

General uglify options

  • uglify* - All options directly passed to gulp-uglify, e.g.
    • uglify.mangle
    • uglify.beautify
    • uglify.compress
    • uglify.preserveComments - (Default: 'license')

Further options can be passed according to the gulp-uglify documentation.

uglify:tmp

  • Uglify all JavaScript files.
  • Options:
    • uglifyTmp.src - Included source files. (Default: ./.tmp/**/*.js)
    • uglifyTmp.srcExcluded - Excluded source files (Default: ./.tmp/**/*.min.js)

Minification/Optimization

Several minification tasks

htmlmin:tmp

  • Minifies all htm/html files in the tmp folder.
  • Options used:
    • tmpDir

minify:json:tmp

  • Minify .json & .qext files.
  • Options used:
    • tmpDir

Wbfolder

Create a wbfolder.wbl file to be used in Dev Hub - Extension Editor.

wbfolder:tmp

  • Creates a wbfolder.wbl file in the .tmp directory.
  • Options used:
    • wbfolder.enabled- Whether the task is enabled or not, defaults to true.
    • wbfolder.cwd - Working directory, defaults to ./.tmp.
    • wbfolder.src - Source mask, defaults to ./**/*.*.
    • wbfolder.dest - wbfolder.wbl file destination, defaults to ./.tmp/wbfolder.wbl.

Note: The wbfolder.wbl file is only necessary if you want to allow users to open your visualization extension in Qlik Dev Hub. wbfolder.wbl is NOT required and necessary to run your visualization extension in Qlik Sense.

Zip

Create .zip files based on the building strategy

zip:dev

  • Creates a zip file following the pattern "%packageName%_dev.zip" (e.g. "my-extension_dev.zip")
  • This task is used in the pre-built task-chain build and will create the output of the build-strategy "dev"
  • Options used:
    • tmpDir
    • buildDir
    • packageName

zip:release

  • Creates a zip file following the pattern "%packageName%_v%pkg.version%.zip" (e.g. "my-extension_v0.12.1.zip")
  • This task is used in the pre-built task-chain release and creates a packaged version of your current version
  • Options used:
    • tmpDir
    • buildDir
    • packageName
    • pkg.version

zip:latest

  • Create a zip file following the pattern "%packageName%_latest.zip" (e.g. "my-extension_latest.zip")
  • Useful to have a provide a link to the always latest version
  • Options used:
    • tmpDir
    • buildDir
    • packageName

Deployment

Publishing & Tools

Bump

Bumps the version in your package.json file

bump:patch

  • Changes the version in package.json from 0.2.1 to 0.2.2
  • Shortcuts: sense-go b or sense-go b:p

bump:minor

  • Changes the version in package.json from 0.2.1 to 0.3.1
  • Shortcut: sense-go b:min

bump:major

  • Changes the version in package.json from 0.2.1 to 1.0.0
  • Shortcut: sense-go b:maj

bump:version

  • Set the package.json version to a specific value given by the parameter --newversion resp. --nv.
  • Shortcut: sense-go b:v

Example:

$ sense-go bump:version --newversion=0.1.0
$ sense-go b:v --nv=0.1.0

Possible command line parameters

--tag

  • Tags the current version of your commit with the newly created version created by any of the bump-tasks.

--commit="Your commit message"

  • Commits all files with the given commit message, if no commit message is defined, "." will be committed as a message.

Task Chains

Based on gulp tasks provided by sense-go you can then create your task chains. Some are already predefined:

sense-go build

Task build as an example:

  gulp.task( 
    'build', 
    gulp.series( 
      'init', 
      'clean:tmp', 
      'copy:toTmp', 
      'replace:tmp', 
      'clean:buildDev', 
      'copy:tmpToDev', 
      'clean:localExtensionDir', 
      'deploy:tmpToLocal' 
      )
  );

The default task-chains are defined in the taskChains section in the default-config.yml file.

Modify existing task-chains (by configuration)

You can add additional task-chains or overwrite the existing ones in your project configuration file, e.g:

taskChains:
  ## Completely overwrite the existing "build" task
  "build":
    - "clean:tmp"
    - "copy:toTmp"
    - "copy:tmpToDev"
    - "deploy:toSsh"

Create/Modify task-chains (by code)

You can add additional tasks on top of sense-go, mixing your very own tasks with sense-go tasks, etc.

  • Always initialize a task chain with the init task
  • When creating your own tasks, note that sense-go relies on Gulp4

Example:

Use your own gulpfile.js (be aware that sense-go uses gulp 4.0 beta):

'use strict';
var senseGo = require( 'sense-go' );
var gulp = senseGo.gulp;
var path = require( 'path' );

var customConfig = senseGo.loadYml( path.join( __dirname, 'custom-config.yml') );

senseGo.init( customConfig,  function (  ) {
  
  gulp.task('myTask', function() {
    ...
  } );
  
  
  // Create your own task chain, and overwrite the current task chain 'build'
  gulp.task( 'build', gulp.series( 
    'init', 
    'clean:tmp', 
    'copy:toTmp', 
    'myTask'        // <== Load your own custom task and mix it with existing ones 
  ) );
  
  // Run your task
  gulp.series(['build'])();
    
});

Then run sense-go build in the CLI.

Used Gulp plugins

sense-go is heavily relying on existing gulp plugins. A big thank you to the authors of these plugins!!

General

Validation

Packaging

Transpilation

babel: Turn ES6 code into readable vanilla ES5 with source maps | homepage

About

Author

Stefan Walther

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue. The process for contributing is outlined below:

  1. Create a fork of the project
  2. Work on whatever bug or feature you wish
  3. Create a pull request (PR)

I cannot guarantee that I will merge all PRs but I will evaluate them all.

License

Copyright © 2019, Stefan Walther.
MIT


This file was generated by verb-generate-readme, v0.6.0, on January 25, 2019.

sense-go's People

Contributors

greenkeeper[bot] avatar renovate-bot avatar renovate[bot] avatar stefanwalther avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sense-go's Issues

.bin

Enable to use sense-go instead of gulp in each of the projects.

neither package.json nor .sense-go.yml available

I'm trying to start and use sense-go but for some reason i cant. I've made the same folder structure and placed package.json file in the root folder but when i try to start sense-go im getting:

[03:24:44] Using the default sense-go settings                                                                                                                                                    
[03:24:44]      neither package.json nor .sense-go.yml available) ...                                                                                                                             
[03:24:44] sense-go does not provide any default task out of the box. 

I've copied the default yml config file and then i'm getting:

[03:25:53] Using the .sense-go.local.yml file ...                                                                                                                                                 
[03:25:53] sense-go does not provide any default task out of the box.   

Is there anything else that need to be done after the initial installation or there is another step that im missing while i've prepared the project?

New tasks - Wishlist

Are there any tasks you are missing.

Here are some ideas of what I'd like to add:

  • Usage of webpack
  • postcss
  • Developing extensions in es6 and using babel
  • Developing extensions in TypeScript
  • CleanCss task

Please feel free to add your wishes and vote for the existing proposals!

Validations

  • eslint
  • yml validation
  • qext/json validation
  • html/css validation

Documentation 0.6

Concepts:

  • Installation
  • Deployment
  • Configuration
  • Overall workflow
  • Task chains

Tasks:

  • bump
  • clean
  • copy
  • git - actually not sure if really useful
  • htmlmin
  • import
  • jsonlint - It's there, but let's document it later, not really MVP
  • jsonminify
  • less
  • npm - It's there, but let's document it later, not really MVP
  • replace
  • ssh
  • transpile - actually not sure if really useful, so removed from doc
  • uglify
  • wbfolder
  • zip
  • watch

Version 10 of node.js has been released

Version 10 of Node.js (code name Dubnium) has been released! 🎊

To see what happens to your code in Node.js 10, Greenkeeper has created a branch with the following changes:

  • Replaced the old Node.js version in your .nvmrc with the new one
  • The new Node.js version is in-range for the engines in 1 of your package.json files, so that was left alone

If you’re interested in upgrading this repo to Node.js 10, you can open a PR with these changes. Please note that this issue is just intended as a friendly reminder and the PR as a possible starting point for getting your code running on Node.js 10.

More information on this issue

Greenkeeper has checked the engines key in any package.json file, the .nvmrc file, and the .travis.yml file, if present.

  • engines was only updated if it defined a single version, not a range.
  • .nvmrc was updated to Node.js 10
  • .travis.yml was only changed if there was a root-level node_js that didn’t already include Node.js 10, such as node or lts/*. In this case, the new version was appended to the list. We didn’t touch job or matrix configurations because these tend to be quite specific and complex, and it’s difficult to infer what the intentions were.

For many simpler .travis.yml configurations, this PR should suffice as-is, but depending on what you’re doing it may require additional work or may not be applicable at all. We’re also aware that you may have good reasons to not update to Node.js 10, which is why this was sent as an issue and not a pull request. Feel free to delete it without comment, I’m a humble robot and won’t feel rejected 🤖


FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Test Coverage

General:

  • Running with default configuration and default project
  • Run the full, typical task chain for visualization extensions

Tasks:

  • wbfolder ??
  • lessEach
  • lessReduce
  • clean
  • copy
  • htmlmin
  • import
  • replace
  • zip

Publish tasks

  • Bump new version
  • Run the necessary extended task chains
  • Upload to git
  • npm publish

Add `fixMetaData` to reflect changes in Qlik Sense 2.1

In Qlik Sense 2.1 a bunch of new meta-data entries are suggested and recommended to be used in the .qext file. Create a task adding them by default, partly also fetching - if possible - from the package.json file.

Dependency deprecation warning: gulp-util (npm)

On registry https://registry.npmjs.org/, the "latest" version (v3.0.8) of dependency gulp-util has the following deprecation notice:

gulp-util is deprecated - replace it, following the guidelines at https://medium.com/gulpjs/gulp-util-ca3b1f9f9ac5

Marking the latest version of an npm package as deprecated results in the entire package being considered deprecated, so contact the package author you think this is a mistake.

Please take the actions necessary to rename or substitute this deprecated package and commit to your base branch. If you wish to ignore this deprecation warning and continue using gulp-util as-is, please add it to your ignoreDeps array in Renovate config before closing this issue, otherwise another issue will be recreated the next time Renovate runs.

support for deployment to server using QRS

Hi Stefan,

I noticed in the code for this tool you currently have a note next to the QRS setup saying yet to be implemented. I was wondering how you are getting on with this? Is it possible, or is it something that could be a long way off being included. Nice job on the tool already though!

Thanks

Consolidation of internal naming

There is a discrepancy in the internal naming:

  • The config file uses the term deployment
  • Tasks are using the term deploy

As this is a potential breaking change (if users have already created custom taskChains), this needs to be part of a new major release.

Import task

Allow the user to import files automatically, ideal to be used in combination with external libraries from e.g. bower_components or node_modules.
#18 needs to be solved first.

.min.js for libraries

  • Support scenario where one just wants to create a min-file, distributed to the "dist" folder.

time-stamp dependency missing

I'm running node 4.4.7 and after npm install -g sense-go I've got a missing module error:
module.js:327
throw err;
^

Error: Cannot find module 'time-stamp'
at Function.Module._resolveFilename (module.js:325:15)
at Function.Module._load (module.js:276:25)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object. (C:\Users\aai\AppData\Roaming\npm\node_modules\sense-go\bin\log.js:4:17)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)

after adding this module it runs fine.

package name cannot be null or empty

Initialising sense-go or sense-go build within new project folder (empty) returns following error:

[10:54:53] .: STARTING SENSE-GO :.
[10:54:53] Using the default sense-go settings ...
[10:54:53] 	(neither package.json nor .sense-go.yml available ...)
[10:54:53] Validation: one or more error occurred:
[10:54:53]   - packageName cannot be null or empty.
[10:54:53] AssertionError [ERR_ASSERTION] Task never defined: default

Running sense-go or sense-go build with .sense-go.yml file in project folder results in same error.

NPM v6.9.0
Node v10.15.3

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.