diff --git a/dist/index.d.ts b/dist/index.d.ts new file mode 100644 index 0000000..237deca --- /dev/null +++ b/dist/index.d.ts @@ -0,0 +1,2 @@ +#! /usr/bin/env node +export {}; diff --git a/dist/index.js b/dist/index.js new file mode 100644 index 0000000..6efe909 --- /dev/null +++ b/dist/index.js @@ -0,0 +1,70 @@ +#! /usr/bin/env node +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const fs_1 = __importDefault(require("fs")); +const path_1 = __importDefault(require("path")); +const child_process_1 = require("child_process"); +const env_1 = __importDefault(require("./utils/env")); +const confFileProvidedPath = process.argv[process.argv.length - 1]; +if (confFileProvidedPath === "--version" || confFileProvidedPath === "-v") { + try { + const packageJson = fs_1.default.readFileSync(path_1.default.resolve(__dirname, "package.json"), "utf8"); + console.log(`Turbo Sync Version: ${JSON.parse(packageJson).version}`); + } + catch (error) { + console.log("Turbo Sync Version fetch failed! \nNo Worries, Turbo Sync is still installed properly"); + } + process.exit(6); +} +console.log("Running Folder Sync ..."); +const defaultConfigFilePath = path_1.default.resolve(process.cwd(), "turbosync.config.json"); +const confFileComputedPath = typeof confFileProvidedPath == "string" && + confFileProvidedPath.endsWith(".json") + ? path_1.default.resolve(process.cwd(), confFileProvidedPath) + : null; +if (!fs_1.default.existsSync(defaultConfigFilePath) && !confFileComputedPath) { + console.log("Please Provide the path to a config file or add a config file named `turbosync.config.json` to the path you're running this program"); + process.exit(); +} +if (!defaultConfigFilePath && + confFileComputedPath && + !fs_1.default.existsSync(confFileComputedPath)) { + console.log("Config File does not exist"); + process.exit(); +} +try { + const configFinalPath = fs_1.default.existsSync(defaultConfigFilePath) + ? defaultConfigFilePath + : confFileComputedPath && fs_1.default.existsSync(confFileComputedPath) + ? confFileComputedPath + : null; + const configJSON = configFinalPath + ? fs_1.default.readFileSync(configFinalPath, "utf8") + : null; + if (!configJSON) + throw new Error("Config JSON could not be resolved. Please check your files."); + const parsedConfigJSON = (0, env_1.default)({ json: configJSON }); + /** @type {import(".").TurboSyncConfigArray} */ + const configArray = JSON.parse(parsedConfigJSON); + for (let i = 0; i < configArray.length; i++) { + const config = configArray[i]; + console.log(`Syncing \`${config.title} ...\``); + const childProcess = (0, child_process_1.spawn)("node", [ + path_1.default.resolve(__dirname, "./lib/sync.js"), + `${JSON.stringify(config)}`, + ], { + stdio: "inherit", + detached: false, + }); + } +} +catch (error) { + console.log(`Process Error =>`, error.message); + process.exit(); +} +setInterval(() => { + console.log(`Turbo Sync Running for ${process.uptime().toLocaleString()}s ...`); +}, 60000); diff --git a/dist/lib/sync.d.ts b/dist/lib/sync.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/dist/lib/sync.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/lib/sync.js b/dist/lib/sync.js new file mode 100644 index 0000000..93e4795 --- /dev/null +++ b/dist/lib/sync.js @@ -0,0 +1,46 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const child_process_1 = require("child_process"); +const files_1 = __importDefault(require("./watch/files")); +const folders_1 = __importDefault(require("./watch/folders")); +const confFileProvidedJSON = process.argv[process.argv.length - 1]; +try { + const configFileObject = JSON.parse(confFileProvidedJSON); + console.log(`Running '${configFileObject.title}' ...`); + if (Array.isArray(configFileObject.files) && + Array.isArray(configFileObject.folders)) { + throw new Error("Choose wither `files` or `folders`. Not both"); + } + const files = configFileObject === null || configFileObject === void 0 ? void 0 : configFileObject.files; + const firstFile = files === null || files === void 0 ? void 0 : files[0]; + const folders = configFileObject === null || configFileObject === void 0 ? void 0 : configFileObject.folders; + const firstFolder = folders === null || folders === void 0 ? void 0 : folders[0]; + const options = configFileObject.options; + if (firstFile && (files === null || files === void 0 ? void 0 : files[0])) { + (0, files_1.default)({ files, options }); + } + else if (firstFolder && (folders === null || folders === void 0 ? void 0 : folders[0])) { + (0, folders_1.default)({ folders, options }); + } +} +catch (error) { + console.log(error); + process.exit(); +} +process.on("exit", (code) => { + if (code == 1) { + const args = process.argv; + const cmd = args.shift(); + if (cmd) { + (0, child_process_1.spawn)(cmd, args, { + stdio: "inherit", + }); + } + } + else { + process.exit(0); + } +}); diff --git a/dist/lib/watch/files.d.ts b/dist/lib/watch/files.d.ts new file mode 100644 index 0000000..f01ced6 --- /dev/null +++ b/dist/lib/watch/files.d.ts @@ -0,0 +1,2 @@ +import { SyncFilesFnParams } from "../../types"; +export default function watchFiles({ files, options, }: SyncFilesFnParams): Promise; diff --git a/dist/lib/watch/files.js b/dist/lib/watch/files.js new file mode 100644 index 0000000..0a9415b --- /dev/null +++ b/dist/lib/watch/files.js @@ -0,0 +1,152 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.default = watchFiles; +const child_process_1 = require("child_process"); +const fs_1 = __importDefault(require("fs")); +const delay_1 = __importDefault(require("../../utils/delay")); +let timeout; +const UPDATE_TIMEOUT = 2000; +function watchFiles(_a) { + return __awaiter(this, arguments, void 0, function* ({ files, options, }) { + try { + for (let i = 0; i < files.length; i++) { + const file = files[i]; + const filePath = typeof file == "string" ? file : (file === null || file === void 0 ? void 0 : file.path) ? file.path : null; + const interval = typeof file == "object" ? file.interval : null; + if (!filePath) + continue; + if (typeof file == "string" && !fs_1.default.existsSync(filePath)) { + try { + const existingFilePath = files.find((fl) => { + if (typeof fl == "string") + return fs_1.default.existsSync(fl); + if (!fl.host) + return fs_1.default.existsSync(fl.path); // TODO handle remote + }); + if (!existingFilePath) { + throw new Error("No existing Files for reference"); + } + const fileDirPath = typeof existingFilePath == "string" + ? existingFilePath + : existingFilePath.path; + if (!fs_1.default.existsSync(fileDirPath)) { + fs_1.default.mkdirSync(fileDirPath, { recursive: true }); + } + fs_1.default.writeFileSync(filePath, ""); + if (typeof existingFilePath == "string") { + sync({ filePath: existingFilePath, files, options }); + } + else { + sync({ + filePath: existingFilePath.path, + files, + options, + }); + } + } + catch (error) { + throw new Error(`File Doesn't exist and couldn't be created. Please check if Directory exists.\nERROR => ${error.message}`); + } + } + if (typeof file == "string" && !fs_1.default.statSync(filePath).isFile()) { + throw new Error(`'${filePath}' is not a File!`); + } + if (typeof file == "object" && file.host) { + // TODO Handle SSH + } + else if (typeof file == "string") { + sync({ options, filePath, files }); + yield (0, delay_1.default)(); + fs_1.default.watchFile(filePath, { + interval: interval || 500, + }, (curr, prev) => { + const INTERVAL = (options === null || options === void 0 ? void 0 : options.interval) + ? options.interval + : UPDATE_TIMEOUT; + clearTimeout(timeout); + timeout = setTimeout(() => { + sync({ options, filePath, files }); + process.exit(1); + }, INTERVAL); + }); + } + } + } + catch (error) { + console.log("ERROR:", error.message); + process.exit(0); + } + }); +} +function sync({ options, filePath, files }) { + var _a; + const destFiles = files.filter((fl) => { + if (typeof fl == "string") + return fl !== filePath; + if (fl === null || fl === void 0 ? void 0 : fl.path) + return fl.path !== filePath; + return false; + }); + for (let j = 0; j < destFiles.length; j++) { + let cmdArray = ["rsync", "-avh"]; + if (options === null || options === void 0 ? void 0 : options.delete) { + cmdArray.push("--delete"); + } + if ((_a = options === null || options === void 0 ? void 0 : options.exclude) === null || _a === void 0 ? void 0 : _a[0]) { + options.exclude.forEach((excl) => { + cmdArray.push(`--exclude '${excl}'`); + }); + } + const dstFl = destFiles[j]; + if (typeof dstFl == "string") { + if (!fs_1.default.existsSync(dstFl)) + continue; + if (filePath === dstFl) { + console.log(`You can't sync the same paths. Please check your configuration and resolve duplicate paths`); + process.exit(6); + } + cmdArray.push(filePath, dstFl); + const cmd = cmdArray.join(" "); + console.log(`Running cmd 1 => ${cmd}`); + (0, child_process_1.execSync)(cmd, { + stdio: "inherit", + }); + } + else if (dstFl.path) { + if (!dstFl.host && !fs_1.default.existsSync(dstFl.path)) + continue; + if (filePath === dstFl.path) { + console.log(`You can't sync the same paths. Please check your configuration and resolve duplicate paths`); + process.exit(6); + } + if (dstFl.host && dstFl.ssh_key && dstFl.user) { + cmdArray.push("-e", `'ssh -i ${dstFl.ssh_key}'`); + cmdArray.push(filePath, `${dstFl.user}@${dstFl.host}:${dstFl.path}`); + const cmd = cmdArray.join(" "); + (0, child_process_1.execSync)(cmd, { + stdio: "inherit", + }); + } + else { + cmdArray.push(filePath, dstFl.path); + const cmd = cmdArray.join(" "); + console.log(`Running cmd 2 => ${cmd}`); + (0, child_process_1.execSync)(cmd, { + stdio: "inherit", + }); + } + } + } +} diff --git a/dist/lib/watch/folders.d.ts b/dist/lib/watch/folders.d.ts new file mode 100644 index 0000000..53ff457 --- /dev/null +++ b/dist/lib/watch/folders.d.ts @@ -0,0 +1,2 @@ +import { SyncFoldersFnParams } from "../../types"; +export default function watchFolders({ folders, options, }: SyncFoldersFnParams): Promise; diff --git a/dist/lib/watch/folders.js b/dist/lib/watch/folders.js new file mode 100644 index 0000000..498c071 --- /dev/null +++ b/dist/lib/watch/folders.js @@ -0,0 +1,154 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.default = watchFolders; +const fs_1 = __importDefault(require("fs")); +const path_1 = __importDefault(require("path")); +const child_process_1 = require("child_process"); +const delay_1 = __importDefault(require("../../utils/delay")); +let timeout; +const UPDATE_TIMEOUT = 2000; +function watchFolders(_a) { + return __awaiter(this, arguments, void 0, function* ({ folders, options, }) { + try { + const dirs = folders; + console.log(`Now handling ${dirs.length} Directories`); + const INTERVAL = (options === null || options === void 0 ? void 0 : options.interval) ? options.interval : UPDATE_TIMEOUT; + for (let i = 0; i < dirs.length; i++) { + const dir = dirs[i]; + if (!dir) { + console.log(`Dir: ${dir} doesn't exist`); + continue; + } + const dirPath = typeof dir == "string" ? dir : dir.path; + if ((typeof dir == "string" && !fs_1.default.existsSync(dirPath)) || + (typeof dir == "object" && + dir.path && + !dir.host && + !fs_1.default.existsSync(dir.path))) { + console.log(`Dir ${dirPath} does not exist. Creating ...`); + try { + const existingDirPath = dirs.find((dr) => { + if (typeof dr == "string") + return fs_1.default.existsSync(dr); + if (!dr.host) + return fs_1.default.existsSync(dr.path); // TODO handle remote + return false; + }); + console.log(`Existing Dir to clone: ${existingDirPath}`); + if (!existingDirPath) { + throw new Error("No existing Directories for reference"); + } + fs_1.default.mkdirSync(dirPath, { + recursive: true, + }); + if (typeof existingDirPath == "string") { + sync({ + dirPath: existingDirPath, + dirs, + options, + init: true, + }); + } + else { + sync({ + dirPath: existingDirPath.path, + dirs, + options, + init: true, + }); + } + } + catch (error) { + console.log("Error:", error.message); + throw new Error(`Folder Doesn't exist and couldn't be created. Please check if Directory exists.\nERROR => ${error.message}`); + } + } + if (typeof dir == "string") { + sync({ dirPath, dirs, options }); + yield (0, delay_1.default)(); + fs_1.default.watch(dirPath, { recursive: true }, (evt, fileName) => { + clearTimeout(timeout); + timeout = setTimeout(() => { + sync({ dirPath, dirs, options }); + process.exit(1); + }, INTERVAL); + }); + } + } + } + catch (error) { + console.log("ERROR:", error.message); + process.exit(0); + } + }); +} +function sync({ options, dirs, dirPath, init }) { + var _a; + const dstDirs = dirs.filter((dr) => { + if (typeof dr == "string") + return dr !== dirPath; + if (dr === null || dr === void 0 ? void 0 : dr.path) + return dr.path !== dirPath; + return false; + }); + for (let j = 0; j < dstDirs.length; j++) { + let cmdArray = ["rsync", "-avh"]; + if (options === null || options === void 0 ? void 0 : options.delete) { + cmdArray.push("--delete"); + } + if ((_a = options === null || options === void 0 ? void 0 : options.exclude) === null || _a === void 0 ? void 0 : _a[0]) { + options.exclude.forEach((excl) => { + cmdArray.push(`--exclude '${excl}'`); + }); + } + const dstDr = dstDirs[j]; + if (typeof dstDr == "string") { + if (!fs_1.default.existsSync(dstDr)) + continue; + if (dirPath === dstDr) { + console.log(`You can't sync the same paths. Please check your configuration and resolve duplicate paths`); + process.exit(6); + } + cmdArray.push(path_1.default.normalize(dirPath) + "/", path_1.default.normalize(dstDr) + "/"); + const cmd = cmdArray.join(" "); + (0, child_process_1.execSync)(cmd, { + stdio: "inherit", + }); + } + else if (dstDr.path) { + if (!dstDr.host && !fs_1.default.existsSync(dstDr.path)) + continue; + if (dirPath === dstDr.path) { + console.log(`You can't sync the same paths. Please check your configuration and resolve duplicate paths`); + process.exit(6); + } + if (dstDr.host && dstDr.ssh_key && dstDr.user) { + cmdArray.push("-e", `'ssh -i ${dstDr.ssh_key}'`); + cmdArray.push(path_1.default.normalize(dirPath) + "/", `${dstDr.user}@${dstDr.host}:${dstDr.path}/`); + const cmd = cmdArray.join(" "); + (0, child_process_1.execSync)(cmd, { + stdio: "inherit", + }); + } + else { + cmdArray.push(path_1.default.normalize(dirPath), path_1.default.normalize(dstDr.path)); + const cmd = cmdArray.join(" "); + (0, child_process_1.execSync)(cmd, { + stdio: "inherit", + }); + } + } + } +} diff --git a/dist/types/index.d.ts b/dist/types/index.d.ts new file mode 100644 index 0000000..8b82408 --- /dev/null +++ b/dist/types/index.d.ts @@ -0,0 +1,41 @@ +export type TurboSyncConfigArray = TurboSyncConfigObject[]; +export interface TurboSyncConfigObject { + title?: string; + files?: string[] | TurboSyncFileObject[]; + folders?: string[] | TurboSyncFileObject[]; + options?: TurboSyncOptions; +} +export interface TurboSyncFileObject { + path: string; + host?: string; + user?: string; + ssh_key?: string; + interval?: number; +} +export interface TurboSyncOptions { + delete?: boolean; + exclude?: string[]; + interval?: number; +} +export interface SyncFilesFnParams { + files: string[] | TurboSyncFileObject[]; + options: TurboSyncOptions | undefined; +} +export interface SyncFilesSyncFnParams { + files: string[] | TurboSyncFileObject[]; + options: TurboSyncOptions | undefined; + filePath: string; +} +export interface SyncFoldersFnParams { + folders: string[] | TurboSyncFileObject[]; + options: TurboSyncOptions | undefined; +} +export interface SyncFoldersSyncFnParams { + dirs: string[] | TurboSyncFileObject[]; + options: TurboSyncOptions | undefined; + dirPath: string; + init?: boolean; +} +export interface HandleEnvVarsFnParams { + json: string; +} diff --git a/dist/types/index.js b/dist/types/index.js new file mode 100644 index 0000000..c8ad2e5 --- /dev/null +++ b/dist/types/index.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/dist/utils/console-colors.d.ts b/dist/utils/console-colors.d.ts new file mode 100644 index 0000000..ce5bdf8 --- /dev/null +++ b/dist/utils/console-colors.d.ts @@ -0,0 +1,3 @@ +declare const colorsArr: readonly ["red", "bright", "dim", "underscore", "blink", "reverse", "hidden", "black", "green", "yellow", "blue", "magenta", "cyan", "white", "gray"]; +export default function colors(text: string, type: (typeof colorsArr)[number], bg: boolean): string; +export {}; diff --git a/dist/utils/console-colors.js b/dist/utils/console-colors.js new file mode 100644 index 0000000..8de27f6 --- /dev/null +++ b/dist/utils/console-colors.js @@ -0,0 +1,67 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.default = colors; +const colorsArr = [ + "red", + "bright", + "dim", + "underscore", + "blink", + "reverse", + "hidden", + "black", + "green", + "yellow", + "blue", + "magenta", + "cyan", + "white", + "gray", +]; +const colorCodes = { + Reset: "\x1b[0m", + Bright: "\x1b[1m", + Dim: "\x1b[2m", + Underscore: "\x1b[4m", + Blink: "\x1b[5m", + Reverse: "\x1b[7m", + Hidden: "\x1b[8m", + FgBlack: "\x1b[30m", + FgRed: "\x1b[31m", + FgGreen: "\x1b[32m", + FgYellow: "\x1b[33m", + FgBlue: "\x1b[34m", + FgMagenta: "\x1b[35m", + FgCyan: "\x1b[36m", + FgWhite: "\x1b[37m", + FgGray: "\x1b[90m", + BgBlack: "\x1b[40m", + BgRed: "\x1b[41m", + BgGreen: "\x1b[42m", + BgYellow: "\x1b[43m", + BgBlue: "\x1b[44m", + BgMagenta: "\x1b[45m", + BgCyan: "\x1b[46m", + BgWhite: "\x1b[47m", + BgGray: "\x1b[100m", +}; +function colors(text, type, bg) { + let finalText = ``; + switch (type) { + case "red": + finalText += bg ? colorCodes.BgRed : colorCodes.FgRed; + break; + case "green": + finalText += bg ? colorCodes.BgGreen : colorCodes.FgGreen; + break; + case "blue": + finalText += bg ? colorCodes.BgBlue : colorCodes.FgBlue; + break; + default: + finalText += colorCodes.Bright; + break; + } + finalText += `${text}${colorCodes.Reset}`; + console.log("finalText", finalText); + return finalText; +} diff --git a/dist/utils/delay.d.ts b/dist/utils/delay.d.ts new file mode 100644 index 0000000..683e6e2 --- /dev/null +++ b/dist/utils/delay.d.ts @@ -0,0 +1 @@ +export default function delay(time?: number): Promise; diff --git a/dist/utils/delay.js b/dist/utils/delay.js new file mode 100644 index 0000000..603e107 --- /dev/null +++ b/dist/utils/delay.js @@ -0,0 +1,21 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.default = delay; +function delay() { + return __awaiter(this, arguments, void 0, function* (time = 500) { + return new Promise((resolve) => { + setTimeout(() => { + resolve(true); + }, time); + }); + }); +} diff --git a/dist/utils/env.d.ts b/dist/utils/env.d.ts new file mode 100644 index 0000000..94390ec --- /dev/null +++ b/dist/utils/env.d.ts @@ -0,0 +1,2 @@ +import { HandleEnvVarsFnParams } from "../types"; +export default function handleEnvVars({ json }: HandleEnvVarsFnParams): string; diff --git a/dist/utils/env.js b/dist/utils/env.js new file mode 100644 index 0000000..8437cb5 --- /dev/null +++ b/dist/utils/env.js @@ -0,0 +1,42 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.default = handleEnvVars; +const fs_1 = __importDefault(require("fs")); +const path_1 = __importDefault(require("path")); +function handleEnvVars({ json }) { + let newJson = json; + try { + let envVars = Object.assign({}, process.env); + const localEnvFilePath = path_1.default.resolve(process.cwd(), "./.env"); + if (fs_1.default.existsSync(localEnvFilePath)) { + const localEnvText = fs_1.default.readFileSync(localEnvFilePath, "utf8"); + const localEnvKeyPairArray = localEnvText + .split("\n") + .filter((keyPair) => keyPair && + keyPair.match(/.{3,}/) && + !keyPair.match(/^\#/)) + .map((keyPair) => keyPair.trim()); + localEnvKeyPairArray.forEach((keyPair) => { + let keyPairArray = keyPair.split("="); + const key = keyPairArray.shift(); + const value = keyPairArray.join("="); + if (!key) + return; + const newEnvObject = {}; + newEnvObject[key] = value; + envVars = Object.assign(Object.assign({}, envVars), newEnvObject); + }); + } + for (let key in envVars) { + newJson = newJson.replaceAll(`$${key}`, String(envVars[key])); + } + } + catch (error) { + console.log(`Error replacing Environment variables`, error.message); + return json; + } + return newJson; +} diff --git a/index.ts b/index.ts index 7456005..793a99f 100644 --- a/index.ts +++ b/index.ts @@ -1,5 +1,4 @@ #! /usr/bin/env node -// @ts-check import fs from "fs"; import path from "path"; diff --git a/lib/sync.ts b/lib/sync.ts index af7dd58..4d8912e 100644 --- a/lib/sync.ts +++ b/lib/sync.ts @@ -1,10 +1,6 @@ -#! /usr/bin/env node - -// @ts-check - -const { spawn } = require("child_process"); -const watchFiles = require("./watch/files"); -const watchFolders = require("./watch/folders"); +import { spawn } from "child_process"; +import watchFiles from "./watch/files"; +import watchFolders from "./watch/folders"; const confFileProvidedJSON = process.argv[process.argv.length - 1]; diff --git a/lib/watch/files.ts b/lib/watch/files.ts index 87cac7d..f9fe9dc 100644 --- a/lib/watch/files.ts +++ b/lib/watch/files.ts @@ -1,5 +1,3 @@ -// @ts-check - import { execSync } from "child_process"; import fs from "fs"; import delay from "../../utils/delay"; diff --git a/lib/watch/folders.ts b/lib/watch/folders.ts index ade0905..84e9094 100644 --- a/lib/watch/folders.ts +++ b/lib/watch/folders.ts @@ -1,5 +1,3 @@ -// @ts-check - import fs from "fs"; import path from "path"; import { execSync } from "child_process"; diff --git a/package.json b/package.json index c2aac7a..86c3655 100644 --- a/package.json +++ b/package.json @@ -1,15 +1,15 @@ { "name": "@moduletrace/turbosync", "version": "1.0.0", - "module": "index.js", + "module": "dist/index.js", "scripts": { - "start": "node index.ts", + "start": "node dist/index.js", "build": "tsc", - "compile": "bun build index.js --compile --outfile bin/turbosync", + "compile": "bun build index.ts --compile --outfile bin/turbosync", "dev": "node index.js --watch" }, "bin": { - "turbosync": "./index.js" + "turbosync": "./dist/index.js" }, "description": "Sync files and directories with ease", "main": "index.js", diff --git a/publish.sh b/publish.sh old mode 100644 new mode 100755 index 365d8f1..30ebeea --- a/publish.sh +++ b/publish.sh @@ -1,5 +1,7 @@ #!/bin/bash +tsc + if [ -z "$1" ]; then msg="Updates" else @@ -9,4 +11,4 @@ fi git add . git commit -m "$msg" git push -npm publish +bun publish diff --git a/push.sh b/push.sh new file mode 100755 index 0000000..f8a4555 --- /dev/null +++ b/push.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +if [ -z "$1" ]; then + msg="Updates" +else + msg="$1" +fi + +git add . +git commit -m "$msg" +git push diff --git a/tsconfig.json b/tsconfig.json index c9d846c..c4baee1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -16,6 +16,6 @@ "declaration": true, "outDir": "dist" }, - "include": ["**/**.ts"], - "exclude": ["node_modules"] + "include": ["**/*.ts"], + "exclude": ["node_modules", "dist"] } diff --git a/types/index.ts b/types/index.ts index d9a56be..153d002 100644 --- a/types/index.ts +++ b/types/index.ts @@ -1,5 +1,3 @@ -// @ts-check - export type TurboSyncConfigArray = TurboSyncConfigObject[]; export interface TurboSyncConfigObject {