build(aio): copy content image assets

This commit is contained in:
Peter Bacon Darwin 2017-04-01 07:01:44 +01:00 committed by Pete Bacon Darwin
parent 08941aa0c7
commit dd4e3f8704
4 changed files with 55 additions and 3 deletions

View File

@ -24,7 +24,8 @@ const API_SOURCE_PATH = path.resolve(PROJECT_ROOT, 'packages');
const AIO_PATH = path.resolve(PROJECT_ROOT, 'aio');
const CONTENTS_PATH = path.resolve(AIO_PATH, 'content');
const TEMPLATES_PATH = path.resolve(AIO_PATH, 'transforms/templates');
const OUTPUT_PATH = path.resolve(AIO_PATH, 'src/content/docs');
const OUTPUT_PATH = path.resolve(AIO_PATH, 'src/content');
const DOCS_OUTPUT_PATH = path.resolve(OUTPUT_PATH, 'docs');
module.exports =
new Package(
@ -51,11 +52,12 @@ module.exports =
.processor(require('./processors/filterIgnoredDocs'))
.processor(require('./processors/fixInternalDocumentLinks'))
.processor(require('./processors/processNavigationMap'))
.processor(require('./processors/copyContentAssets'))
// overrides base packageInfo and returns the one for the 'angular/angular' repo.
.factory('packageInfo', function() { return require(path.resolve(PROJECT_ROOT, 'package.json')); })
.factory(require('./readers/json'))
.factory(require('./services/copyFolder'))
.config(function(checkAnchorLinksProcessor, log) {
// TODO: re-enable
@ -168,7 +170,7 @@ module.exports =
})
// Where do we write the output files?
.config(function(writeFilesProcessor) { writeFilesProcessor.outputFolder = OUTPUT_PATH; })
.config(function(writeFilesProcessor) { writeFilesProcessor.outputFolder = DOCS_OUTPUT_PATH; })
// Target environments
@ -292,6 +294,12 @@ module.exports =
convertToJsonProcessor.docTypes = EXPORT_DOC_TYPES.concat([
'content', 'decorator', 'directive', 'pipe', 'module'
]);
})
.config(function(copyContentAssetsProcessor) {
copyContentAssetsProcessor.assetMappings.push(
{ from: path.resolve(CONTENTS_PATH, 'images'), to: path.resolve(OUTPUT_PATH, 'images') }
);
});

View File

@ -0,0 +1,12 @@
module.exports = function copyContentAssetsProcessor(copyFolder) {
return {
$runAfter: ['files-written'],
assetMappings: [],
$process() {
this.assetMappings.forEach(map => {
copyFolder(map.from, map.to);
});
}
};
};

View File

@ -0,0 +1,27 @@
const testPackage = require('../../helpers/test-package');
const Dgeni = require('dgeni');
const factory = require('./copyContentAssets');
fdescribe('extractDecoratedClasses processor', function() {
let dgeni, injector, processor;
beforeEach(function() {
dgeni = new Dgeni([testPackage('angular.io-package')]);
injector = dgeni.configureInjector();
processor = injector.get('copyContentAssetsProcessor');
});
it('should exist', () => {
expect(processor).toBeDefined();
});
it('should call copyFolder with each mapping', () => {
const mockCopyFolder = jasmine.createSpy();
processor = factory(mockCopyFolder);
processor.assetMappings.push({ from: 'a/b/c', to: 'x/y/z' });
processor.assetMappings.push({ from: '1/2/3', to: '4/5/6' });
processor.$process();
expect(mockCopyFolder).toHaveBeenCalledWith('a/b/c', 'x/y/z');
expect(mockCopyFolder).toHaveBeenCalledWith('1/2/3', '4/5/6');
});
});

View File

@ -0,0 +1,5 @@
const {cp} = require('shelljs');
module.exports = function copyFolder() {
return (from, to) => cp('-rf', from, to);
};