Skip to content
This repository has been archived by the owner on May 5, 2024. It is now read-only.

Commit

Permalink
#13: Remove prerequisite on wixtoolset
Browse files Browse the repository at this point in the history
  • Loading branch information
nbarikipoulos committed Nov 22, 2020
1 parent eff6ee4 commit dfa06c6
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules/
wix_bin/

.DS_Store
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,13 @@

Package node.js application to a standalone executable and pack it into a msi installer (Windows only).

- Create a binary which does not require node,
- Create a standalone binary that does not require node,
- Pack it in a windows msi installer that:
- Extract info from package.json such as bin name, provider's name, and so on,
- Automatically create a license panel in installer from LICENSE/LICENSE.md file, if any,
- Automatically create in the windows start menu an entry that contains link to the homepage URL filled in package.json or provided in cli,
- Automatically update the PATH environmement variable with the install folder.

## Prerequisite

MSI build step is based on the wix toolset project and then, it should be installed. see [here](https://wixtoolset.org).
This module has been "tested" with the WIX release 3.11.2.

## Install

As this module introduces a contraints to both target os and arch (respectively win32 and x64), install it globally, as an optional dependency or launch it using npx to avoid to constrain your module with these settings.
Expand Down
10 changes: 4 additions & 6 deletions lib/config/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

const fs = require('fs')
const path = require('path').win32

const { validate: uuidValidate } = require('uuid')
const { isWebUri } = require('valid-url')

const { factory: validator, createValidator } = require('../../util/update-validate')
const { innerPath } = require('../../util/misc')

module.exports = (config) => {
const unv = validator(INPUT_DESCRIPTORS)
Expand Down Expand Up @@ -135,14 +135,12 @@ const getPackage = _ => {

const PACKAGE = getPackage()

const root = path.join(__dirname, '../..')

const DEFAULT = {
skipLicense: false,
buildDir: 'build',
icon: path.join(root, 'assets/prompt.png'),
banner: path.join(root, 'assets/banner.jpg'),
background: path.join(root, 'assets/background.jpg')
icon: innerPath('assets/prompt.png'),
banner: innerPath('assets/banner.jpg'),
background: innerPath('assets/background.jpg')
}

const isFileExists = (value) => createValidator(
Expand Down
14 changes: 10 additions & 4 deletions lib/ops.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,32 @@

'use strict'

const { promisify } = require('util')
const execFile = promisify(require('child_process').execFile)
const { promises: pfs } = require('fs')
const path = require('path').win32
const { exec: execPack } = require('pkg')
const { promisify } = require('util')
const execFile = promisify(require('child_process').execFile)
const createWXS = require('./wxs')
const createLicense = require('./license')
const ico = require('./ico')

const { WIX_FOLDER } = require('../util/misc')

const candleExePath = path.join(WIX_FOLDER, 'candle')
const lightExePath = path.join(WIX_FOLDER, 'light')

const createDir = (path) => pfs.mkdir(path, { recursive: true })

const pack = (entry, exe) => execPack([entry, '--targets', 'win-x64', '--output', exe])

const candle = (wxs, wxsobj) => execFile('candle', [
const candle = (wxs, wxsobj) => execFile(candleExePath, [
wxs,
'-arch', 'x64',
'-ext', 'WiXUtilExtension',
'-out', wxsobj
])

const light = (wxsobj, msi) => execFile('light', [
const light = (wxsobj, msi) => execFile(lightExePath, [
wxsobj,
'-ext', 'WiXUtilExtension',
'-ext', 'WiXUIExtension',
Expand Down
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"name": "wix-msi",
"version": "0.2.0",
"description": "Package node.js application to a standalone executable (i.e. that does not require node.js installed) and pack it into a msi installer",
"description": "Package node.js application to a standalone executable and pack it into a msi installer",
"bin": {
"wix-msi": "./bin/cli.js"
},
"main": "index.js",
"scripts": {
"postinstall": "node ./wix-install.js",
"test": "standard"
},
"homepage": "https://github.com/nbarikipoulos/wix-msi#readme",
Expand All @@ -26,11 +27,13 @@
],
"dependencies": {
"acorn": "^8.0.4",
"axios": "^0.21.0",
"colors": "^1.4.0",
"jimp": "^0.16.1",
"mustache": "^4.0.1",
"pkg": "^4.4.9",
"png-to-ico": "^2.1.1",
"unzipper": "^0.10.11",
"uuid": "^8.3.0",
"valid-url": "^1.0.9",
"xmlbuilder2": "^2.3.1",
Expand All @@ -43,7 +46,8 @@
"/lib",
"/util",
"/cli",
"/assets"
"/assets",
"/wix-install.js"
],
"repository": {
"type": "git",
Expand Down
8 changes: 7 additions & 1 deletion util/misc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*! Copyright (c) 2020 Nicolas Barriquand <nicolas.barriquand@outlook.fr>. MIT licensed. */

const path = require('path')
const acorn = require('acorn')

const getFuncArgs = (func) => acorn.parse(func, { ecmaVersion: 'latest' })
Expand All @@ -9,12 +10,17 @@ const getFuncArgs = (func) => acorn.parse(func, { ecmaVersion: 'latest' })
.map(n => n.name)
.filter(v => v !== '_')

const MODULE_ROOT_PATH = path.join(__dirname, '..')
const innerPath = (...innerPaths) => path.join(MODULE_ROOT_PATH, ...innerPaths)

// ////////////////////////////////
// ////////////////////////////////
// Public API
// ////////////////////////////////
// ////////////////////////////////

module.exports = {
getFuncArgs
getFuncArgs,
innerPath,
WIX_FOLDER: innerPath('wix_bin')
}
16 changes: 16 additions & 0 deletions wix-install.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*! Copyright (c) 2020 Nicolas Barriquand <nicolas.barriquand@outlook.fr>. MIT licensed. */

'use strict'

const axios = require('axios')
const unzipper = require('unzipper')
const { WIX_FOLDER } = require('./util/misc')

const url = 'https://github.com/wixtoolset/wix3/releases/download/wix3112rtm/wix311-binaries.zip'

const f = async _ => {
const data = (await axios({ url, method: 'get', responseType: 'stream' })).data
data.pipe(unzipper.Extract({ path: WIX_FOLDER }))
}

f()

0 comments on commit dfa06c6

Please sign in to comment.