2019-06-15 22:38:05 +00:00
|
|
|
import { promisify } from 'util';
|
2019-06-16 01:21:11 +00:00
|
|
|
import { readFile, writeFile } from 'fs';
|
2019-06-15 22:38:05 +00:00
|
|
|
|
2019-06-16 18:30:04 +00:00
|
|
|
export const readFileSync = promisify(readFile);
|
|
|
|
export const writeFileSync = promisify(writeFile);
|
2019-06-15 22:38:05 +00:00
|
|
|
|
|
|
|
export async function loadSource(path: string): Promise<string> {
|
|
|
|
if (path === '-') {
|
|
|
|
return readFileSync(0, 'utf-8');
|
|
|
|
} else {
|
|
|
|
return readFileSync(path, 'utf-8');
|
|
|
|
}
|
|
|
|
}
|
2019-06-16 01:21:11 +00:00
|
|
|
|
|
|
|
export async function writeSource(path: string, data: string): Promise<void> {
|
|
|
|
if (path === '-') {
|
|
|
|
process.stdout.write(data);
|
|
|
|
} else {
|
|
|
|
return writeFileSync(path, data, {
|
|
|
|
encoding: 'utf-8',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|