ramm 0.0.16 → 0.0.18

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/ramm.js CHANGED
@@ -253,7 +253,10 @@ function normalizePath(rawFilePath) {
253
253
  }
254
254
 
255
255
  // src/files.ts
256
- var finalizeWithNewline = (str) => {
256
+ var normalizeFileContent = (str) => {
257
+ if (str === "") {
258
+ return str;
259
+ }
257
260
  if (str.at(-1) !== `
258
261
  `) {
259
262
  return str + `
@@ -293,7 +296,7 @@ var writeIfNew = async (rawFilePath, str) => {
293
296
  if (await checkStrInFile(filePath, str)) {
294
297
  return;
295
298
  }
296
- await appendFile(filePath, finalizeWithNewline(str));
299
+ await appendFile(filePath, normalizeFileContent(str));
297
300
  };
298
301
  var writeFile = async (pathToFile, str) => {
299
302
  const normalizedPath = normalizePath(pathToFile);
@@ -353,19 +356,22 @@ var createCron = async ({
353
356
  time,
354
357
  pathToFile
355
358
  }) => {
356
- const constructedLine = `${time} ${pathToFile}`;
359
+ const pathToFileNorm = normalizePath(pathToFile);
360
+ const constructedLine = `${time} ${pathToFileNorm}`;
357
361
  const tempFile = `/tmp/cron_${new Date().getTime().toString()}`;
358
362
  const { output: cronConfig } = await execCommand("crontab -l");
359
363
  let newCronConfig = cronConfig;
360
364
  if (cronConfig.includes(constructedLine)) {
361
365
  return;
362
366
  }
363
- if (cronConfig.includes(pathToFile)) {
367
+ if (cronConfig.includes(pathToFileNorm)) {
364
368
  newCronConfig = cronConfig.split(`
365
- `).filter((str) => !str.includes(pathToFile)).join(`
369
+ `).filter((str) => !str.includes(pathToFileNorm)).join(`
366
370
  `);
367
371
  }
372
+ newCronConfig = normalizeFileContent(normalizeFileContent(cronConfig) + constructedLine);
368
373
  await writeFile(tempFile, newCronConfig);
374
+ await execCommand(`cat ${tempFile}`);
369
375
  await execCommand(`crontab ${tempFile}`);
370
376
  await execCommand(`rm ${tempFile}`);
371
377
  };
@@ -378,6 +384,7 @@ export {
378
384
  runPodmanContainer,
379
385
  restartSystemdService,
380
386
  normalizePath,
387
+ normalizeFileContent,
381
388
  installSystemPackage,
382
389
  installPodman,
383
390
  installBun,
@@ -1,3 +1,4 @@
1
+ export declare const normalizeFileContent: (str: string) => string;
1
2
  export declare const writeIfNew: (rawFilePath: string, str: string) => Promise<void>;
2
3
  export declare const writeFile: (pathToFile: string, str: string) => Promise<void>;
3
4
  export declare const writeFileIfNotMatch: (pathToFile: string, str: string) => Promise<void>;
@@ -7,7 +7,7 @@ export { restartSystemdService } from "./systemd.ts";
7
7
  export { installSystemPackage } from "./packages.ts";
8
8
  export { debugBlock } from "./debug.ts";
9
9
  export { setupNftable } from "./nft.ts";
10
- export { writeIfNew, writeFile, writeFileIfNotMatch } from "./files.ts";
10
+ export { writeIfNew, writeFile, writeFileIfNotMatch, normalizeFileContent, } from "./files.ts";
11
11
  export { createAndAddSshKey, getServerFingerprintBySsh, addKeyToHostConfig, } from "./ssh.ts";
12
12
  export { normalizePath } from "./path.ts";
13
13
  export { createCron } from "./cron.ts";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ramm",
3
3
  "type": "module",
4
- "version": "0.0.16",
4
+ "version": "0.0.18",
5
5
  "scripts": {
6
6
  "build": "bun build ./src/ramm.ts --target bun --outdir ./dist && cp ./src/bun.sh ./dist/bun.sh && bun run types",
7
7
  "types": "tsc --project tsconfig.types.json"