-
Notifications
You must be signed in to change notification settings - Fork 7
/
map.ts
37 lines (34 loc) · 948 Bytes
/
map.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { existsSync } from 'fs';
import { copySync, utimes, writeFile } from 'fs-extra';
import { makeHash } from './hash';
import { RecipeImpl } from '../utils/recipe-factory';
interface MapOption {
baseFolder: string
staticDomain: string
}
export const map: RecipeImpl<MapOption, undefined> = async({target, dep, baseFolder, staticDomain, make}) => {
copySync(dep, target);
if (existsSync(dep + '.md5') && baseFolder && staticDomain) {
await makeHash({
target: target + '.md5',
dep: target,
baseFolder,
staticDomain,
make,
}, {
file: dep,
md5: true
});
}
};
export const touch = async ({target}) => {
const now = new Date();
try {
await utimes(target, now, now);
} catch (err) {
if (err.code === 'ENOENT') {
return writeFile(target, '')
}
throw err
}
};