Skip to content

Commit

Permalink
Merge pull request #44 from unexpectedjs/fix-copying-documentation-as…
Browse files Browse the repository at this point in the history
…sets

Ensure assets in the documentation directory are included in builds.
  • Loading branch information
alexjeffburke committed Jul 4, 2020
2 parents a1a4014 + b63e813 commit 99a39ed
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
/*global __dirname*/
var Evaldown = require('evaldown');
var metalSmith = require('metalsmith');
var fs = require('fs').promises;
var glob = require('glob');
var os = require('os');
var path = require('path');
var rimraf = require('rimraf');
var util = require('util');
var _ = require('lodash');

var createExpect = require('./lib/createExpect');
var globAsync = util.promisify(glob);
var rimrafAsync = util.promisify(rimraf);

async function copyDocumentationAssets(sourceDir, targetDir) {
const assetFilePaths = await globAsync('**/!(**.md)', {
cwd: sourceDir,
nodir: true
});

for (const filePath of assetFilePaths) {
await fs.copyFile(
path.join(sourceDir, filePath),
path.join(targetDir, filePath)
);
}
}

function idToName(id) {
return id.replace(/-/g, ' ');
}
Expand Down Expand Up @@ -120,13 +137,14 @@ module.exports = async function generate(options) {
'assertions/*/*.md',
'assertions.md'
];
var documentation = path.join(cwd, 'documentation');
var output = options.output || 'site-build';
var tmpOutput = path.join(os.tmpdir(), 'udsg', String(process.pid));

const stats = await new Evaldown({
commentMarker: 'unexpected-markdown',
outputFormat: 'inlined',
sourcePath: path.join(cwd, 'documentation'),
sourcePath: documentation,
targetPath: tmpOutput,
fileGlobals: {
expect: options => createExpect(options.metadata)
Expand All @@ -135,6 +153,10 @@ module.exports = async function generate(options) {

console.log(`evaldown completed with ${JSON.stringify(stats)}`);

await copyDocumentationAssets(documentation, tmpOutput);

console.log('copied documentation assets');

await new Promise((resolve, reject) => {
metalSmith('.')
.destination(output)
Expand Down

0 comments on commit 99a39ed

Please sign in to comment.