Skip to content

Commit

Permalink
chore: update build scripts (qlik-oss#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
cbt1 authored May 9, 2022
1 parent 9949250 commit 0802bb7
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ dist/
sn-pivot-table-ext/
coverage/
example/
core/esm/
8 changes: 8 additions & 0 deletions core/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"module": "esm/index.js",
"peerDependencies": {
"@nebula.js/stardust": "2.x",
"react": "^17.0.2",
"react-dom": "^17.0.2"
}
}
4 changes: 0 additions & 4 deletions nebula.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
const path = require('path');

const { version } = require(path.resolve(__dirname, './package.json')); // eslint-disable-line
const mode = process.env.NODE_ENV === 'production' ? 'production' : 'development';
const sourcemap = mode !== 'production';

module.exports = {
build: {
sourcemap,
mode,
typescript: true,
replacementStrings: {
'process.env.PACKAGE_VERSION': JSON.stringify(version),
Expand Down
21 changes: 16 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,32 @@
"nebula",
"stardust"
],
"bugs": {
"url": "https://github.com/qlik-oss/sn-pivot-table/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/qlik-oss/sn-pivot-table.git"
},
"files": [
"api-specifications",
"core",
"dist",
"sn-pivot-table-ext",
"api-specifications"
"sn-pivot-table-ext"
],
"engines": {
"node": ">=8"
},
"main": "dist/sn-pivot-table.js",
"module": "dist/sn-pivot-table.esm.js",
"module": "core/esm/index.js",
"scripts": {
"build": "nebula build",
"build": "node ./scripts/build.js --core --ext",
"build:dev": "node ./scripts/build.js --core --mode development",
"build:watch": "node ./scripts/build.js --mode development -w",
"copy:ext": "node ./scripts/copy-ext.js",
"lint": "eslint src/",
"start": "nebula serve",
"sense": "nebula sense --sourcemap true --meta src/meta.json",
"sense": "nebula sense",
"types:check": "tsc --noEmit",
"test": "jest",
"spec": "scriptappy-from-jsdoc -c ./scriptappy.config.js"
Expand Down
60 changes: 60 additions & 0 deletions scripts/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#! /usr/bin/env node
/* eslint-disable no-console */

const yargs = require('yargs');
const fs = require('fs-extra');
const path = require('path');
const build = require('@nebula.js/cli-build');
const sense = require('@nebula.js/cli-sense');

const args = yargs(process.argv.slice(2)).argv;
const buildExt = args.ext;
const buildCore = args.core;
const mode = args.mode || 'production';
const watch = args.w;
const sourcemap = mode !== 'production';

// cleanup old build
fs.removeSync(path.resolve(process.cwd(), 'dist'));
fs.removeSync(path.resolve(process.cwd(), 'core/esm'));
if (buildExt) {
fs.removeSync(path.resolve(process.cwd(), 'sn-pivot-table-ext'));
}

const buildArgs = {};

const buildExtension = async () => {
console.log('---> BUILDING EXTENSION');
await sense({ output: 'sn-pivot-table-ext', sourcemap });
};

if (buildCore) {
buildArgs.core = 'core';
}

if (mode === 'production') {
buildArgs.sourcemap = false;
} else {
buildArgs.mode = mode;
}

if (watch) {
buildArgs.watch = true;
}

const main = async () => {
console.log('---> BUILDING SUPERNOVA');
const watcher = await build(buildArgs);
if (buildExt) {
buildExtension();
if (watch) {
watcher.on('event', (event) => {
if (event.code === 'BUNDLE_END') {
buildExtension();
}
});
}
}
};

main();
23 changes: 23 additions & 0 deletions scripts/copy-ext.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* eslint-disable no-console */
const path = require('path');
const os = require('os');
const fs = require('fs-extra');

function copyExt() {
const targetPath = [os.homedir(), 'Qlik', 'Sense', 'Extensions', 'sn-pivot-table-ext'];
if (os.platform() === 'win32') {
targetPath.splice(1, 0, 'Documents');
}

const target = path.resolve(...targetPath);

fs.copySync(path.resolve(process.cwd(), 'sn-pivot-table-ext'), target);
console.log('Copied into Extensions folder!');
}

if (require.main === module) {
// execute if running directly from CLI
copyExt();
}

module.exports = copyExt;
5 changes: 0 additions & 5 deletions src/meta.json

This file was deleted.

0 comments on commit 0802bb7

Please sign in to comment.