Skip to content

Commit

Permalink
Fix create-svelte build-template script (#1555)
Browse files Browse the repository at this point in the history
With the addition of `/package` to `.gitignore`, the `package.template.json` is filtered out. Put it at the top to avoid that.
  • Loading branch information
dummdidumm authored May 25, 2021
1 parent 8d5b3e9 commit f211906
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .changeset/weak-parents-guess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'create-svelte': patch
---

Adjust build-template script to include package.json
33 changes: 17 additions & 16 deletions packages/create-svelte/scripts/build-templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,29 @@ async function generate_templates(shared) {
const ts = [];

glob('**/*', { cwd, filesOnly: true, dot: true }).forEach((name) => {
// the package.template.json thing is a bit annoying — basically we want
// to be able to develop and deploy the app from here, but have a different
// package.json in newly created projects (based on package.template.json)
if (name === 'package.template.json') {
let contents = fs.readFileSync(path.join(cwd, name), 'utf8');
// TODO package-specific versions
contents = contents.replace(/workspace:\*/g, 'next');
fs.writeFileSync(`${dir}/package.json`, contents);
return;
}

// ignore files that are written conditionally
if (shared.has(name)) return;

// ignore contents of .gitignore or .ignore
if (!gitignore.accepts(name) || !ignore.accepts(name) || name === '.ignore') return;

// the package.template.json thing is a bit annoying — basically we want
// to be able to develop and deploy the app from here, but have a different
// package.json in newly created projects (based on package.template.json)
if (/\.(js|ts|svelte|svelte\.md)$/.test(name) || name === 'package.template.json') {
let contents = fs.readFileSync(path.join(cwd, name), 'utf8');

if (name === 'package.template.json') {
// TODO package-specific versions
contents = contents.replace(/workspace:\*/g, 'next');
fs.writeFileSync(`${dir}/package.json`, contents);
} else {
ts.push({
name,
contents
});
}
if (/\.(js|ts|svelte|svelte\.md)$/.test(name)) {
const contents = fs.readFileSync(path.join(cwd, name), 'utf8');
ts.push({
name,
contents
});
} else {
const dest = path.join(assets, name).replace('.gitignore', 'gitignore'); // npm does wacky stuff to gitignores
mkdirp(path.dirname(dest));
Expand Down

0 comments on commit f211906

Please sign in to comment.