-
Notifications
You must be signed in to change notification settings - Fork 0
/
sow.js
executable file
·51 lines (43 loc) · 1.54 KB
/
sow.js
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env node
import copy from 'recursive-copy'
import { fixInstalledPath, fixSourceControlPath, logNoSuchFile, buildCopyOptions, parseMeadows, runDirectly } from './common.js'
export async function sow() {
const { meadows, vars } = await parseMeadows()
if (!meadows) {
throw new Error("No meadows found! Make sure you're defining it in your meadows.mjs. (e.g. `({ meadows: [...] })`)")
}
const copyOptions = {
dot: true,
overwrite: true,
expand: true
}
try {
for (const [index, meadow] of Object.entries(meadows)) {
let shouldSowMeadow = await (meadow.if?.(vars) ?? true)
if (shouldSowMeadow) {
// We could, if we wanted to get smart, throw files together in a batch, then trigger them asynchronously.
if (meadow.path) {
await copy(
fixSourceControlPath(meadow.path),
fixInstalledPath(meadow.path),
buildCopyOptions(copyOptions, meadow)
)
.then(() => console.log(`Copied '${fixSourceControlPath(meadow.path)}' to '${fixInstalledPath(meadow.path)}'`))
.catch(logNoSuchFile)
} else if (meadow.run) {
await meadow.run(vars)
}
} else {
if (meadow.path) {
console.log(`Skipping file '${meadow.path}'.`)
} else if (meadow.run) {
console.log(`Skipping run step "${meadow.name || `Step ${index}`}".`)
}
}
}
console.log('Done sowing.')
} catch (err) {
console.error('Error while sowing:', err)
}
}
if (runDirectly()) await sow()