<|start_filename|>test/test.js<|end_filename|>
const expect = require('chai').expect;
const _ = require('../lib/bundle');

const packageVersion = process.env.npm_package_version || require('../package.json')['version'];


describe('macSignatureInstaller()', function () {

	context('when message contains the EOM keyword EndOfStaticRawSignature', function() {
		it('should throw an Error', function () {
			expect(function () { _('...\n...EndOfStaticRawSignature...\n...') }).to.throw(Error, /must not include/);
		});
	});

	context('when message is an empty string', function() {
		const result = _('');

		it('should return a non-empty string', function () {
			expect(result).to.be.a('string').which.is.not.empty;
		});

		it('should contain the version number of the package', function () {
			expect(result).to.have.string('\nVersion ' + packageVersion + ' - Copyright');
		});
	});

	context('when message is a non-empty string and not the EOM keyword', function() {
		const randomMessage = 'The time is: ' + new Date().toISOString();
		const resultWithString = _(randomMessage);
		const resultWithEmptyString = _('');

		it('should return a non-empty string', function () {
			expect(resultWithString).to.be.a('string').which.is.not.empty;
		});

		it('should contain the message', function () {
			expect(resultWithString).to.have.string(randomMessage);
		});

		it('should only differ in length by the length of the message + 1 line break', function () {
			expect(resultWithString).to.have.lengthOf(resultWithEmptyString.length + randomMessage.length + 1);
		});

		it('should have the message wrapped in the EOM keyword', function () {
			expect(resultWithString).to.have.string('RAW_SIGNATURE << EndOfStaticRawSignature\n' + randomMessage + '\nEndOfStaticRawSignature\n');
		});
	});

});


<|start_filename|>webpack.config.js<|end_filename|>
const webpack = require('webpack');
const path = require('path');

const config = {
	target: 'node',
	context: path.join(__dirname, 'src'),
	entry: './macSignatureInstaller.js',
	output: {
		path: path.join(__dirname, 'lib'),
		filename: 'bundle.js',
		libraryTarget: 'commonjs2',
	},
	module: {
		loaders: [
			{
				test: /\.js$/,
				exclude: /node_modules/,
				loader: 'babel-loader',
				query: {
					presets: ['es2015', 'stage-0'],
				}
			},
		]
	},
	plugins: [
		new webpack.optimize.UglifyJsPlugin({
			mangle: true,
			sourcemap: false,
		}),
	]
};

module.exports = config;


<|start_filename|>src/macSignatureInstaller.js<|end_filename|>
/**!
 * HTML Email Signature Installer for Mail.app (macOS)
 * Copyright (c) 2016 Cloud Under Ltd
 * @license MIT
 */

const shellScript = require('raw!../mac-signature-installer.command');
const keyword = 'EndOfStaticRawSignature';
const search = `${keyword}\n${keyword}`;

/**
 * Put in the signature encoded as email message and you'll get the
 * installer Bash script returned, with the signature embedded.
 */
function macSignatureInstaller(message) {
	if (message.includes(keyword)) {
		throw new Error(`String must not include the word ${keyword}`);
	}
	return message ? shellScript.replace(search, `${keyword}\n${message}\n${keyword}`) : shellScript;
};

module.exports = macSignatureInstaller;


<|start_filename|>package.json<|end_filename|>
{
  "name": "mac-signature-installer",
  "version": "0.2.0",
  "description": "Script helping to install HTML email signatures in Mail.app on macOS",
  "main": "lib/bundle.js",
  "scripts": {
    "compile": "webpack",
    "prepublish": "npm run compile",
    "test": "npm run compile && mocha"
  },
  "author": "Cloud Under Ltd",
  "license": "MIT",
  "keywords": [
    "mail",
    "macos",
    "osx",
    "mac",
    "email",
    "signature",
    "bash",
    "shell"
  ],
  "devDependencies": {
    "babel-core": "^6.18.2",
    "babel-loader": "^6.2.8",
    "babel-preset-es2015": "^6.18.0",
    "babel-preset-stage-0": "^6.16.0",
    "chai": "^3.5.0",
    "mocha": "^3.1.2",
    "raw-loader": "^0.5.1",
    "webpack": "^1.13.3"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/CloudUnder/mac-signature-installer.git"
  },
  "bugs": {
    "url": "https://github.com/CloudUnder/mac-signature-installer/issues"
  }
}
