Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/src/extension/template.ts
6458 views
1
/*
2
* template.ts
3
*
4
* Copyright (C) 2020-2022 Posit Software, PBC
5
*/
6
7
import { join } from "../deno_ral/path.ts";
8
import { existsSync } from "../deno_ral/fs.ts";
9
import { resolvePathGlobs } from "../core/path.ts";
10
import { lines } from "../core/text.ts";
11
import { warning } from "../deno_ral/log.ts";
12
13
const kQuartoIgnore = ".quartoignore";
14
15
export function templateFiles(dir: string) {
16
// Look for a quarto ignore file
17
const excludes: string[] = [];
18
const includes: string[] = [];
19
const ignoreFile = join(dir, kQuartoIgnore);
20
if (existsSync(ignoreFile)) {
21
const ignoreFileContents = Deno.readTextFileSync(ignoreFile);
22
const ignoreLines = lines(ignoreFileContents.trim());
23
ignoreLines.forEach((line) => {
24
const splitOnComment = line.split("#");
25
const exclude = splitOnComment[0];
26
if (exclude && exclude.startsWith("!")) {
27
if (exclude.length > 1) {
28
includes.push(exclude.substring(1));
29
} else {
30
warning(`Unknown ignore pattern '${exclude}'`);
31
}
32
} else if (exclude) {
33
excludes.push(exclude);
34
}
35
});
36
}
37
excludes.push(...kBuiltInExcludes);
38
39
const filtered = excludes.filter((ex) => {
40
return !includes.includes(ex);
41
});
42
43
const resolved = resolvePathGlobs(
44
dir,
45
["**/*"],
46
filtered,
47
);
48
return resolved.include;
49
}
50
51
const kBuiltInExcludes = [
52
".*",
53
"COPYING.md",
54
"COPYRIGHT",
55
"README.md",
56
"CHANGELOG.md",
57
"COPYRIGHT",
58
"LICENSE",
59
"_extensions",
60
"CLAUDE.md",
61
"AGENTS.md",
62
];
63
64