Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions create/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export async function main({ cwd, templateDir, exampleTemplatesDir, targetDir, e
errorOnExist: true,
});

// npm strips `.gitignore` from published packages, so the template ships it as
// `gitignore`. Restore the dotfile name in the generated project.
await restoreGitignore(targetDir);

const EXAMPLE_ENV_PATH = path.join(targetDir, '.env.example');
const ENV_PATH = path.join(targetDir, '.env');
const PKG_PATH = path.join(targetDir, 'package.json');
Expand Down Expand Up @@ -100,6 +104,8 @@ export async function main({ cwd, templateDir, exampleTemplatesDir, targetDir, e
errorOnExist: true,
});

await restoreGitignore(exampleTargetDir);

// Apply the same token replacements as for the main project, remapped to exampleTargetDir.
const remap = (f) => path.join(exampleTargetDir, path.relative(targetDir, f));
await replaceTokensInFiles(filesWithAppTitle.map(remap), appTitleRegex, APP_TITLE);
Expand Down Expand Up @@ -148,6 +154,18 @@ What's next?
);
}

async function restoreGitignore(dir) {
const shipped = path.join(dir, 'gitignore');
const dotfile = path.join(dir, '.gitignore');
try {
await fs.rename(shipped, dotfile);
} catch (error) {
if (error.code !== 'ENOENT') {
throw error;
}
}
}

async function mergeExampleFiles(sourceDir, targetDir) {
const entries = await fs.readdir(sourceDir, { recursive: true, withFileTypes: true });
for (const entry of entries) {
Expand Down
15 changes: 13 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,17 @@
"files": [
"template",
"example-templates",
"create"
"create",
"!**/node_modules/**",
"!**/dist/**",
"!**/build/**",
"!**/.turbo/**",
"!**/.react-router/**",
"!**/coverage/**",
"!**/data-mocks/**",
"!**/.cache/**",
"!**/*.tsbuildinfo",
"!**/package-lock.json"
],
"engines": {
"node": ">=22.3.0"
Expand All @@ -33,7 +43,8 @@
"create-tinker-stack"
],
"scripts": {
"prerelease": "find template example-templates -name package-lock.json -delete && find template example-templates -name tsconfig.tsbuildinfo -delete && find template example-templates -name .turbo -type d -prune -exec rm -rf {} +",
"clean:template": "find template example-templates -type d \\( -name node_modules -o -name dist -o -name build -o -name .turbo -o -name .react-router -o -name coverage -o -name data-mocks -o -name .cache \\) -prune -exec rm -rf {} + && find template example-templates -type f \\( -name package-lock.json -o -name '*.tsbuildinfo' \\) -delete",
"prerelease": "npm run clean:template",
"release": "commit-and-tag-version",
"test": "npm run test:e2e",
"test:e2e": "vitest run --no-file-parallelism",
Expand Down
3 changes: 3 additions & 0 deletions template/.gitignore → template/gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ data-mocks/
vite.config.ts.timestamp-*
.playwright-mcp/

# Example templates (self-contained, generated into examples/<name>/)
examples/

# Misc
.DS_Store
*.pem
Expand Down
11 changes: 11 additions & 0 deletions tests/generator.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ describe('create-tinker-stack generator', () => {
);
expect(examplePackageJson.scripts).toHaveProperty('build');

// npm strips `.gitignore` from published packages, so the template ships
// it as `gitignore` and the generator restores the dotfile name.
const gitignore = await readFile(path.join(projectDir, '.gitignore'), 'utf8');
expect(gitignore).toContain('node_modules');
expect(gitignore).toContain('examples/');
await expect(readFile(path.join(projectDir, 'gitignore'), 'utf8'))
.rejects.toMatchObject({ code: 'ENOENT' });
await expect(readFile(path.join(exampleDir, '.gitignore'), 'utf8')).resolves.toContain(
'node_modules'
);

await runCommand('npm', ['install'], { cwd: projectDir });
await runCommand('npm', ['run', 'typecheck'], { cwd: projectDir });
await runCommand('npm', ['run', 'build:data'], { cwd: projectDir });
Expand Down
Loading