Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partially working example of getting volo.url from package.json for private repos #162

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
229 changes: 115 additions & 114 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,117 +7,118 @@
/*jslint node: true */
/*global console */

'use strict';
var fs = require('fs'),
path = require('path'),
lang = require('./lang'),
file = require('./file'),
homeDir = require('./homeDir'),
overrideConfigUrl = path.join(homeDir, '.voloconfig'),
localConfigUrl = path.join(homeDir, '.voloconfiglocal'),

data, overrideConfig, localConfig, contents;

// The defaults to use.
data = lang.delegate({
"volo": {
version: "0.2.10"
},

"npmRegistry": "https://registry.npmjs.org/",

"github": {
"userAgent": "volo/0.2.10",
"scheme": "https",
"host": "github.com",
"apiHost": "api.github.com",
"searchHost": "api.github.com",
"rawUrlPattern": "https://raw.github.com/{owner}/{repo}/{version}/{file}",
"searchPath": "/legacy/repos/search/{query}?language=JavaScript",
"searchOverrides": {
"amd": {
"underscore": "amdjs/underscore",
"backbone": "amdjs/backbone"
}
},
"typeOverrides": {
"dojo/dijit": "directory"
},

"auth": {
"domain": "https://api.github.com",
"authPath": "/authorizations",
"scopes": ["repo"],
"note": "Allow volo to interact with your repos.",
"noteUrl": "https://github.com/volojs/volo"
}
},

"command": {
"add": {
"discard": {
".gitignore": true,
"test": true,
"tests": true,
"doc": true,
"docs": true,
"example": true,
"examples": true,
"demo": true,
"demos": true
}
}
}
});

//Allow a local config at homeDir + '.config.js'
if (file.exists(overrideConfigUrl)) {
contents = (fs.readFileSync(overrideConfigUrl, 'utf8') || '').trim();

if (contents) {
overrideConfig = JSON.parse(contents);
lang.mixin(data, overrideConfig, true);
}
}

module.exports = {
get: function () {
return data;
},

//Simple local config. No fancy JSON object merging just plain mixing
//of top level properties.
getLocal: function () {
var contents;

if (!localConfig) {
if (file.exists(localConfigUrl)) {

contents = (fs.readFileSync(localConfigUrl, 'utf8') || '').trim();

if (contents) {
localConfig = JSON.parse(contents);
}
}

if (!localConfig) {
localConfig = {};
}
}

return localConfig;
},

saveLocal: function () {
//Make sure the directory exists
try {
file.mkdirs(path.dirname(localConfigUrl));
fs.writeFileSync(localConfigUrl, JSON.stringify(localConfig, null, ' '));
} catch (e) {
console.error('Cannot save local config, continuing without saving.');
return '';
}

return localConfigUrl;
}
};
'use strict';
var fs = require('fs'),
path = require('path'),
lang = require('./lang'),
file = require('./file'),
homeDir = require('./homeDir'),
overrideConfigUrl = path.join(homeDir, '.voloconfig'),
localConfigUrl = path.join(homeDir, '.voloconfiglocal'),

data, overrideConfig, localConfig, contents;

// The defaults to use.
data = lang.delegate({
"volo": {
version: "0.2.10"
},

"npmRegistry": "https://registry.npmjs.org/",

"github": {
"userAgent": "volo/0.2.10",
"scheme": "https",
"host": "github.com",
"apiHost": "api.github.com",
"searchHost": "api.github.com",
"rawUrlPattern": "https://raw.github.com/{owner}/{repo}/{version}/{file}",
"rawApiPattern": "https://api.github.com/repos/{owner}/{repo}/contents/?path={file}&ref={version}",
"searchPath": "/legacy/repos/search/{query}?language=JavaScript",
"searchOverrides": {
"amd": {
"underscore": "amdjs/underscore",
"backbone": "amdjs/backbone"
}
},
"typeOverrides": {
"dojo/dijit": "directory"
},

"auth": {
"domain": "https://api.github.com",
"authPath": "/authorizations",
"scopes": ["repo"],
"note": "Allow volo to interact with your repos.",
"noteUrl": "https://github.com/volojs/volo"
}
},

"command": {
"add": {
"discard": {
".gitignore": true,
"test": true,
"tests": true,
"doc": true,
"docs": true,
"example": true,
"examples": true,
"demo": true,
"demos": true
}
}
}
});

//Allow a local config at homeDir + '.config.js'
if (file.exists(overrideConfigUrl)) {
contents = (fs.readFileSync(overrideConfigUrl, 'utf8') || '').trim();

if (contents) {
overrideConfig = JSON.parse(contents);
lang.mixin(data, overrideConfig, true);
}
}

module.exports = {
get: function () {
return data;
},

//Simple local config. No fancy JSON object merging just plain mixing
//of top level properties.
getLocal: function () {
var contents;

if (!localConfig) {
if (file.exists(localConfigUrl)) {

contents = (fs.readFileSync(localConfigUrl, 'utf8') || '').trim();

if (contents) {
localConfig = JSON.parse(contents);
}
}

if (!localConfig) {
localConfig = {};
}
}

return localConfig;
},

saveLocal: function () {
//Make sure the directory exists
try {
file.mkdirs(path.dirname(localConfigUrl));
fs.writeFileSync(localConfigUrl, JSON.stringify(localConfig, null, ' '));
} catch (e) {
console.error('Cannot save local config, continuing without saving.');
return '';
}

return localConfigUrl;
}
};
Loading