mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-23 11:03:39 +00:00
Use ied instead of npm for installation of plugins
This commit is contained in:
+109
-109
@@ -1,110 +1,110 @@
|
||||
{
|
||||
"name": "gitbook",
|
||||
"version": "4.0.0",
|
||||
"homepage": "https://www.gitbook.com",
|
||||
"description": "Library and cmd utility to generate GitBooks",
|
||||
"main": "lib/index.js",
|
||||
"browser": "./lib/browser.js",
|
||||
"dependencies": {
|
||||
"bash-color": "0.0.4",
|
||||
"cheerio": "0.20.0",
|
||||
"chokidar": "1.5.0",
|
||||
"cp": "0.2.0",
|
||||
"cpr": "1.1.1",
|
||||
"crc": "3.4.0",
|
||||
"destroy": "1.0.4",
|
||||
"direction": "0.1.5",
|
||||
"dom-serializer": "0.1.0",
|
||||
"error": "7.0.2",
|
||||
"escape-html": "^1.0.3",
|
||||
"escape-string-regexp": "1.0.5",
|
||||
"extend": "^3.0.0",
|
||||
"fresh-require": "1.0.3",
|
||||
"front-matter": "^2.1.0",
|
||||
"gitbook-asciidoc": "1.2.2",
|
||||
"gitbook-core": "4.0.0",
|
||||
"gitbook-markdown": "1.3.2",
|
||||
"gitbook-plugin-copy-code": "4.0.0",
|
||||
"gitbook-plugin-headings": "4.0.0",
|
||||
"gitbook-plugin-highlight": "4.0.0",
|
||||
"gitbook-plugin-livereload": "4.0.0",
|
||||
"gitbook-plugin-lunr": "4.0.0",
|
||||
"gitbook-plugin-search": "4.0.0",
|
||||
"gitbook-plugin-sharing": "4.0.0",
|
||||
"gitbook-plugin-theme-default": "4.0.0",
|
||||
"gitbook-plugin-hints": "4.0.0",
|
||||
"github-slugid": "1.0.1",
|
||||
"graceful-fs": "4.1.4",
|
||||
"i18n-t": "1.0.1",
|
||||
"ignore": "3.1.2",
|
||||
"immutable": "^3.8.1",
|
||||
"is": "^3.1.0",
|
||||
"js-yaml": "^3.6.1",
|
||||
"json-schema-defaults": "0.1.1",
|
||||
"jsonschema": "1.1.0",
|
||||
"juice": "2.0.0",
|
||||
"mkdirp": "0.5.1",
|
||||
"moment": "2.13.0",
|
||||
"npm": "3.9.2",
|
||||
"npmi": "2.0.1",
|
||||
"nunjucks": "2.5.2",
|
||||
"object-path": "^0.9.2",
|
||||
"omit-keys": "^0.1.0",
|
||||
"open": "0.0.5",
|
||||
"q": "1.4.1",
|
||||
"react": "^15.3.2",
|
||||
"react-dom": "^15.3.2",
|
||||
"react-redux": "^4.4.5",
|
||||
"read-installed": "^4.0.3",
|
||||
"redux": "^3.5.2",
|
||||
"request": "2.72.0",
|
||||
"resolve": "1.1.7",
|
||||
"rmdir": "1.2.0",
|
||||
"semver": "5.1.0",
|
||||
"send": "0.13.2",
|
||||
"spawn-cmd": "0.0.2",
|
||||
"tiny-lr": "0.2.1",
|
||||
"tmp": "0.0.28",
|
||||
"urijs": "1.18.0"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "./node_modules/.bin/mocha ./testing/setup.js \"./src/**/*/__tests__/*.js\" --bail --reporter=list --timeout=100000 --compilers js:babel-register",
|
||||
"dist": "rm -rf lib/ && babel -d lib/ src/ --source-maps --ignore \"**/*/__tests__/*.js\"",
|
||||
"prepublish": "npm run dist"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/GitbookIO/gitbook.git"
|
||||
},
|
||||
"bin": {
|
||||
"gitbook": "./bin/gitbook.js"
|
||||
},
|
||||
"keywords": [
|
||||
"git",
|
||||
"book",
|
||||
"gitbook"
|
||||
],
|
||||
"author": "GitBook Inc. <contact@gitbook.com>",
|
||||
"license": "Apache-2.0",
|
||||
"bugs": {
|
||||
"url": "https://github.com/GitbookIO/gitbook/issues"
|
||||
},
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Aaron O'Mullan",
|
||||
"email": "aaron@gitbook.com"
|
||||
},
|
||||
{
|
||||
"name": "Samy Pessé",
|
||||
"email": "samy@gitbook.com"
|
||||
}
|
||||
],
|
||||
"devDependencies": {
|
||||
"babel-cli": "^6.14.0",
|
||||
"babel-preset-es2015": "^6.14.0",
|
||||
"babel-preset-react": "^6.11.1",
|
||||
"babel-preset-stage-2": "^6.13.0",
|
||||
"babel-register": "^6.14.0",
|
||||
"mocha": "^3.0.2"
|
||||
}
|
||||
}
|
||||
"name": "gitbook",
|
||||
"version": "4.0.0",
|
||||
"homepage": "https://www.gitbook.com",
|
||||
"description": "Library and cmd utility to generate GitBooks",
|
||||
"main": "lib/index.js",
|
||||
"browser": "./lib/browser.js",
|
||||
"dependencies": {
|
||||
"bash-color": "0.0.4",
|
||||
"cheerio": "0.20.0",
|
||||
"chokidar": "1.5.0",
|
||||
"cp": "0.2.0",
|
||||
"cpr": "1.1.1",
|
||||
"crc": "3.4.0",
|
||||
"destroy": "1.0.4",
|
||||
"direction": "0.1.5",
|
||||
"dom-serializer": "0.1.0",
|
||||
"error": "7.0.2",
|
||||
"escape-html": "^1.0.3",
|
||||
"escape-string-regexp": "1.0.5",
|
||||
"extend": "^3.0.0",
|
||||
"fresh-require": "1.0.3",
|
||||
"front-matter": "^2.1.0",
|
||||
"gitbook-asciidoc": "1.2.2",
|
||||
"gitbook-core": "4.0.0",
|
||||
"gitbook-markdown": "1.3.2",
|
||||
"gitbook-plugin-copy-code": "4.0.0",
|
||||
"gitbook-plugin-headings": "4.0.0",
|
||||
"gitbook-plugin-highlight": "4.0.0",
|
||||
"gitbook-plugin-hints": "4.0.0",
|
||||
"gitbook-plugin-livereload": "4.0.0",
|
||||
"gitbook-plugin-lunr": "4.0.0",
|
||||
"gitbook-plugin-search": "4.0.0",
|
||||
"gitbook-plugin-sharing": "4.0.0",
|
||||
"gitbook-plugin-theme-default": "4.0.0",
|
||||
"github-slugid": "1.0.1",
|
||||
"graceful-fs": "4.1.4",
|
||||
"i18n-t": "1.0.1",
|
||||
"ied": "2.3.3",
|
||||
"ignore": "3.1.2",
|
||||
"immutable": "^3.8.1",
|
||||
"is": "^3.1.0",
|
||||
"js-yaml": "^3.6.1",
|
||||
"json-schema-defaults": "0.1.1",
|
||||
"jsonschema": "1.1.0",
|
||||
"juice": "2.0.0",
|
||||
"mkdirp": "0.5.1",
|
||||
"moment": "2.13.0",
|
||||
"npm": "3.10.9",
|
||||
"nunjucks": "2.5.2",
|
||||
"object-path": "^0.9.2",
|
||||
"omit-keys": "^0.1.0",
|
||||
"open": "0.0.5",
|
||||
"q": "1.4.1",
|
||||
"react": "^15.3.2",
|
||||
"react-dom": "^15.3.2",
|
||||
"react-redux": "^4.4.5",
|
||||
"read-installed": "^4.0.3",
|
||||
"redux": "^3.5.2",
|
||||
"request": "2.72.0",
|
||||
"resolve": "1.1.7",
|
||||
"rmdir": "1.2.0",
|
||||
"semver": "5.1.0",
|
||||
"send": "0.13.2",
|
||||
"spawn-cmd": "0.0.2",
|
||||
"tiny-lr": "0.2.1",
|
||||
"tmp": "0.0.28",
|
||||
"urijs": "1.18.0"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "./node_modules/.bin/mocha ./testing/setup.js \"./src/**/*/__tests__/*.js\" --bail --reporter=list --timeout=100000 --compilers js:babel-register",
|
||||
"dist": "rm -rf lib/ && babel -d lib/ src/ --source-maps --ignore \"**/*/__tests__/*.js\"",
|
||||
"prepublish": "npm run dist"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/GitbookIO/gitbook.git"
|
||||
},
|
||||
"bin": {
|
||||
"gitbook": "./bin/gitbook.js"
|
||||
},
|
||||
"keywords": [
|
||||
"git",
|
||||
"book",
|
||||
"gitbook"
|
||||
],
|
||||
"author": "GitBook Inc. <contact@gitbook.com>",
|
||||
"license": "Apache-2.0",
|
||||
"bugs": {
|
||||
"url": "https://github.com/GitbookIO/gitbook/issues"
|
||||
},
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Aaron O'Mullan",
|
||||
"email": "aaron@gitbook.com"
|
||||
},
|
||||
{
|
||||
"name": "Samy Pessé",
|
||||
"email": "samy@gitbook.com"
|
||||
}
|
||||
],
|
||||
"devDependencies": {
|
||||
"babel-cli": "^6.14.0",
|
||||
"babel-preset-es2015": "^6.14.0",
|
||||
"babel-preset-react": "^6.11.1",
|
||||
"babel-preset-stage-2": "^6.13.0",
|
||||
"babel-register": "^6.14.0",
|
||||
"mocha": "^3.0.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,11 +7,11 @@ const FS = require('../models/fs');
|
||||
const error = require('../utils/error');
|
||||
|
||||
/**
|
||||
Create a fake filesystem for unit testing GitBook.
|
||||
|
||||
@param {Map<String:String|Map>}
|
||||
*/
|
||||
function createMockFS(files) {
|
||||
* Create a fake filesystem for unit testing GitBook.
|
||||
* @param {Map<String:String|Map>}
|
||||
* @return {FS}
|
||||
*/
|
||||
function createMockFS(files, root = '') {
|
||||
files = Immutable.fromJS(files);
|
||||
const mtime = new Date();
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const path = require('path');
|
||||
const tmp = require('tmp');
|
||||
|
||||
const PluginDependency = require('../../models/pluginDependency');
|
||||
const Book = require('../../models/book');
|
||||
@@ -7,23 +7,36 @@ const installPlugin = require('../installPlugin');
|
||||
|
||||
const Parse = require('../../parse');
|
||||
|
||||
describe('installPlugin', function() {
|
||||
let book;
|
||||
describe('installPlugin', () => {
|
||||
let book, dir;
|
||||
|
||||
this.timeout(30000);
|
||||
|
||||
before(function() {
|
||||
const fs = NodeFS(path.resolve(__dirname, '../../../'));
|
||||
const baseBook = Book.createForFS(fs);
|
||||
before(() => {
|
||||
dir = tmp.dirSync({ unsafeCleanup: true });
|
||||
const fs = NodeFS(dir.name);
|
||||
const baseBook = Book.createForFS(fs)
|
||||
.setLogLevel('disabled');
|
||||
|
||||
return Parse.parseConfig(baseBook)
|
||||
.then(function(_book) {
|
||||
.then((_book) => {
|
||||
book = _book;
|
||||
});
|
||||
});
|
||||
|
||||
it('must install a plugin from NPM', function() {
|
||||
after(() => {
|
||||
dir.removeCallback();
|
||||
});
|
||||
|
||||
it('must install a plugin from NPM', () => {
|
||||
const dep = PluginDependency.createFromString('ga');
|
||||
return installPlugin(book, dep)
|
||||
.then(() => {
|
||||
expect(dir.name).toHaveFile('node_modules/gitbook-plugin-ga/package.json');
|
||||
expect(dir.name).toNotHaveFile('package.json');
|
||||
});
|
||||
});
|
||||
|
||||
it('must install a specific version of a plugin', () => {
|
||||
const dep = PluginDependency.createFromString('ga@0.2.1');
|
||||
return installPlugin(book, dep);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,27 +1,34 @@
|
||||
const path = require('path');
|
||||
const tmp = require('tmp');
|
||||
|
||||
const Book = require('../../models/book');
|
||||
const NodeFS = require('../../fs/node');
|
||||
const MockFS = require('../../fs/mock');
|
||||
const installPlugins = require('../installPlugins');
|
||||
|
||||
const Parse = require('../../parse');
|
||||
|
||||
describe('installPlugins', function() {
|
||||
let book;
|
||||
describe('installPlugins', () => {
|
||||
let book, dir;
|
||||
|
||||
this.timeout(30000);
|
||||
before(() => {
|
||||
dir = tmp.dirSync({ unsafeCleanup: true });
|
||||
|
||||
before(function() {
|
||||
const fs = NodeFS(path.resolve(__dirname, '../../../'));
|
||||
const baseBook = Book.createForFS(fs);
|
||||
const fs = MockFS({
|
||||
'book.json': JSON.stringify({ plugins: ['ga', 'sitemap' ]})
|
||||
}, dir.name);
|
||||
const baseBook = Book.createForFS(fs)
|
||||
.setLogLevel('disabled');
|
||||
|
||||
return Parse.parseConfig(baseBook)
|
||||
.then(function(_book) {
|
||||
.then((_book) => {
|
||||
book = _book;
|
||||
});
|
||||
});
|
||||
|
||||
it('must install all plugins from NPM', function() {
|
||||
after(() => {
|
||||
dir.removeCallback();
|
||||
});
|
||||
|
||||
it('must install all plugins from NPM', () => {
|
||||
return installPlugins(book)
|
||||
.then(function(n) {
|
||||
expect(n).toBe(2);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const npmi = require('npmi');
|
||||
const resolve = require('resolve');
|
||||
|
||||
const Promise = require('../utils/promise');
|
||||
const { exec } = require('../utils/command');
|
||||
const resolveVersion = require('./resolveVersion');
|
||||
|
||||
/**
|
||||
@@ -20,6 +20,8 @@ function installPlugin(book, plugin) {
|
||||
logger.info.ln('');
|
||||
logger.info.ln('installing plugin "' + name + '"');
|
||||
|
||||
const installerBin = resolve.sync('ied/lib/cmd.js');
|
||||
|
||||
// Find a version to install
|
||||
return resolveVersion(plugin)
|
||||
.then(function(version) {
|
||||
@@ -27,17 +29,12 @@ function installPlugin(book, plugin) {
|
||||
throw new Error('Found no satisfactory version for plugin "' + name + '" with requirement "' + requirement + '"');
|
||||
}
|
||||
|
||||
logger.info.ln('install plugin "' + name + '" (' + requirement + ') from NPM with version', version);
|
||||
return Promise.nfcall(npmi, {
|
||||
'name': plugin.getNpmID(),
|
||||
version,
|
||||
'path': installFolder,
|
||||
'npmLoad': {
|
||||
'loglevel': 'silent',
|
||||
'loaded': true,
|
||||
'prefix': installFolder
|
||||
}
|
||||
});
|
||||
logger.info.ln('install plugin "' + name + '" (' + requirement + ') with version', version);
|
||||
|
||||
const npmID = plugin.getNpmID();
|
||||
const command = `${installerBin} install ${npmID}@${version}`;
|
||||
|
||||
return exec(command, { cwd: installFolder });
|
||||
})
|
||||
.then(function() {
|
||||
logger.info.ok('plugin "' + name + '" installed with success');
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
const npmi = require('npmi');
|
||||
|
||||
const DEFAULT_PLUGINS = require('../constants/defaultPlugins');
|
||||
const Promise = require('../utils/promise');
|
||||
const installPlugin = require('./installPlugin');
|
||||
@@ -34,10 +32,10 @@ function installPlugins(book) {
|
||||
|
||||
if (plugins.size == 0) {
|
||||
logger.info.ln('nothing to install!');
|
||||
return Promise();
|
||||
return Promise(0);
|
||||
}
|
||||
|
||||
logger.info.ln('installing', plugins.size, 'plugins using npm@' + npmi.NPM_VERSION);
|
||||
logger.info.ln('installing', plugins.size, 'plugins from registry');
|
||||
|
||||
return Promise.forEach(plugins, function(plugin) {
|
||||
return installPlugin(book, plugin);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const npm = require('npm');
|
||||
const semver = require('semver');
|
||||
const Immutable = require('immutable');
|
||||
const { Map } = require('immutable');
|
||||
|
||||
const Promise = require('../utils/promise');
|
||||
const Plugin = require('../models/plugin');
|
||||
@@ -9,10 +9,9 @@ const gitbook = require('../gitbook');
|
||||
let npmIsReady;
|
||||
|
||||
/**
|
||||
Initialize and prepare NPM
|
||||
|
||||
@return {Promise}
|
||||
*/
|
||||
* Initialize and prepare NPM
|
||||
* @return {Promise}
|
||||
*/
|
||||
function initNPM() {
|
||||
if (npmIsReady) return npmIsReady;
|
||||
|
||||
@@ -25,11 +24,11 @@ function initNPM() {
|
||||
}
|
||||
|
||||
/**
|
||||
Resolve a plugin dependency to a version
|
||||
|
||||
@param {PluginDependency} plugin
|
||||
@return {Promise<String>}
|
||||
*/
|
||||
* Resolve a plugin dependency to a version
|
||||
*
|
||||
* @param {PluginDependency} plugin
|
||||
* @return {Promise<String>}
|
||||
*/
|
||||
function resolveVersion(plugin) {
|
||||
const npmId = Plugin.nameToNpmID(plugin.getName());
|
||||
const requiredVersion = plugin.getVersion();
|
||||
@@ -43,7 +42,7 @@ function resolveVersion(plugin) {
|
||||
return Promise.nfcall(npm.commands.view, [npmId + '@' + requiredVersion, 'engines'], true);
|
||||
})
|
||||
.then(function(versions) {
|
||||
versions = Immutable.Map(versions).entrySeq();
|
||||
versions = Map(versions).entrySeq();
|
||||
|
||||
const result = versions
|
||||
.map(function(entry) {
|
||||
|
||||
@@ -4,12 +4,12 @@ const spawn = require('spawn-cmd').spawn;
|
||||
const Promise = require('./promise');
|
||||
|
||||
/**
|
||||
Execute a command
|
||||
|
||||
@param {String} command
|
||||
@param {Object} options
|
||||
@return {Promise}
|
||||
*/
|
||||
* Execute a command
|
||||
*
|
||||
* @param {String} command
|
||||
* @param {Object} options
|
||||
* @return {Promise}
|
||||
*/
|
||||
function exec(command, options) {
|
||||
const d = Promise.defer();
|
||||
|
||||
@@ -34,13 +34,13 @@ function exec(command, options) {
|
||||
}
|
||||
|
||||
/**
|
||||
Spawn an executable
|
||||
|
||||
@param {String} command
|
||||
@param {Array} args
|
||||
@param {Object} options
|
||||
@return {Promise}
|
||||
*/
|
||||
* Spawn an executable
|
||||
*
|
||||
* @param {String} command
|
||||
* @param {Array} args
|
||||
* @param {Object} options
|
||||
* @return {Promise}
|
||||
*/
|
||||
function spawnCmd(command, args, options) {
|
||||
const d = Promise.defer();
|
||||
const child = spawn(command, args, options);
|
||||
@@ -69,11 +69,11 @@ function spawnCmd(command, args, options) {
|
||||
}
|
||||
|
||||
/**
|
||||
Transform an option object to a command line string
|
||||
|
||||
@param {String|number} value
|
||||
@param {String}
|
||||
*/
|
||||
* Transform an option object to a command line string
|
||||
*
|
||||
* @param {String|number} value
|
||||
* @param {String}
|
||||
*/
|
||||
function escapeShellArg(value) {
|
||||
if (is.number(value)) {
|
||||
return value;
|
||||
@@ -86,11 +86,11 @@ function escapeShellArg(value) {
|
||||
}
|
||||
|
||||
/**
|
||||
Transform a map of options into a command line arguments string
|
||||
|
||||
@param {Object} options
|
||||
@return {String}
|
||||
*/
|
||||
* Transform a map of options into a command line arguments string
|
||||
*
|
||||
* @param {Object} options
|
||||
* @return {String}
|
||||
*/
|
||||
function optionsToShellArgs(options) {
|
||||
const result = [];
|
||||
|
||||
|
||||
+1
-1
@@ -36,5 +36,5 @@ packages.forEach((name) => {
|
||||
updateDependencies(pkg.dependencies);
|
||||
updateDependencies(pkg.devDependencies);
|
||||
|
||||
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 3), 'utf-8');
|
||||
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2), 'utf-8');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user