Skip to content

Commit a7e46b7

Browse files
committed
Prefix dot files with _. in templates
1 parent 2ab8b87 commit a7e46b7

File tree

6 files changed

+20
-14
lines changed

6 files changed

+20
-14
lines changed

.changeset/lovely-actors-jog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"create-solana-program": patch
3+
---
4+
5+
Prefix dot files with \_. in templates
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
.anchor
2+
.cargo
23
.DS_Store
34
**/.DS_Store
45
**/target
56
**/*.rs.bk
67
node_modules
78
test-ledger
89
dist
9-
.amman
10-
.cargo
11-
.bin
12-
.programs
13-
.env.*

utils/renderTemplates.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
* Renders a template folder/file to the provided destination,
1717
* by recursively copying all files under the source directory,
1818
* with the following exception:
19-
* - `_filename` are renamed to `.filename`.
19+
* - `_.filename` are renamed to `.filename`.
2020
* - `package.json` files are merged.
2121
* - `.gitignore` files are concatenated.
2222
* - `.njk` files are rendered as nunjucks templates
@@ -40,6 +40,19 @@ export function renderTemplate(ctx: RenderContext, src: string, dest: string) {
4040

4141
const filename = path.basename(src);
4242

43+
// Rename `_.file` to `.file` in the destination.
44+
if (filename.startsWith('_.')) {
45+
dest = path.resolve(path.dirname(dest), filename.replace(/^_./, '.'));
46+
}
47+
48+
// Concatenate .gitignore files.
49+
if (filename === '_.gitignore' && fs.existsSync(dest)) {
50+
const existing = fs.readFileSync(dest, 'utf8');
51+
const newGitignore = fs.readFileSync(src, 'utf8');
52+
fs.writeFileSync(dest, existing + '\n' + newGitignore);
53+
return;
54+
}
55+
4356
// Merge package.json files.
4457
if (filename === 'package.json' && fs.existsSync(dest)) {
4558
const existing = JSON.parse(fs.readFileSync(dest, 'utf8'));
@@ -49,14 +62,6 @@ export function renderTemplate(ctx: RenderContext, src: string, dest: string) {
4962
return;
5063
}
5164

52-
// Append to existing .gitignore.
53-
if (filename === '.gitignore' && fs.existsSync(dest)) {
54-
const existing = fs.readFileSync(dest, 'utf8');
55-
const newGitignore = fs.readFileSync(src, 'utf8');
56-
fs.writeFileSync(dest, existing + '\n' + newGitignore);
57-
return;
58-
}
59-
6065
// Render nunjucks templates.
6166
if (filename.endsWith('.njk')) {
6267
dest = dest.replace(/\.njk$/, '');

0 commit comments

Comments
 (0)