Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
idleberg committed Aug 11, 2017
0 parents commit 89233e3
Show file tree
Hide file tree
Showing 14 changed files with 465 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# dependencies
bower_components/
node_modules/
vendor/

# package manager files
npm-debug.log*
package-lock.json
yarn-error.log

# project specific
*.exe
todo.md
6 changes: 6 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.travis.yml
gulpfile.json
gulpfile.json
tsconfig.json
tslint.json
yarn.lock
24 changes: 24 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
sudo: false
language: node_js
node_js:
- "6"
git:
depth: 1
branches:
only:
- master
cache:
timeout: 1800
yarn: true
directories:
- node_modules
env:
- CXX=g++-4.8
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.8
notifications:
email: false
9 changes: 9 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
The MIT License (MIT)

Copyright (c) 2017 Jan T. Sott

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# makensis

[![npm](https://img.shields.io/npm/l/makensis.svg?style=flat-square)](https://www.npmjs.org/package/makensis)
[![npm](https://img.shields.io/npm/v/makensis.svg?style=flat-square)](https://www.npmjs.org/package/makensis)
[![Travis](https://img.shields.io/travis/idleberg/node-makensis.svg?style=flat-square)](https://travis-ci.org/idleberg/node-makensis)
[![David](https://img.shields.io/david/idleberg/node-makensis.svg?style=flat-square)](https://david-dm.org/idleberg/node-makensis)
[![David](https://img.shields.io/david/dev/idleberg/node-makensis.svg?style=flat-square)](https://david-dm.org/idleberg/node-makensis?type=dev)

A Node wrapper for `makensis`, the NSIS compiler

## Installation

`npm install -g -makensis`

## Usage

```js
import { compiler as makensis} from 'makensis';
const options = {
verbose: 2,
define: {
'SPECIAL_BUILD': true
}
}

makensis.compile('/path/to/installer.nsi', options)
}).catch((err) => {
console.error(err);
});
```

### Methods

`compile(script, [options])`

Compile specified script with MakeNSIS

`version()`

Returns version of MakeNSIS

`cmdhelp([command])`

Returns usage information for a specific command, or a list all commands

## License

This work is licensed under [The MIT License](https://opensource.org/licenses/MIT)

## Donate

You are welcome support this project using [Flattr](https://flattr.com/submit/auto?user_id=idleberg&url=https://github.com/idleberg/node-makensis) or Bitcoin `17CXJuPsmhuTzFV2k4RKYwpEHVjskJktRd`
49 changes: 49 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* vscode-gulpfile.js
*
* Copyright (c) 2016, 2017 Jan T. Sott
* Licensed under the MIT license.
*/

// Dependencies
const gulp = require('gulp');
const debug = require('gulp-debug');
const tslint = require('gulp-tslint');
const jsonlint = require('gulp-jsonlint');

// Supported files
const tsFiles = [
'src/*.ts',
];

const jsonFiles = [
'package.json',
'tsconfig.json',
'tslint.json'
];

// Lint TypeScript
gulp.task('lint:ts', gulp.series( (done) => {
gulp.src(tsFiles)
.pipe(debug({title: 'tslint'}))
.pipe(tslint({
formatter: "prose"
}))
.pipe(tslint.report())
done();
}));

// Lint JSON
gulp.task('lint:json', gulp.series( (done) => {
gulp.src(jsonFiles)
.pipe(debug({title: 'json-lint'}))
.pipe(jsonlint())
.pipe(jsonlint.failAfterError())
.pipe(jsonlint.reporter());
done();
}));

// Available tasks
gulp.task('lint', gulp.parallel('lint:ts', 'lint:json', (done) => {
done();
}));
63 changes: 63 additions & 0 deletions lib/makensis.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var util_1 = require("./util");
/**
* Returns usage information for a command, or list all commands
* @param {string} [command] - an NSIS command
* @returns {string} - usage description
*/
var cmdhelp = function (command) {
if (command === void 0) { command = ''; }
var args = ['-CMDHELP'];
if (typeof command !== 'undefined' && command !== '') {
args.push(command);
}
return util_1.spawnMakensis(args);
};
exports.cmdhelp = cmdhelp;
/**
* Compile specified script with MakeNSIS
* @param {string} script - path to NSIS script
* @param {Object} options - compiler options
*/
var compile = function (script, options) {
if (options === void 0) { options = null; }
options || (options = {});
var args = [];
if (Number.isInteger(options.verbose) && options.verbose >= 0 && options.verbose <= 4) {
args.push('-V' + options.verbose);
}
if (options.pause === true) {
args.push('-PAUSE');
}
if (options.nocd === true) {
args.push('-NOCD');
}
if (options.noconfig === true) {
args.push('-NOCONFIG');
}
if (options.strict === true) {
args.push('-WX');
}
if (typeof options.define !== 'undefined') {
Object.keys(options.define).forEach(function (key) {
args.push("-D" + key + "=" + options.define[key]);
});
}
if (typeof options.execute !== 'undefined') {
options.execute.forEach(function (key) {
args.push("-X" + key);
});
}
args.push(script);
return util_1.spawnMakensis(args);
};
exports.compile = compile;
/**
* Returns version of MakeNSIS
* @returns {string} - compiler version
*/
var version = function () {
return util_1.spawnMakensis(['-VERSION']);
};
exports.version = version;
28 changes: 28 additions & 0 deletions lib/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var makensis = require("./makensis");
var options = {
verbose: 2,
define: {
'SHOW_WARNING': 'true'
},
execute: [
'OutFile inst.exe'
]
};
makensis.compile('/Users/jan/Desktop/_nsis/error.nsi', options)
.then(function (stdStream) {
console.log(stdStream);
}).catch(function (stdErr) {
console.error(stdErr);
});
// makensis.version().then((version) => {
// console.log(version);
// }).catch((error) => {
// console.error(error);
// });
// makensis.cmdhelp('OutFile').then((version) => {
// console.log(version);
// }).catch((error) => {
// console.error(error);
// });
29 changes: 29 additions & 0 deletions lib/util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var child_process_1 = require("child_process");
var stringify = function (data) {
return data.toString().trim();
};
exports.stringify = stringify;
var spawnMakensis = function (args) {
return new Promise(function (resolve, reject) {
var stdOut = '';
var stdErr = '';
var cmd = child_process_1.spawn('makensis', args);
cmd.stdout.on('data', function (data) {
stdOut += stringify(data);
});
cmd.stderr.on('data', function (data) {
stdErr += stringify(data);
});
cmd.on('close', function (code) {
if (code === 0) {
resolve(stdOut);
}
else {
reject(stdErr);
}
});
});
};
exports.spawnMakensis = spawnMakensis;
26 changes: 26 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "makensis",
"version": "0.0.0",
"description": "",
"main": "lib/makensis.js",
"keywords": [
"nsis",
"makensis"
],
"author": "",
"license": "MIT",
"devDependencies": {
"@types/node": "^8.0.19",
"gulp": "github:gulpjs/gulp#4.0",
"gulp-debug": "^3.1.0",
"gulp-jsonlint": "^1.2.0",
"gulp-tslint": "^8.1.1",
"tslint": "^5.5.0",
"typescript": "^2.3.4"
},
"scripts": {
"build": "tsc -p ./",
"prepublish": "npm run build",
"test": "gulp lint"
}
}
82 changes: 82 additions & 0 deletions src/makensis.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { spawnMakensis } from './util';

interface CompilerOptions {
define?: Object;
execute?: Array<string>;
nocd?: boolean;
noconfig?: boolean;
pause?: boolean;
strict?: boolean;
verbose?: number;
}

/**
* Returns usage information for a command, or list all commands
* @param {string} [command] - an NSIS command
* @returns {string} - usage description
*/
const cmdhelp = (command: string = '') => {
let args: Array<string> = ['-CMDHELP'];

if (typeof command !== 'undefined' && command !== '') {
args.push(command);
}
return spawnMakensis(args);
};

/**
* Compile specified script with MakeNSIS
* @param {string} script - path to NSIS script
* @param {Object} options - compiler options
*/
const compile = (script: string, options: CompilerOptions = null) => {
options || (options = {});

let args: Array<string> = [];

if (Number.isInteger(options.verbose) && options.verbose >= 0 && options.verbose <= 4) {
args.push('-V' + options.verbose);
}

if (options.pause === true) {
args.push('-PAUSE');
}

if (options.nocd === true) {
args.push('-NOCD');
}

if (options.noconfig === true) {
args.push('-NOCONFIG');
}

if (options.strict === true) {
args.push('-WX');
}

if (typeof options.define !== 'undefined') {
Object.keys(options.define).forEach(function(key) {
args.push(`-D${key}=${options.define[key]}`);
});
}

if (typeof options.execute !== 'undefined') {
options.execute.forEach(function(key) {
args.push(`-X${key}`);
});
}

args.push(script);

return spawnMakensis(args);
};

/**
* Returns version of MakeNSIS
* @returns {string} - compiler version
*/
const version = () => {
return spawnMakensis(['-VERSION']);
};

export { compile, cmdhelp, version };
Loading

0 comments on commit 89233e3

Please sign in to comment.