Updates
This commit is contained in:
parent
8865292893
commit
a71614cb0f
16
bun.lock
Normal file
16
bun.lock
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"lockfileVersion": 1,
|
||||||
|
"workspaces": {
|
||||||
|
"": {
|
||||||
|
"name": "@moduletrace/turbosync",
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/node": "^22.10.2",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"packages": {
|
||||||
|
"@types/node": ["@types/node@22.10.2", "", { "dependencies": { "undici-types": "~6.20.0" } }, "sha512-Xxr6BBRCAOQixvonOye19wnzyDiUtTeqldOOmj3CkeblonbccA12PFwlufvRdrpjXxqnmUaeiU5EOA+7s5diUQ=="],
|
||||||
|
|
||||||
|
"undici-types": ["undici-types@6.20.0", "", {}, "sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg=="],
|
||||||
|
}
|
||||||
|
}
|
4
dist/index.d.ts
vendored
4
dist/index.d.ts
vendored
@ -1,5 +1,7 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
declare global {
|
declare global {
|
||||||
var SYNCING: boolean;
|
var SYNC_SUCCESS_EXIT_CODE: number;
|
||||||
|
var CONFIG_DIR: string;
|
||||||
|
var SYNCING_FILE: string;
|
||||||
}
|
}
|
||||||
export {};
|
export {};
|
||||||
|
6
dist/index.js
vendored
6
dist/index.js
vendored
@ -8,8 +8,12 @@ const fs_1 = __importDefault(require("fs"));
|
|||||||
const path_1 = __importDefault(require("path"));
|
const path_1 = __importDefault(require("path"));
|
||||||
const child_process_1 = require("child_process");
|
const child_process_1 = require("child_process");
|
||||||
const env_1 = __importDefault(require("./utils/env"));
|
const env_1 = __importDefault(require("./utils/env"));
|
||||||
global.SYNCING = false;
|
|
||||||
const confFileProvidedPath = process.argv[process.argv.length - 1];
|
const confFileProvidedPath = process.argv[process.argv.length - 1];
|
||||||
|
global.CONFIG_DIR = process.cwd();
|
||||||
|
global.SYNCING_FILE = path_1.default.join(global.CONFIG_DIR, "syncing.txt");
|
||||||
|
if (fs_1.default.existsSync(global.SYNCING_FILE)) {
|
||||||
|
fs_1.default.unlinkSync(global.SYNCING_FILE);
|
||||||
|
}
|
||||||
if (confFileProvidedPath === "--version" || confFileProvidedPath === "-v") {
|
if (confFileProvidedPath === "--version" || confFileProvidedPath === "-v") {
|
||||||
try {
|
try {
|
||||||
const packageJson = fs_1.default.readFileSync(path_1.default.resolve(__dirname, "../package.json"), "utf-8");
|
const packageJson = fs_1.default.readFileSync(path_1.default.resolve(__dirname, "../package.json"), "utf-8");
|
||||||
|
12
dist/lib/sync.js
vendored
12
dist/lib/sync.js
vendored
@ -3,12 +3,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
const fs_1 = __importDefault(require("fs"));
|
||||||
const child_process_1 = require("child_process");
|
const child_process_1 = require("child_process");
|
||||||
const files_1 = __importDefault(require("./watch/files"));
|
const files_1 = __importDefault(require("./watch/files"));
|
||||||
const folders_1 = __importDefault(require("./watch/folders"));
|
const folders_1 = __importDefault(require("./watch/folders"));
|
||||||
|
const path_1 = __importDefault(require("path"));
|
||||||
const confFileProvidedJSON = process.argv[process.argv.length - 1];
|
const confFileProvidedJSON = process.argv[process.argv.length - 1];
|
||||||
global.SYNCING = false;
|
global.SYNC_SUCCESS_EXIT_CODE = 32;
|
||||||
|
global.CONFIG_DIR = process.cwd();
|
||||||
|
global.SYNCING_FILE = path_1.default.join(global.CONFIG_DIR, "syncing.txt");
|
||||||
try {
|
try {
|
||||||
|
if (fs_1.default.existsSync(global.SYNCING_FILE)) {
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
const configFileObject = JSON.parse(confFileProvidedJSON);
|
const configFileObject = JSON.parse(confFileProvidedJSON);
|
||||||
console.log(`Running '${configFileObject.title}' ...`);
|
console.log(`Running '${configFileObject.title}' ...`);
|
||||||
if (Array.isArray(configFileObject.files) &&
|
if (Array.isArray(configFileObject.files) &&
|
||||||
@ -32,7 +39,8 @@ catch (error) {
|
|||||||
process.exit();
|
process.exit();
|
||||||
}
|
}
|
||||||
process.on("exit", (code) => {
|
process.on("exit", (code) => {
|
||||||
if (code == 1) {
|
if (code == global.SYNC_SUCCESS_EXIT_CODE) {
|
||||||
|
fs_1.default.unlinkSync(global.SYNCING_FILE);
|
||||||
const args = process.argv;
|
const args = process.argv;
|
||||||
const cmd = args.shift();
|
const cmd = args.shift();
|
||||||
if (cmd) {
|
if (cmd) {
|
||||||
|
6
dist/lib/watch/files.js
vendored
6
dist/lib/watch/files.js
vendored
@ -72,16 +72,16 @@ function watchFiles(_a) {
|
|||||||
fs_1.default.watchFile(filePath, {
|
fs_1.default.watchFile(filePath, {
|
||||||
interval: interval || 200,
|
interval: interval || 200,
|
||||||
}, (curr, prev) => {
|
}, (curr, prev) => {
|
||||||
if (global.SYNCING)
|
if (fs_1.default.existsSync(global.SYNCING_FILE))
|
||||||
return;
|
return;
|
||||||
const INTERVAL = (options === null || options === void 0 ? void 0 : options.interval)
|
const INTERVAL = (options === null || options === void 0 ? void 0 : options.interval)
|
||||||
? options.interval
|
? options.interval
|
||||||
: UPDATE_TIMEOUT;
|
: UPDATE_TIMEOUT;
|
||||||
clearTimeout(timeout);
|
clearTimeout(timeout);
|
||||||
timeout = setTimeout(() => {
|
timeout = setTimeout(() => {
|
||||||
global.SYNCING = true;
|
fs_1.default.writeFileSync(global.SYNCING_FILE, `SYNCING FILE: curr:${curr} :: prev:${prev}`);
|
||||||
sync({ options, filePath, files });
|
sync({ options, filePath, files });
|
||||||
process.exit(1);
|
process.exit(global.SYNC_SUCCESS_EXIT_CODE);
|
||||||
}, INTERVAL);
|
}, INTERVAL);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
12
dist/lib/watch/folders.js
vendored
12
dist/lib/watch/folders.js
vendored
@ -79,13 +79,18 @@ function watchFolders(_a) {
|
|||||||
sync({ dirPath, dirs, options });
|
sync({ dirPath, dirs, options });
|
||||||
yield (0, delay_1.default)();
|
yield (0, delay_1.default)();
|
||||||
fs_1.default.watch(dirPath, { recursive: true }, (evt, fileName) => {
|
fs_1.default.watch(dirPath, { recursive: true }, (evt, fileName) => {
|
||||||
if (global.SYNCING)
|
console.log("Folder Changed", evt, fileName);
|
||||||
|
if (fs_1.default.existsSync(global.SYNCING_FILE)) {
|
||||||
|
console.log("Existing Sync found. Returning ...");
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
clearTimeout(timeout);
|
clearTimeout(timeout);
|
||||||
timeout = setTimeout(() => {
|
timeout = setTimeout(() => {
|
||||||
global.SYNCING = true;
|
console.log("Folder Syncing in progress ...");
|
||||||
|
console.log(`Writing Sync File =>${global.SYNCING_FILE}`);
|
||||||
|
fs_1.default.writeFileSync(global.SYNCING_FILE, `SYNCING Folder: evt:${evt} :: fileName:${fileName}`);
|
||||||
sync({ dirPath, dirs, options });
|
sync({ dirPath, dirs, options });
|
||||||
process.exit(1);
|
process.exit(global.SYNC_SUCCESS_EXIT_CODE);
|
||||||
}, INTERVAL);
|
}, INTERVAL);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -159,4 +164,5 @@ function sync({ options, dirs, dirPath, init }) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
console.log("Folder Sync Complete. Exiting ...");
|
||||||
}
|
}
|
||||||
|
1
dist/test/test-1/folder-1/test-folder/test-file.d.ts
vendored
Normal file
1
dist/test/test-1/folder-1/test-folder/test-file.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
declare var l: string;
|
2
dist/test/test-1/folder-1/test-folder/test-file.js
vendored
Normal file
2
dist/test/test-1/folder-1/test-folder/test-file.js
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
"use strict";
|
||||||
|
var l = "Hi There #8";
|
2
dist/test/test-1/folder-1/test.js
vendored
2
dist/test/test-1/folder-1/test.js
vendored
@ -1,3 +1,3 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const testVar = 35;
|
const testVar = 37;
|
||||||
|
1
dist/test/test-1/folder-2/test-file-2.js
vendored
1
dist/test/test-1/folder-2/test-file-2.js
vendored
@ -1,3 +1,2 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const testVar = 5;
|
|
||||||
|
1
dist/test/test-1/folder-2/test-folder/test-file.d.ts
vendored
Normal file
1
dist/test/test-1/folder-2/test-folder/test-file.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
declare var l: string;
|
2
dist/test/test-1/folder-2/test-folder/test-file.js
vendored
Normal file
2
dist/test/test-1/folder-2/test-folder/test-file.js
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
"use strict";
|
||||||
|
var l = "Hi There #7";
|
2
dist/test/test-1/folder-2/test.js
vendored
2
dist/test/test-1/folder-2/test.js
vendored
@ -1,3 +1,3 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const testVar = 35;
|
const testVar = 37;
|
||||||
|
13
index.ts
13
index.ts
@ -7,15 +7,20 @@ import handleEnvVars from "./utils/env";
|
|||||||
import { TurboSyncConfigArray } from "./types";
|
import { TurboSyncConfigArray } from "./types";
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
var SYNCING: boolean;
|
|
||||||
var SYNC_SUCCESS_EXIT_CODE: number;
|
var SYNC_SUCCESS_EXIT_CODE: number;
|
||||||
|
var CONFIG_DIR: string;
|
||||||
|
var SYNCING_FILE: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
global.SYNCING = false;
|
|
||||||
global.SYNC_SUCCESS_EXIT_CODE = 32;
|
|
||||||
|
|
||||||
const confFileProvidedPath = process.argv[process.argv.length - 1];
|
const confFileProvidedPath = process.argv[process.argv.length - 1];
|
||||||
|
|
||||||
|
global.CONFIG_DIR = process.cwd();
|
||||||
|
global.SYNCING_FILE = path.join(global.CONFIG_DIR, "syncing.txt");
|
||||||
|
|
||||||
|
if (fs.existsSync(global.SYNCING_FILE)) {
|
||||||
|
fs.unlinkSync(global.SYNCING_FILE);
|
||||||
|
}
|
||||||
|
|
||||||
if (confFileProvidedPath === "--version" || confFileProvidedPath === "-v") {
|
if (confFileProvidedPath === "--version" || confFileProvidedPath === "-v") {
|
||||||
try {
|
try {
|
||||||
const packageJson = fs.readFileSync(
|
const packageJson = fs.readFileSync(
|
||||||
|
12
lib/sync.ts
12
lib/sync.ts
@ -1,13 +1,21 @@
|
|||||||
|
import fs from "fs";
|
||||||
import { spawn } from "child_process";
|
import { spawn } from "child_process";
|
||||||
import watchFiles from "./watch/files";
|
import watchFiles from "./watch/files";
|
||||||
import watchFolders from "./watch/folders";
|
import watchFolders from "./watch/folders";
|
||||||
import { TurboSyncConfigObject } from "../types";
|
import { TurboSyncConfigObject } from "../types";
|
||||||
|
import path from "path";
|
||||||
|
|
||||||
const confFileProvidedJSON = process.argv[process.argv.length - 1];
|
const confFileProvidedJSON = process.argv[process.argv.length - 1];
|
||||||
|
|
||||||
global.SYNCING = false;
|
global.SYNC_SUCCESS_EXIT_CODE = 32;
|
||||||
|
global.CONFIG_DIR = process.cwd();
|
||||||
|
global.SYNCING_FILE = path.join(global.CONFIG_DIR, "syncing.txt");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if (fs.existsSync(global.SYNCING_FILE)) {
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
const configFileObject: TurboSyncConfigObject =
|
const configFileObject: TurboSyncConfigObject =
|
||||||
JSON.parse(confFileProvidedJSON);
|
JSON.parse(confFileProvidedJSON);
|
||||||
|
|
||||||
@ -39,6 +47,8 @@ try {
|
|||||||
|
|
||||||
process.on("exit", (code) => {
|
process.on("exit", (code) => {
|
||||||
if (code == global.SYNC_SUCCESS_EXIT_CODE) {
|
if (code == global.SYNC_SUCCESS_EXIT_CODE) {
|
||||||
|
fs.unlinkSync(global.SYNCING_FILE);
|
||||||
|
|
||||||
const args = process.argv;
|
const args = process.argv;
|
||||||
const cmd = args.shift();
|
const cmd = args.shift();
|
||||||
if (cmd) {
|
if (cmd) {
|
||||||
|
@ -3,14 +3,13 @@ import fs from "fs";
|
|||||||
import delay from "../../utils/delay";
|
import delay from "../../utils/delay";
|
||||||
import { SyncFilesFnParams, SyncFilesSyncFnParams } from "../../types";
|
import { SyncFilesFnParams, SyncFilesSyncFnParams } from "../../types";
|
||||||
|
|
||||||
|
|
||||||
export default async function watchFiles({
|
export default async function watchFiles({
|
||||||
files,
|
files,
|
||||||
options,
|
options,
|
||||||
}: SyncFilesFnParams) {
|
}: SyncFilesFnParams) {
|
||||||
let timeout: any;
|
let timeout: any;
|
||||||
const UPDATE_TIMEOUT = 2000;
|
const UPDATE_TIMEOUT = 2000;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (let i = 0; i < files.length; i++) {
|
for (let i = 0; i < files.length; i++) {
|
||||||
const file = files[i];
|
const file = files[i];
|
||||||
@ -73,7 +72,7 @@ export default async function watchFiles({
|
|||||||
interval: interval || 200,
|
interval: interval || 200,
|
||||||
},
|
},
|
||||||
(curr, prev) => {
|
(curr, prev) => {
|
||||||
if (global.SYNCING) return;
|
if (fs.existsSync(global.SYNCING_FILE)) return;
|
||||||
|
|
||||||
const INTERVAL = options?.interval
|
const INTERVAL = options?.interval
|
||||||
? options.interval
|
? options.interval
|
||||||
@ -82,9 +81,12 @@ export default async function watchFiles({
|
|||||||
clearTimeout(timeout);
|
clearTimeout(timeout);
|
||||||
|
|
||||||
timeout = setTimeout(() => {
|
timeout = setTimeout(() => {
|
||||||
global.SYNCING = true;
|
fs.writeFileSync(
|
||||||
|
global.SYNCING_FILE,
|
||||||
|
`SYNCING FILE: curr:${curr} :: prev:${prev}`
|
||||||
|
);
|
||||||
sync({ options, filePath, files });
|
sync({ options, filePath, files });
|
||||||
process.exit(1);
|
process.exit(global.SYNC_SUCCESS_EXIT_CODE);
|
||||||
}, INTERVAL);
|
}, INTERVAL);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -11,10 +11,6 @@ export default async function watchFolders({
|
|||||||
let timeout: any;
|
let timeout: any;
|
||||||
const UPDATE_TIMEOUT = 200;
|
const UPDATE_TIMEOUT = 200;
|
||||||
|
|
||||||
if (global.SYNCING) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const dirs = folders;
|
const dirs = folders;
|
||||||
|
|
||||||
@ -89,17 +85,26 @@ export default async function watchFolders({
|
|||||||
await delay();
|
await delay();
|
||||||
|
|
||||||
fs.watch(dirPath, { recursive: true }, (evt, fileName) => {
|
fs.watch(dirPath, { recursive: true }, (evt, fileName) => {
|
||||||
if (global.SYNCING) return;
|
console.log("Folder Changed", evt, fileName);
|
||||||
|
|
||||||
|
if (fs.existsSync(global.SYNCING_FILE)) {
|
||||||
|
console.log("Existing Sync found. Returning ...");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
clearTimeout(timeout);
|
clearTimeout(timeout);
|
||||||
|
|
||||||
timeout = setTimeout(() => {
|
timeout = setTimeout(() => {
|
||||||
global.SYNCING = true;
|
console.log("Folder Syncing in progress ...");
|
||||||
|
console.log(
|
||||||
|
`Writing Sync File =>${global.SYNCING_FILE}`
|
||||||
|
);
|
||||||
|
fs.writeFileSync(
|
||||||
|
global.SYNCING_FILE,
|
||||||
|
`SYNCING Folder: evt:${evt} :: fileName:${fileName}`
|
||||||
|
);
|
||||||
sync({ dirPath, dirs, options });
|
sync({ dirPath, dirs, options });
|
||||||
setTimeout(() => {
|
process.exit(global.SYNC_SUCCESS_EXIT_CODE);
|
||||||
global.SYNCING = false;
|
|
||||||
process.exit(global.SYNC_SUCCESS_EXIT_CODE);
|
|
||||||
}, 500);
|
|
||||||
}, INTERVAL);
|
}, INTERVAL);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -188,4 +193,6 @@ function sync({ options, dirs, dirPath, init }: SyncFoldersSyncFnParams) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log("Folder Sync Complete. Exiting ...");
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@moduletrace/turbosync",
|
"name": "@moduletrace/turbosync",
|
||||||
"version": "1.0.8",
|
"version": "1.0.9",
|
||||||
"module": "dist/index.js",
|
"module": "dist/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node dist/index.js",
|
"start": "node dist/index.js",
|
||||||
|
Loading…
Reference in New Issue
Block a user