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

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
igorklopov committed Aug 8, 2016
0 parents commit 42d2b2e
Show file tree
Hide file tree
Showing 1,016 changed files with 28,238 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/build/node
/examples/06-http-server-w-assets/assets
/examples/26-sails
/node_modules
/node_repository
/test/test-50-many-arrow-functions/test-x-index.js
/test/test-50-no-super-in-constructor/test-x-index.js
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/bin/binaries.json
/bin/house*
/bin/enclose*.exe
/bin/enclose-*-linux-*
/bin/enclose-*-darwin-*
/build/node
/node_modules
/node_repository
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*
167 changes: 167 additions & 0 deletions bin/enclose-exe-cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
#!/usr/bin/env node

"use strict";

var path = require("path");
var windows = process.platform === "win32";
var reporter = require("../lib/reporter.js");

function defined(v) {
if (v === null) return false;
if (typeof v === "undefined") return false;
return true;
}

var optionator = require("optionator")({
prepend:
"enclose@" + process.versions.enclose + "\n" +
"Usage: " +
"enclose [options] input",
options: [ {
option: "output",
alias: "o",
type: "String",
description: "name of output executable"
}, {
option: "arch",
alias: "a",
type: "String",
description: "arch of executable: x86 or x64"
}, {
option: "version",
alias: "v",
type: "String",
description: "node version to put into exe"
}, {
option: "loglevel",
alias: "l",
type: "String",
description: "'error', 'warning' or 'info'"
}, {
option: "config",
alias: "c",
type: "String",
description: "config file with includes"
}, {
option: "color",
type: "Boolean",
description: "force using color in console"
}, {
option: "no-color",
type: "Boolean",
description: "disable color in console"
} ]
});

var opts = optionator.parse(
process.argv
);

var cli = {};

if (opts._.length > 1) {
throw new Error(
"Only one input file is expected. " +
"But " + JSON.stringify(opts._) + " is passed"
);
}

if (opts._.length > 0) {
cli.input = opts._[0];
}

if (defined(opts.loglevel)) {
cli.loglevel = opts.loglevel;
}

if (defined(opts.output)) {
cli.output = opts.output;
}

if (defined(opts.config)) {
cli.config = opts.config;
}

// ///////////////////////////////////////////////////////////////////
// ///////////////////////////////////////////////////////////////////
// ///////////////////////////////////////////////////////////////////

if (defined(cli.input)) {
cli.input = path.resolve(cli.input);
}

if (defined(cli.output)) {
cli.output = path.resolve(cli.output);
}

if (defined(cli.config)) {
cli.config = path.resolve(cli.config);
}

// ///////////////////////////////////////////////////////////////////
// ///////////////////////////////////////////////////////////////////
// ///////////////////////////////////////////////////////////////////

if (!defined(cli.input)) {
reporter.output(optionator.generateHelp());
process.exit();
}

function outputFromInput(input) {
var ext;
if (input.slice(-3) === ".js") {
ext = windows ? ".exe" : "";
return input.slice(0, -3) + ext;
} else {
ext = windows ? ".exe" : ".out";
return input + ext;
}
}

if (defined(cli.input) && !defined(cli.output)) {
var dni = path.dirname(cli.input);
var bni = path.basename(cli.input);
cli.output = path.join(dni, outputFromInput(bni));
}

// ///////////////////////////////////////////////////////////////////
// ///////////////////////////////////////////////////////////////////
// ///////////////////////////////////////////////////////////////////

if (defined(cli.input)) {
if (typeof cli.input !== "string") {
throw new Error(
"'input' must be of type 'string'"
);
}
}

if (defined(cli.loglevel)) {
if (typeof cli.loglevel !== "string") {
throw new Error(
"'loglevel' must be of type 'string'"
);
}
}

if (defined(cli.output)) {
if (typeof cli.output !== "string") {
throw new Error(
"'output' must be of type 'string'"
);
}
}

if (defined(cli.config)) {
if (typeof cli.config !== "string") {
throw new Error(
"'config' must be of type 'string'"
);
}
}

module.exports = cli;

if (!module.parent) {
reporter.output(cli);
}
110 changes: 110 additions & 0 deletions bin/enclose-exe.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#!/usr/bin/env node

/* eslint-disable no-bitwise */

"use strict";

var fs = require("fs");
var path = require("path");
var async = require("async");
var windows = process.platform === "win32";

var bundler = require("../lib/bundler.js");
var producer = require("../lib/producer.js");
var reporter = require("../lib/reporter.js");

var cli;

async.waterfall([
function(next) {

try {
cli = require("./enclose-exe-cli.js");
return next();
} catch (error) {
reporter.report("", "error", error.message, error);
return next(error);
}

},
function(next) {

// loglevel must be set as early as possible

if (cli.loglevel) {
if (!reporter.isCorrectLevel(cli.loglevel)) {
var error = new Error("Bad loglevel: " + cli.loglevel);
reporter.report("", "error", error.message, error);
return next(error);
}
reporter.level = cli.loglevel;
}

next();

},
function(next) {

var home = path.dirname(process.argv[1]);
var dictionary = path.join(home, "..", "dictionary");

if (!fs.existsSync(dictionary)) {
var error = new Error("Dictionary directory not found");
reporter.report("", "error", error.message, error);
return next(error);
}

next();

},
function(next) {

bundler({
cli: cli
}, next);

},
function(stripe, next) {

var pathToHouseSize = path.join(__dirname, "house.size");
var houseSize = fs.readFileSync(pathToHouseSize, "utf8") | 0;

producer({
stripe: stripe,
houseSize: houseSize
}, next);

},
function(product, next) {

fs.writeFile(cli.output, product, next);

},
function(next) {

if (!windows) {
return fs.stat(cli.output, function(error, stat) {
if (error) return next(error);
var plusx = (stat.mode | 64 | 8).toString(8).slice(-3);
fs.chmod(cli.output, plusx, next);
});
}

next();

}
], function(error) {

process.once("exit", function() {
reporter.finish();
if (error && error.wasReported) {
process.exit(1);
}
});

if (error) {
if (error.wasReported) return;
throw error;
}

});
Loading

0 comments on commit 42d2b2e

Please sign in to comment.