Navigation | Overlay |
---|---|
t Navigate files | h Toggle hits |
y Change url to tip of branch | m Toggle misses |
b / v Jump to prev/next hit line | p Toggle partial |
z / x Jump to prev/next missed or partial line | 1..9 Toggle flags |
shift + o Open current page in GitHub | a Toggle all on |
/ or ? Show keyboard shortcuts dialog | c Toggle context lines or commits |
1 | 4 |
import * as fs from 'fs'; |
2 | 4 |
import path from 'path'; |
3 |
import { Platform } from '@remax/types'; |
|
4 |
|
|
5 | 4 |
function readTypescriptManifest(path: string, target: Platform) { |
6 | 4 |
require('@babel/register')({ |
7 |
presets: [ |
|
8 |
[require.resolve('@babel/preset-env'), { modules: 'commonjs' }], |
|
9 |
require.resolve('@babel/preset-typescript'), |
|
10 |
],
|
|
11 |
extensions: ['.ts'], |
|
12 |
cache: false, |
|
13 |
});
|
|
14 | 4 |
delete require.cache[path]; |
15 |
const config = require(path)[target] || require(path).default || require(path); |
|
16 |
|
|
17 | 4 |
return config; |
18 |
}
|
|
19 |
|
|
20 | 4 |
function readJavascriptManifest(path: string, target: Platform) { |
21 | 4 |
delete require.cache[path]; |
22 |
const config = require(path)[target] || require(path).default || require(path); |
|
23 |
|
|
24 | 4 |
return config; |
25 |
}
|
|
26 |
|
|
27 |
export default function readManifest(filename: string, target: Platform, strict = false) { |
|
28 |
if (!fs.existsSync(filename)) { |
|
29 |
if (strict) { |
|
30 | 4 |
throw new Error(`${path}.ts|js 文件不存在,请先创建配置文件,参考 https://remaxjs.org/guide/config`); |
31 |
}
|
|
32 | 4 |
return {}; |
33 |
}
|
|
34 |
if (path.extname(filename) === '.ts') { |
|
35 | 4 |
return readTypescriptManifest(filename, target); |
36 |
} else { |
|
37 | 4 |
return readJavascriptManifest(filename, target); |
38 |
}
|
|
39 |
}
|
Read our documentation on viewing source code .