Skip to content

Commit

Permalink
Merge pull request #58 from Hugos68/dev
Browse files Browse the repository at this point in the history
Improved gitignore job, now adds missing lines, otherwise skips
  • Loading branch information
Hugos68 authored Sep 25, 2023
2 parents 7a02fcd + 8a784a3 commit 2f8c587
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
5 changes: 5 additions & 0 deletions .changeset/swift-radios-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'capkit': patch
---

Improved gitignore job, fills in missing gitignores
30 changes: 12 additions & 18 deletions src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,24 +174,18 @@ export async function initializeProject({ appName, appId, platforms, plugins }:
});

if (existsSync(`${process.cwd()}/.gitignore`)) {
const gitignore = await fs.readFile(`${process.cwd()}/.gitignore`, 'utf-8');
if (!gitignore.includes('# Capacitor')) {
jobs.push({
start: `Configuring: "${kleur.cyan('.gitignore')}"`,
stop: `Successfully configured: "${kleur.cyan('.gitignore')}"`,
task: async () => {
const gitignores = [
'# Capacitor',
'/android',
'/ios',
'capacitor.config.json.timestamp-*'
];
const gitignore = await fs.readFile(`${process.cwd()}/.gitignore`, 'utf-8');
const newGitignore = gitignore + '\n' + gitignores.join('\n');
return fs.writeFile('.gitignore', newGitignore, 'utf-8');
}
});
}
jobs.push({
start: `Configuring: "${kleur.cyan('.gitignore')}"`,
stop: `Successfully configured: "${kleur.cyan('.gitignore')}"`,
task: async () => {
const lines = ['# Capacitor', '/android', '/ios', 'capacitor.config.json.timestamp-*'];
const gitignore = await fs.readFile(`${process.cwd()}/.gitignore`, 'utf-8');
const uniqueLines = lines.filter((line) => !gitignore.includes(line));
if (uniqueLines.length === 0) return;
const newGitignore = gitignore + '\n' + uniqueLines.join('\n');
return fs.writeFile('.gitignore', newGitignore, 'utf-8');
}
});
}

/* Install jobs */
Expand Down

0 comments on commit 2f8c587

Please sign in to comment.