Skip to content

Commit

Permalink
mdn: download source maps
Browse files Browse the repository at this point in the history
Close #201
  • Loading branch information
myfreeer committed Jan 10, 2021
1 parent 1784977 commit 89628ca
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/mdn/life-cycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
postProcessInteractiveExample,
preProcessInteractiveExample
} from './process-html/process-interactive-examples';
import {processYariSourceMap} from './process-source-maps';

const lifeCycle = defaultLifeCycle();
lifeCycle.linkRedirect.push(skipProcess, redirectUrl);
Expand All @@ -25,8 +26,11 @@ lifeCycle.processAfterDownload.unshift(
preProcessHtml,
processHtml(preProcessInteractiveExample)
);
lifeCycle.processAfterDownload.push(processHtml(postProcessHtml),
processHtml(postProcessInteractiveExample));
lifeCycle.processAfterDownload.push(
processHtml(postProcessHtml),
processHtml(postProcessInteractiveExample),
processYariSourceMap
);

const options: DownloadOptions = defaultDownloadOptions(lifeCycle);
options.logSubDir = 'developer.mozilla.org';
Expand Down
23 changes: 23 additions & 0 deletions src/mdn/process-source-maps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {processSourceMap} from 'website-scrap-engine/lib/life-cycle/process-source-map';
import {
DownloadResource,
SubmitResourceFunc
} from 'website-scrap-engine/lib/life-cycle/types';
import {StaticDownloadOptions} from 'website-scrap-engine/lib/options';
import {PipelineExecutor} from 'website-scrap-engine/lib/life-cycle/pipeline-executor';
import {AsyncResult} from 'website-scrap-engine/lib/life-cycle/types';
import {ResourceType} from 'website-scrap-engine/lib/resource';

export function processYariSourceMap(
res: DownloadResource,
submit: SubmitResourceFunc,
options: StaticDownloadOptions,
pipeline: PipelineExecutor): AsyncResult<DownloadResource | void> {
if (res.type !== ResourceType.Html &&
res.type !== ResourceType.Svg &&
res.downloadLink.startsWith('https://developer.mozilla.org/static/') && (
res.uri?.path()?.endsWith('.js') || res.uri?.path()?.endsWith('.css'))) {
return processSourceMap(res, submit, options, pipeline);
}
return res;
}

0 comments on commit 89628ca

Please sign in to comment.