-
Notifications
You must be signed in to change notification settings - Fork 431
Expand file tree
/
Copy pathtemplate.ts
More file actions
64 lines (58 loc) · 1.53 KB
/
template.ts
File metadata and controls
64 lines (58 loc) · 1.53 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
* template.ts
*
* Copyright (C) 2020-2022 Posit Software, PBC
*/
import { join } from "../deno_ral/path.ts";
import { existsSync } from "../deno_ral/fs.ts";
import { resolvePathGlobs } from "../core/path.ts";
import { lines } from "../core/text.ts";
import { warning } from "../deno_ral/log.ts";
const kQuartoIgnore = ".quartoignore";
export function templateFiles(dir: string) {
// Look for a quarto ignore file
const excludes: string[] = [];
const includes: string[] = [];
const ignoreFile = join(dir, kQuartoIgnore);
if (existsSync(ignoreFile)) {
const ignoreFileContents = Deno.readTextFileSync(ignoreFile);
const ignoreLines = lines(ignoreFileContents.trim());
ignoreLines.forEach((line) => {
const splitOnComment = line.split("#");
const exclude = splitOnComment[0];
if (exclude && exclude.startsWith("!")) {
if (exclude.length > 1) {
includes.push(exclude.substring(1));
} else {
warning(`Unknown ignore pattern '${exclude}'`);
}
} else if (exclude) {
excludes.push(exclude);
}
});
}
excludes.push(...kBuiltInExcludes);
const filtered = excludes.filter((ex) => {
return !includes.includes(ex);
});
const resolved = resolvePathGlobs(
dir,
["**/*"],
filtered,
);
return resolved.include;
}
const kBuiltInExcludes = [
".*",
"COPYING.md",
"COPYRIGHT",
"README.md",
"CHANGELOG.md",
"COPYRIGHT",
"LICENSE",
"_extensions",
"CLAUDE.md",
"CLAUDE.local.md",
"AGENTS.md",
"AGENTS.local.md",
];