Skip to content

Commit

Permalink
Merge pull request #13 from UofGAnalytics/cli-ui
Browse files Browse the repository at this point in the history
CLI UI
  • Loading branch information
dmca-glasgow committed Jun 25, 2021
2 parents b924759 + 12653ac commit 71145e8
Show file tree
Hide file tree
Showing 29 changed files with 362 additions and 11,588 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
build/
cache/
yarn-error.log
node_modules
.RData
.RDataTmp
Rplots.pdf
1 change: 1 addition & 0 deletions compiler/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build/
11,108 changes: 0 additions & 11,108 deletions compiler/dist/index.js

This file was deleted.

218 changes: 0 additions & 218 deletions compiler/dist/template/main.css

This file was deleted.

7 changes: 0 additions & 7 deletions compiler/dist/template/main.js

This file was deleted.

5 changes: 5 additions & 0 deletions compiler/src/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ const { argv } = yargs(process.argv.slice(2))
.option('noCache', {
type: 'boolean',
description: 'No cache',
})
.option('spelling', {
type: 'boolean',
description: 'Check spelling',
});

const dirPath = String(argv._[0] || '.');
Expand All @@ -49,6 +53,7 @@ const options = {
noReport: argv.noReport,
noEmbedAssets: argv.noEmbedAssets,
noCache: argv.noCache,
spelling: argv.spelling,
};

rMarkdown(dirPath, options);
10 changes: 5 additions & 5 deletions compiler/src/html-wrapper/view-options/readability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ const options: ReadabilityItem[] = [
{
value: 'letterSpacing',
label: 'Letter spacing',
min: 0.6,
max: 2,
increment: 0.1,
min: -0.1,
max: 0.2,
increment: 0.05,
},
{
value: 'lineWidth',
label: 'Line width',
min: 0.6,
max: 2,
increment: 0.1,
max: 1.2,
increment: 0.05,
},
];

Expand Down
52 changes: 38 additions & 14 deletions compiler/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import chalk from 'chalk';

import { codeMod } from './code-mod';
import { collectCoursework } from './course';
import {
customCombinedTransforms,
customTransforms,
htmlCompiler,
linter,
markdownParser,
Expand Down Expand Up @@ -58,18 +58,22 @@ async function createUnit(ctx: Context, unitIdx: number) {
export async function buildUnit(ctx: Context, unitIdx: number) {
const { files } = ctx.course.units[unitIdx];

const markdowns = await processKnitr(files, ctx);
////////////
// 1 code mod - rewrite old syntax to new syntax with regex
////////////

const mdasts = await Promise.all(
markdowns.map((file) => markdownParser(file, ctx))
);
files.forEach((file) => {
file.contents = codeMod(file.contents as string);
});

// transforms in parallel with reports back to original files
await Promise.all(
mdasts.map((mdast, idx) => customTransforms(mdast, ctx, files[idx]))
////////////
// 2 static analysis
////////////

const mdasts = await Promise.all(
files.map((file) => markdownParser(file, ctx))
);

// linter in parallel
await Promise.all(
mdasts.map((mdast, idx) => linter(mdast, ctx, files[idx]))
);
Expand All @@ -78,15 +82,35 @@ export async function buildUnit(ctx: Context, unitIdx: number) {
printReport(files, ctx);
}
if (reportHasFatalErrors(files, ctx)) {
const options = { ...ctx.options, reportOnlyErrors: true };
printReport(files, { ...ctx, options });
if (ctx.options.noReport) {
const options = { ...ctx.options, reportOnlyErrors: true };
printReport(files, { ...ctx, options });
}
return null;
}

// combine mdast trees
const mdast = combineMdastTrees(mdasts);
////////////
// 3 knitr: Rmarkdown -> markdown
////////////

// needs to re-read original files for easy
// compatibility with Windows Command Prompt
const markdowns = await processKnitr(files, ctx);

files.forEach((file) => {
file.contents = codeMod(file.contents as string);
});

////////////
// 4 markdown -> html
////////////

const mdasts2 = await Promise.all(
markdowns.map((file) => markdownParser(file, ctx))
);

const mdast = combineMdastTrees(mdasts2);

// transforms on the combined tree
await customCombinedTransforms(mdast, ctx);

const { hast, html } = await htmlCompiler(mdast, ctx, unitIdx);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
import path from 'path';

import { Node } from 'unist';
import visit from 'unist-util-visit';
import { VFile } from 'vfile';

import { Context } from '../types';
import { failMessage } from '../utils/message';
import { checkLocalFileExists } from '../utils/utils';

export function embedAssetUrl(ctx: Context) {
export function assertAssetExists() {
async function getAssetUrl(node: Node, file: VFile) {
const url = (node.url || '') as string;
if (!file.dirname) {
throw new Error('VFile dirname undefined');
}
if (!url.startsWith('http') && !path.isAbsolute(url)) {
const fullPath = path.join(process.cwd(), file.dirname, url);
const exists = await checkLocalFileExists(fullPath);
if (exists) {
node.url = fullPath;
} else {
failMessage(file, `No asset found at ${fullPath}`, node.position);
if (!url.startsWith('http')) {
const exists = await checkLocalFileExists(url);
if (!exists) {
failMessage(file, `No asset found at ${url}`, node.position);
}
}
}
Expand Down
Loading

0 comments on commit 71145e8

Please sign in to comment.