46 lines
887 B
JavaScript
Raw Normal View History

2016-03-18 11:12:50 +01:00
'use strict';
/**
* Module dependencies
*/
// Node.js core.
const path = require('path');
// Public node modules.
const _ = require('lodash');
const fs = require('fs-extra');
const reportback = require('reportback')();
// Local dependencies.
const fileHelper = require('../file');
/**
* Copy file from one place to another
*/
2021-04-29 11:11:46 +02:00
module.exports = function(options, cb) {
2016-03-18 11:12:50 +01:00
cb = reportback.extend(cb, {
alreadyExists: 'error',
2021-04-29 11:11:46 +02:00
invalid: 'error',
2016-03-18 11:12:50 +01:00
});
// Compute the canonical path to copy from
// given its relative path from its source generator's
// `templates` directory.
const absSrcPath = path.resolve(options.templatesDirectory, options.templatePath);
fs.readFile(absSrcPath, 'utf8', (err, contents) => {
2016-03-18 11:12:50 +01:00
if (err) {
return cb.error(err);
}
2021-04-29 11:11:46 +02:00
return fileHelper(
_.merge(options, {
contents,
}),
cb
);
2016-03-18 11:12:50 +01:00
});
};