Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gitbook-cli

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gitbook-cli - npm Package Compare versions

Comparing version 0.3.0 to 0.3.1

12

bin/gitbook.js

@@ -55,2 +55,14 @@ #! /usr/bin/env node

program
.command('versions:current')
.description('print current version to use in the current directory')
.action(function(){
runPromise(
versions.current()
.then(function(v) {
console.log("Current version is", v);
})
);
});
program
.command('versions:available')

@@ -57,0 +69,0 @@ .description('list available versions on NPM')

78

lib/versions.js

@@ -19,3 +19,3 @@ var Q = require("q");

// Check version
// Check if a version is valid for gitbook-cli
function checkVersion(version) {

@@ -34,3 +34,3 @@ return semver.satisfies(version, config.GITBOOK_VERSION);

return 0;
};
}

@@ -86,2 +86,4 @@ // Return a list of all versions

function resolveVersion(version) {
var _version = version;
return availableVersions()

@@ -97,3 +99,3 @@ .then(function(available) {

// Check version
if (!version) throw "Invalid version or tag, see available using 'gitbook versions:available'";
if (!version) throw "Invalid version or tag '"+_version+"', see available using 'gitbook versions:available'";
return version;

@@ -103,2 +105,16 @@ });

// Resolve a version locally
function resolveVersionLocally(version) {
var versions = listVersions();
version = _.chain(versions)
.pluck("version")
.find(function(v) {
return semver.satisfies(v, version);
})
.value();
if (!version) return Q.reject(new Error("Version not found locally: "+version));
return Q(version);
}
// Require a specific version of gitbook (or the default one)

@@ -171,9 +187,9 @@ function requireVersion(version) {

// Return a specific version
function getVersion(version, doInstall) {
var versions, realVersion, gitbook = null;
// Return a specific version, install it if needed
function getCurrentVersion(version, doInstall) {
return Q()
versions = _.pluck(listVersions());
if (!version) {
// If not defined, load version required from book.json
.then(function() {
if (version) return;
try {

@@ -184,25 +200,30 @@ var bookRoot = parsedArgv._[1] || process.cwd();

} catch (e) {}
}
})
version = version || "latest";
realVersion = version;
// Resolve version locally
.then(function() {
version = version || "*";
return resolveVersionLocally(version)
})
if (version == "latest") {
realVersion = _.last(versions).version;
}
// Install if needed
.fail(function(err) {
if (doInstall == false) throw err;
// test loading gitbook
if (realVersion) {
gitbook = requireVersion(realVersion);
if (gitbook) return Q(gitbook);
}
return installVersion(version)
.then(function() {
return getCurrentVersion(version, false)
});
});
}
// don't install
if (doInstall == false) return Q.reject("Invalid version of gitbook: "+version);
return installVersion(version)
.then(function() {
return getVersion(version)
// Return the gitbook associated with the current version
function getVersion(version) {
return getCurrentVersion(version)
.then(function(resolved) {
var gitbook = requireVersion(resolved);
if (!gitbook) throw "Version "+resolved+" is corrupted";
return gitbook;
});
};
}

@@ -216,6 +237,7 @@ // Link a flder to a version

return Q.nfcall(fs.symlink.bind(fs), folder, outputFolder);
};
}
module.exports = {
get: getVersion,
current: getCurrentVersion,
list: listVersions,

@@ -222,0 +244,0 @@ require: requireVersion,

{
"name": "gitbook-cli",
"version": "0.3.0",
"version": "0.3.1",
"homepage": "https://www.gitbook.com",

@@ -5,0 +5,0 @@ "description": "CLI to generate books using gitbook",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc