Skip to content

Commit

Permalink
Merge pull request #19 from stealjs/main
Browse files Browse the repository at this point in the history
Copy over the options.main if it doesn't exist
  • Loading branch information
matthewp committed Mar 3, 2017
2 parents 8996634 + 12f4479 commit 414f66b
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 46 deletions.
13 changes: 12 additions & 1 deletion lib/configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ module.exports = function(root, options) {
.then(function(pkgSource){
var pkg = JSON.parse(pkgSource);
var setPkgMainPromise = Promise.resolve();
var copyElectronMainPromise = Promise.resolve();

var mainPath = path.join(root, optionsMain);
copyElectronMainPromise = asap(fse.readFile)(mainPath).then(null, function(){
// Doesn't exist, create it.
var electronMainPath = __dirname + "/../templates/electron-main.js";
return asap(fse.readFile)(electronMainPath, "utf8")
.then(function(mainSource){
return asap(fse.writeFile)(mainPath, mainSource, "utf8");
});
});

// We need to update the package.json if the main has changed.
var shouldUpdatePackageJSON = pkg.main !== optionsMain;
Expand All @@ -26,6 +37,6 @@ module.exports = function(root, options) {
setPkgMainPromise = asap(fse.writeFile)(pkgPath, pkgSource, "utf8");
}

return setPkgMainPromise;
return Promise.all([setPkgMainPromise, copyElectronMainPromise]);
});
};
13 changes: 11 additions & 2 deletions test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ exports.setup = function(projectPath, setup, dontFail){
this.oldPackageJSON = readFile(path.join(projectPath, "package.json"));

var electronOptions = {
main: "options.main",
main: "electron-main.js",
buildDir: './build',
platforms: ['darwin'],
files: ["dist/**/*", "production.html"]
files: ["dist/**/*", "production.html", "electron-main.js"]
};

var buildResult = {
Expand All @@ -74,13 +74,22 @@ exports.setup = function(projectPath, setup, dontFail){
var fail = function(err){
if(!dontFail) {
done(err);
return;
}
this.buildError = err;
done();
}.bind(this);
stealElectron(electronOptions, buildResult).then(fin, fail);
});

afterEach(function(done){
exports.rmdir(path.join(projectPath, "electron-main.js"))
.then(null, function(){})
.then(function(){
done();
});
});

after(function(done){
writeFile(path.join(projectPath, "package.json"), this.oldPackageJSON);

Expand Down
3 changes: 2 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ describe("steal-electron", function(){

it("Copies over the production files", function(){
assert(exists(__dirname + "/tests/app/build/test/tests/app/production.html"));
assert(exists(__dirname + "/tests/app/build/test/tests/app/electron-main.js"));
});

it("Adds env=electron-production to the steal script tag", function(){
Expand Down Expand Up @@ -55,7 +56,7 @@ describe("steal-electron", function(){

describe("An app with an alternative HTML file", function(){
helpers.setup(__dirname + "/tests/app", function(options){
var idx = options.files.indexOf("production");
var idx = options.files.indexOf("production.html");
options.files.splice(idx, 1, "other-production.html");
options.indexPage = "other-production.html";
});
Expand Down
41 changes: 0 additions & 41 deletions test/tests/app/electron-main.js

This file was deleted.

2 changes: 1 addition & 1 deletion test/tests/app/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "app",
"main": "electron-main.js",
"main": "some-main.js",
"version": "1.0.0"
}

0 comments on commit 414f66b

Please sign in to comment.