ramm 0.0.13 → 0.0.15

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
@@ -239,6 +239,7 @@ EOF`);
239
239
  };
240
240
  // src/files.ts
241
241
  import { appendFile, exists } from "fs/promises";
242
+ var {write } = globalThis.Bun;
242
243
 
243
244
  // src/path.ts
244
245
  import { homedir } from "os";
@@ -294,6 +295,11 @@ var writeIfNew = async (rawFilePath, str) => {
294
295
  }
295
296
  await appendFile(filePath, finalizeWithNewline(str));
296
297
  };
298
+ var writeFile = async (pathToFile, str) => {
299
+ const normalizedPath = normalizePath(pathToFile);
300
+ await createFileIfNeed(normalizedPath);
301
+ await write(normalizedPath, str);
302
+ };
297
303
  // src/ssh.ts
298
304
  import { debug } from "console";
299
305
  var addKeyToHostConfig = async (pathToHost, address, pathToKey) => {
@@ -333,8 +339,30 @@ var createAndAddSshKey = async (pathToKey, comment, context) => {
333
339
  debug(`Key is: ${pubKey}`);
334
340
  await addSshKey(pubKey, context);
335
341
  };
342
+ // src/cron.ts
343
+ var createCron = async ({
344
+ time,
345
+ pathToFile
346
+ }) => {
347
+ const constructedLine = `${time} ${pathToFile}`;
348
+ const tempFile = `/tmp/cron_${new Date().getTime().toString()}`;
349
+ const { output: cronConfig } = await execCommand("crontab -l");
350
+ let newCronConfig = cronConfig;
351
+ if (cronConfig.includes(constructedLine)) {
352
+ return;
353
+ }
354
+ if (cronConfig.includes(pathToFile)) {
355
+ newCronConfig = cronConfig.split(`
356
+ `).filter((str) => !str.includes(pathToFile)).join(`
357
+ `);
358
+ }
359
+ await writeFile(tempFile, newCronConfig);
360
+ await execCommand(`crontab ${tempFile}`);
361
+ await execCommand(`rm ${tempFile}`);
362
+ };
336
363
  export {
337
364
  writeIfNew,
365
+ writeFile,
338
366
  setupNftable,
339
367
  runPodmanContainerService,
340
368
  runPodmanContainer,
@@ -347,6 +375,7 @@ export {
347
375
  execCommand,
348
376
  execBySsh,
349
377
  debugBlock,
378
+ createCron,
350
379
  createAndAddSshKey,
351
380
  copyFilesBySsh,
352
381
  addNftPodmanRule,
@@ -0,0 +1,4 @@
1
+ export declare const createCron: ({ time, pathToFile, }: {
2
+ time: string;
3
+ pathToFile: string;
4
+ }) => Promise<void>;
@@ -7,6 +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 } from "./files.ts";
10
+ export { writeIfNew, writeFile } from "./files.ts";
11
11
  export { createAndAddSshKey, getServerFingerprintBySsh, addKeyToHostConfig, } from "./ssh.ts";
12
12
  export { normalizePath } from "./path.ts";
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.13",
4
+ "version": "0.0.15",
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"