mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-21 01:53:26 +00:00
Correctly read assets using input fs when copying
This commit is contained in:
@@ -10,16 +10,17 @@ var fs = require('../../utils/fs');
|
||||
function onAsset(output, asset) {
|
||||
var book = output.getBook();
|
||||
var options = output.getOptions();
|
||||
var bookFS = book.getContentFS();
|
||||
|
||||
var rootFolder = book.getContentRoot();
|
||||
var outputFolder = options.get('root');
|
||||
|
||||
var filePath = path.resolve(rootFolder, asset);
|
||||
var outputPath = path.resolve(outputFolder, asset);
|
||||
|
||||
return fs.ensureFile(outputPath)
|
||||
.then(function() {
|
||||
return fs.copy(filePath, outputPath);
|
||||
return bookFS.readAsStream(asset)
|
||||
.then(function(stream) {
|
||||
return fs.writeStream(outputPath, stream);
|
||||
});
|
||||
})
|
||||
.thenResolve(output);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
var Immutable = require('immutable');
|
||||
|
||||
var Book = require('../../models/book');
|
||||
var createMockFS = require('../../fs/mock');
|
||||
var listAssets = require('../listAssets');
|
||||
var parseGlossary = require('../parseGlossary');
|
||||
|
||||
describe('listAssets', function() {
|
||||
pit('should not list glossary as asset', function() {
|
||||
var fs = createMockFS({
|
||||
'GLOSSARY.md': '# Glossary\n\n## Hello\nDescription for hello',
|
||||
'assetFile.js': '',
|
||||
'assets': {
|
||||
'file.js': ''
|
||||
}
|
||||
});
|
||||
var book = Book.createForFS(fs);
|
||||
|
||||
return parseGlossary(book)
|
||||
.then(function(resultBook) {
|
||||
return listAssets(resultBook, Immutable.Map());
|
||||
})
|
||||
.then(function(assets) {
|
||||
expect(assets.size).toBe(2);
|
||||
expect(assets.includes('assetFile.js'));
|
||||
expect(assets.includes('assets/file.js'));
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -17,6 +17,9 @@ function listAssets(book, pages) {
|
||||
var glossary = book.getGlossary();
|
||||
var glossaryFile = glossary.getFile().getPath();
|
||||
|
||||
var langs = book.getLanguages();
|
||||
var langsFile = langs.getFile().getPath();
|
||||
|
||||
return timing.measure(
|
||||
'parse.listAssets',
|
||||
fs.listAllFiles()
|
||||
@@ -25,8 +28,9 @@ function listAssets(book, pages) {
|
||||
return (
|
||||
book.isContentFileIgnored(file) ||
|
||||
pages.has(file) ||
|
||||
file !== summaryFile ||
|
||||
file !== glossaryFile
|
||||
file === summaryFile ||
|
||||
file === glossaryFile ||
|
||||
file === langsFile
|
||||
);
|
||||
});
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user