This repository has been archived by the owner on Mar 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from FormidableLabs/chore-global-local-installs
Add local detect and switch for builder.
- Loading branch information
Showing
3 changed files
with
52 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
"use strict"; | ||
|
||
module.exports = function (callback) { | ||
/*eslint-disable global-require*/ | ||
// Configuration | ||
var Config = require("../lib/config"); | ||
var config = new Config(); | ||
|
||
// Set up environment | ||
var Environment = require("../lib/environment"); | ||
var env = new Environment({ | ||
config: config | ||
}); | ||
|
||
// Infer task to run | ||
var Task = require("../lib/task"); | ||
var task = new Task({ | ||
config: config, | ||
env: env | ||
}); | ||
|
||
// Run the task | ||
task.execute(callback); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,27 @@ | ||
#!/usr/bin/env node | ||
"use strict"; | ||
|
||
// Configuration | ||
var Config = require("../lib/config"); | ||
var config = new Config(); | ||
var path = require("path"); | ||
var log = require("../lib/log"); | ||
|
||
// Set up environment | ||
var Environment = require("../lib/environment"); | ||
var env = new Environment({ | ||
config: config | ||
}); | ||
// Infer if we are global and there is a local version available. | ||
var builderPath = require.resolve("./builder-core"); | ||
var localPath = path.resolve(process.cwd(), "node_modules/builder/bin/builder-core.js"); | ||
|
||
// Infer task to run | ||
var Task = require("../lib/task"); | ||
var task = new Task({ | ||
config: config, | ||
env: env | ||
}); | ||
// Swap to local path if different. | ||
if (builderPath !== localPath) { | ||
try { | ||
builderPath = require.resolve(localPath); | ||
log.info("local-detect", "Switched to local builder at: " + localPath); | ||
} catch (err) { | ||
log.warn("local-detect", "Error importing local builder: " + err.message); | ||
log.info("local-detect", "Using global builder at: " + builderPath); | ||
} | ||
} | ||
|
||
// Run the task | ||
task.execute(function (err) { | ||
// Import and run. | ||
var builder = require(builderPath); | ||
builder(function (err) { | ||
/*eslint-disable no-process-exit*/ | ||
process.exit(err ? err.code || 1 : 0); | ||
}); |