@dafish/gogo-meta 1.1.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -322,6 +322,23 @@ function listCommands(metaConfig) {
322
322
  command: normalizeCommand(config)
323
323
  }));
324
324
  }
325
+ async function addToGitignore(metaDir, entry) {
326
+ const gitignorePath = join(metaDir, ".gitignore");
327
+ if (await fileExists(gitignorePath)) {
328
+ const content = await readFile(gitignorePath, "utf-8");
329
+ const lines = content.split("\n").map((line) => line.trim());
330
+ if (lines.includes(entry)) {
331
+ return false;
332
+ }
333
+ const suffix = content.endsWith("\n") ? "" : "\n";
334
+ await appendFile(gitignorePath, `${suffix}${entry}
335
+ `);
336
+ } else {
337
+ await writeFile(gitignorePath, `${entry}
338
+ `, "utf-8");
339
+ }
340
+ return true;
341
+ }
325
342
  var symbols = {
326
343
  success: pc.green("\u2713"),
327
344
  error: pc.red("\u2717"),
@@ -1108,7 +1125,11 @@ async function importCommand(folder, url, options = {}) {
1108
1125
  const config2 = await readMetaConfig(metaDir);
1109
1126
  const updatedConfig2 = addProject(config2, folder, url);
1110
1127
  await writeMetaConfig(metaDir, updatedConfig2);
1128
+ const added2 = await addToGitignore(metaDir, folder);
1111
1129
  success(`Registered project "${folder}" (not cloned)`);
1130
+ if (added2) {
1131
+ info(`Added ${folder} to .gitignore`);
1132
+ }
1112
1133
  info(`Run "gogo git update" to clone missing projects`);
1113
1134
  return;
1114
1135
  }
@@ -1126,11 +1147,8 @@ async function importCommand(folder, url, options = {}) {
1126
1147
  await writeMetaConfig(metaDir, updatedConfig);
1127
1148
  success(`Imported project "${folder}"`);
1128
1149
  }
1129
- const gitignorePath = join(metaDir, ".gitignore");
1130
- if (await fileExists(gitignorePath)) {
1131
- await appendFile(gitignorePath, `
1132
- ${folder}
1133
- `);
1150
+ const added = await addToGitignore(metaDir, folder);
1151
+ if (added) {
1134
1152
  info(`Added ${folder} to .gitignore`);
1135
1153
  }
1136
1154
  }