Skip to content

Commit eda3262

Browse files
committed
Complete loading
1 parent bc581cc commit eda3262

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

bin/gitbook.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ program
4747
if (versions.length > 0) {
4848
console.log('GitBook Versions Installed:');
4949
console.log('');
50+
5051
_.each(versions,function(v, i) {
5152
var text = v.name;
5253
if (v.name != v.version) text += ' [' + v.version + ']';
@@ -120,7 +121,6 @@ program
120121
runPromise(
121122
manager.link(version, folder)
122123
.then(function() {
123-
console.log('');
124124
console.log(color.green('GitBook '+version+' point to '+folder));
125125
})
126126
);
@@ -160,7 +160,7 @@ program
160160
.description('List commands for GitBook')
161161
.action(function(){
162162
runPromise(
163-
manager.load(program.gitbook)
163+
manager.ensureAndLoad(bookRoot, program.gitbook)
164164
.get('commands')
165165
.then(commands.help)
166166
);
@@ -174,7 +174,7 @@ program
174174
var kwargs = _.omit(parsedArgv, '$0', '_');
175175

176176
runPromise(
177-
manager.load(program.gitbook)
177+
manager.ensureAndLoad(bookRoot, program.gitbook)
178178
.then(function(gitbook) {
179179
return commands.exec(gitbook.commands, commandName, args, kwargs);
180180
})

lib/commands.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var _ = require('lodash');
44
// It prints the command and its description, then all the options
55
function help(commands) {
66
_.each(commands, function(command) {
7-
console.log(' '+command.name, '\t', command.description);
7+
console.log(' '+command.name, '\t', command.description);
88
_.each(command.options || [], function(option) {
99
var after = [];
1010

@@ -14,7 +14,7 @@ function help(commands) {
1414
if (after.length > 0) after = "("+after.join("; ")+")";
1515
else after = "";
1616

17-
console.log(' --'+option.name, '\t', option.description, after);
17+
console.log(' --'+option.name, '\t', option.description, after);
1818
});
1919
console.log('');
2020
});

lib/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ function ensureVersion(bookRoot, version, opts) {
4141
});
4242
}
4343

44+
// Ensure a version exists (or install it)
45+
// Then load it and returns the gitbook instance
46+
function ensureAndLoad(bookRoot, version, opts) {
47+
return ensureVersion(bookRoot, version, opts)
48+
.then(function(version) {
49+
return local.load(version);
50+
});
51+
}
4452

4553
// Update current version
4654
// -> Check that a newer version exists
@@ -76,6 +84,7 @@ function updateVersion(tag) {
7684
module.exports = {
7785
load: local.load,
7886
ensure: ensureVersion,
87+
ensureAndLoad: ensureAndLoad,
7988
current: local.current,
8089
uninstall: local.remove,
8190
link: local.link,

lib/local.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ function removeVersion(version) {
9595

9696
// Load a gitbook version
9797
function loadVersion(version) {
98-
return resolveVersion(version)
98+
return Q(_.isString(version)? resolveVersion(version) : version)
9999
.then(function(resolved) {
100100
var gitbook;
101101

0 commit comments

Comments
 (0)