1 | // @flow strict-local
|
2 |
|
3 | import fs from 'fs';
|
4 |
|
5 | /**
|
6 | * Creates an object that contains both source and minified (using the source as a fallback).
|
7 | * e.g. builtins.min.js and builtins.js.
|
8 | */
|
9 | export default function getExisting(
|
10 | minifiedPath: string,
|
11 | sourcePath: string,
|
12 | ): {|minified: string, source: string|} {
|
13 | let source = fs.readFileSync(sourcePath, 'utf8').trim();
|
14 | return {
|
15 | source,
|
16 | minified: fs.existsSync(minifiedPath)
|
17 | ? fs
|
18 | .readFileSync(minifiedPath, 'utf8')
|
19 | .trim()
|
20 | .replace(/;$/, '')
|
21 | : source,
|
22 | };
|
23 | }
|