Skip to content

Commit

Permalink
Feature: add offline mode (#260)
Browse files Browse the repository at this point in the history
* add options for offline mode

* add option for a custom download directory
  • Loading branch information
spjuanjoc committed Oct 15, 2021
1 parent 059ad3e commit 7f26aae
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 6 deletions.
6 changes: 6 additions & 0 deletions lib/buildSystem.js
Expand Up @@ -3,6 +3,7 @@ let CMake = require("./cMake");
let Dist = require("./dist");
let CMLog = require("./cmLog");
let appCMakeJSConfig = require("./appCMakeJSConfig");
let npmConfig = require("./npmConfig");
let path = require("path");
let _ = require("lodash");
let Toolset = require("./toolset");
Expand All @@ -12,6 +13,11 @@ function BuildSystem(options) {
this.options.directory = path.resolve(this.options.directory || process.cwd());
this.log = new CMLog(this.options);
let appConfig = appCMakeJSConfig(this.options.directory, this.log);
let npmOptions = npmConfig(this.log);

if (_.isPlainObject(npmOptions) && _.keys(npmOptions).length) {
this.options.runtimeDirectory = npmOptions["nodedir"];
}
if (_.isPlainObject(appConfig)) {
if (_.keys(appConfig).length) {
this.log.verbose("CFG", "Applying CMake.js config from root package.json:");
Expand Down
16 changes: 10 additions & 6 deletions lib/dist.js
Expand Up @@ -30,11 +30,15 @@ function Dist(options) {
Object.defineProperties(Dist.prototype, {
internalPath: {
get: function () {
return path.join(
environment.home,
".cmake-js",
(this.targetOptions.runtime) + "-" + this.targetOptions.arch,
"v" + this.targetOptions.runtimeVersion);
let cacheDirectory = ".cmake-js";
let runtimeArchDirectory = (this.targetOptions.runtime) + "-" + this.targetOptions.arch;
let runtimeVersionDirectory = "v" + this.targetOptions.runtimeVersion;

return this.options.runtimeDirectory ||
path.join(environment.home,
cacheDirectory,
runtimeArchDirectory,
runtimeVersionDirectory);
}
},
externalPath: {
Expand Down Expand Up @@ -107,7 +111,7 @@ Dist.prototype.ensureDownloaded = async function () {

Dist.prototype.download = async function () {
let log = this.log;
log.info("DIST", "Downloading distribution files.");
log.info("DIST", "Downloading distribution files to: " + this.internalPath);
await fs.ensureDir(this.internalPath);
let sums = await this._downloadShaSums();
await Promise.all([this._downloadLibs(sums), this._downloadTar(sums)]);
Expand Down
31 changes: 31 additions & 0 deletions lib/npmConfig.js
@@ -0,0 +1,31 @@
"use strict";

function getNpmConfig() {
let npmOptions = {};
let npmConfigPrefix = 'npm_config_'
Object.keys(process.env).forEach(function (name) {
if (name.indexOf(npmConfigPrefix) !== 0) {
return
}
let value = process.env[name]
name = name.substring(npmConfigPrefix.length)
if (name) {
npmOptions[name] = value
}
}, this)

return npmOptions;
}

module.exports = function (log) {
log.verbose("CFG", "Looking for NPM config.");
let options = getNpmConfig();

if (options) {
log.silly("CFG", "NPM options:", options);
}else {
log.verbose("CFG", "There are no NPM options available.");
}

return options;
};

0 comments on commit 7f26aae

Please sign in to comment.