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 +12 -5
- package/dist/types/files.d.ts +1 -0
- package/dist/types/ramm.d.ts +1 -1
- package/package.json +1 -1
package/dist/ramm.js
CHANGED
|
@@ -253,7 +253,10 @@ function normalizePath(rawFilePath) {
|
|
|
253
253
|
}
|
|
254
254
|
|
|
255
255
|
// src/files.ts
|
|
256
|
-
var
|
|
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,
|
|
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
|
|
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(
|
|
367
|
+
if (cronConfig.includes(pathToFileNorm)) {
|
|
364
368
|
newCronConfig = cronConfig.split(`
|
|
365
|
-
`).filter((str) => !str.includes(
|
|
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,
|
package/dist/types/files.d.ts
CHANGED
|
@@ -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>;
|
package/dist/types/ramm.d.ts
CHANGED
|
@@ -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