@hot-updater/cli-tools 0.21.8

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.
Files changed (71) hide show
  1. package/LICENSE +21 -0
  2. package/dist/ConfigBuilder.cjs +122 -0
  3. package/dist/ConfigBuilder.d.cts +43 -0
  4. package/dist/ConfigBuilder.d.ts +43 -0
  5. package/dist/ConfigBuilder.js +121 -0
  6. package/dist/_virtual/rolldown_runtime.cjs +25 -0
  7. package/dist/banner.cjs +29 -0
  8. package/dist/banner.d.cts +6 -0
  9. package/dist/banner.d.ts +6 -0
  10. package/dist/banner.js +24 -0
  11. package/dist/colors.d.cts +2 -0
  12. package/dist/colors.d.ts +2 -0
  13. package/dist/colors.js +3 -0
  14. package/dist/copyDirToTmp.cjs +28 -0
  15. package/dist/copyDirToTmp.d.cts +7 -0
  16. package/dist/copyDirToTmp.d.ts +7 -0
  17. package/dist/copyDirToTmp.js +25 -0
  18. package/dist/createTarBr.cjs +94 -0
  19. package/dist/createTarBr.d.cts +22 -0
  20. package/dist/createTarBr.d.ts +22 -0
  21. package/dist/createTarBr.js +88 -0
  22. package/dist/createTarGz.cjs +78 -0
  23. package/dist/createTarGz.d.cts +22 -0
  24. package/dist/createTarGz.d.ts +22 -0
  25. package/dist/createTarGz.js +73 -0
  26. package/dist/createZip.cjs +80 -0
  27. package/dist/createZip.d.cts +22 -0
  28. package/dist/createZip.d.ts +22 -0
  29. package/dist/createZip.js +75 -0
  30. package/dist/crypto.cjs +27 -0
  31. package/dist/crypto.d.cts +5 -0
  32. package/dist/crypto.d.ts +5 -0
  33. package/dist/crypto.js +24 -0
  34. package/dist/cwd.cjs +9 -0
  35. package/dist/cwd.d.cts +4 -0
  36. package/dist/cwd.d.ts +4 -0
  37. package/dist/cwd.js +7 -0
  38. package/dist/getAndroidSdkPath.cjs +10 -0
  39. package/dist/getAndroidSdkPath.d.cts +4 -0
  40. package/dist/getAndroidSdkPath.d.ts +4 -0
  41. package/dist/getAndroidSdkPath.js +9 -0
  42. package/dist/index.cjs +48 -0
  43. package/dist/index.d.cts +17 -0
  44. package/dist/index.d.ts +17 -0
  45. package/dist/index.js +18 -0
  46. package/dist/isObject.cjs +8 -0
  47. package/dist/isObject.js +7 -0
  48. package/dist/loadConfig.cjs +100 -0
  49. package/dist/loadConfig.d.cts +12 -0
  50. package/dist/loadConfig.d.ts +12 -0
  51. package/dist/loadConfig.js +93 -0
  52. package/dist/log.cjs +16 -0
  53. package/dist/log.d.cts +11 -0
  54. package/dist/log.d.ts +11 -0
  55. package/dist/log.js +14 -0
  56. package/dist/makeEnv.cjs +57 -0
  57. package/dist/makeEnv.d.cts +8 -0
  58. package/dist/makeEnv.d.ts +8 -0
  59. package/dist/makeEnv.js +55 -0
  60. package/dist/prompts.d.cts +2 -0
  61. package/dist/prompts.d.ts +2 -0
  62. package/dist/prompts.js +3 -0
  63. package/dist/transformEnv.cjs +14 -0
  64. package/dist/transformEnv.d.cts +4 -0
  65. package/dist/transformEnv.d.ts +4 -0
  66. package/dist/transformEnv.js +11 -0
  67. package/dist/transformTemplate.cjs +22 -0
  68. package/dist/transformTemplate.d.cts +15 -0
  69. package/dist/transformTemplate.d.ts +15 -0
  70. package/dist/transformTemplate.js +21 -0
  71. package/package.json +64 -0
@@ -0,0 +1,17 @@
1
+ import { banner, link, printBanner } from "./banner.cjs";
2
+ import { BuildType, ConfigBuilder, IConfigBuilder, ImportInfo, ProviderConfig } from "./ConfigBuilder.cjs";
3
+ import { colors } from "./colors.cjs";
4
+ import { copyDirToTmp } from "./copyDirToTmp.cjs";
5
+ import { createTarBr, createTarBrTargetFiles } from "./createTarBr.cjs";
6
+ import { createTarGz, createTarGzTargetFiles } from "./createTarGz.cjs";
7
+ import { createZip, createZipTargetFiles } from "./createZip.cjs";
8
+ import { decryptJson, encryptJson } from "./crypto.cjs";
9
+ import { getCwd } from "./cwd.cjs";
10
+ import { getAndroidSdkPath } from "./getAndroidSdkPath.cjs";
11
+ import { ConfigResponse, HotUpdaterConfigOptions, loadConfig, loadConfigSync } from "./loadConfig.cjs";
12
+ import { log } from "./log.cjs";
13
+ import { makeEnv } from "./makeEnv.cjs";
14
+ import { p } from "./prompts.cjs";
15
+ import { transformEnv } from "./transformEnv.cjs";
16
+ import { transformTemplate } from "./transformTemplate.cjs";
17
+ export { BuildType, ConfigBuilder, ConfigResponse, HotUpdaterConfigOptions, IConfigBuilder, ImportInfo, ProviderConfig, banner, colors, copyDirToTmp, createTarBr, createTarBrTargetFiles, createTarGz, createTarGzTargetFiles, createZip, createZipTargetFiles, decryptJson, encryptJson, getAndroidSdkPath, getCwd, link, loadConfig, loadConfigSync, log, makeEnv, p, printBanner, transformEnv, transformTemplate };
@@ -0,0 +1,17 @@
1
+ import { banner, link, printBanner } from "./banner.js";
2
+ import { BuildType, ConfigBuilder, IConfigBuilder, ImportInfo, ProviderConfig } from "./ConfigBuilder.js";
3
+ import { colors } from "./colors.js";
4
+ import { copyDirToTmp } from "./copyDirToTmp.js";
5
+ import { createTarBr, createTarBrTargetFiles } from "./createTarBr.js";
6
+ import { createTarGz, createTarGzTargetFiles } from "./createTarGz.js";
7
+ import { createZip, createZipTargetFiles } from "./createZip.js";
8
+ import { decryptJson, encryptJson } from "./crypto.js";
9
+ import { getCwd } from "./cwd.js";
10
+ import { getAndroidSdkPath } from "./getAndroidSdkPath.js";
11
+ import { ConfigResponse, HotUpdaterConfigOptions, loadConfig, loadConfigSync } from "./loadConfig.js";
12
+ import { log } from "./log.js";
13
+ import { makeEnv } from "./makeEnv.js";
14
+ import { p } from "./prompts.js";
15
+ import { transformEnv } from "./transformEnv.js";
16
+ import { transformTemplate } from "./transformTemplate.js";
17
+ export { BuildType, ConfigBuilder, ConfigResponse, HotUpdaterConfigOptions, IConfigBuilder, ImportInfo, ProviderConfig, banner, colors, copyDirToTmp, createTarBr, createTarBrTargetFiles, createTarGz, createTarGzTargetFiles, createZip, createZipTargetFiles, decryptJson, encryptJson, getAndroidSdkPath, getCwd, link, loadConfig, loadConfigSync, log, makeEnv, p, printBanner, transformEnv, transformTemplate };
package/dist/index.js ADDED
@@ -0,0 +1,18 @@
1
+ import { banner, link, printBanner } from "./banner.js";
2
+ import { ConfigBuilder } from "./ConfigBuilder.js";
3
+ import { colors } from "./colors.js";
4
+ import { getCwd } from "./cwd.js";
5
+ import { copyDirToTmp } from "./copyDirToTmp.js";
6
+ import { createTarBr, createTarBrTargetFiles } from "./createTarBr.js";
7
+ import { createTarGz, createTarGzTargetFiles } from "./createTarGz.js";
8
+ import { createZip, createZipTargetFiles } from "./createZip.js";
9
+ import { decryptJson, encryptJson } from "./crypto.js";
10
+ import { getAndroidSdkPath } from "./getAndroidSdkPath.js";
11
+ import { loadConfig, loadConfigSync } from "./loadConfig.js";
12
+ import { log } from "./log.js";
13
+ import { makeEnv } from "./makeEnv.js";
14
+ import { p } from "./prompts.js";
15
+ import { transformEnv } from "./transformEnv.js";
16
+ import { transformTemplate } from "./transformTemplate.js";
17
+
18
+ export { ConfigBuilder, banner, colors, copyDirToTmp, createTarBr, createTarBrTargetFiles, createTarGz, createTarGzTargetFiles, createZip, createZipTargetFiles, decryptJson, encryptJson, getAndroidSdkPath, getCwd, link, loadConfig, loadConfigSync, log, makeEnv, p, printBanner, transformEnv, transformTemplate };
@@ -0,0 +1,8 @@
1
+
2
+ //#region src/isObject.ts
3
+ const isObject = (value) => {
4
+ return !!value && value.constructor === Object;
5
+ };
6
+
7
+ //#endregion
8
+ exports.isObject = isObject;
@@ -0,0 +1,7 @@
1
+ //#region src/isObject.ts
2
+ const isObject = (value) => {
3
+ return !!value && value.constructor === Object;
4
+ };
5
+
6
+ //#endregion
7
+ export { isObject };
@@ -0,0 +1,100 @@
1
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
+ const require_cwd = require('./cwd.cjs');
3
+ let path = require("path");
4
+ path = require_rolldown_runtime.__toESM(path);
5
+ let cosmiconfig = require("cosmiconfig");
6
+ cosmiconfig = require_rolldown_runtime.__toESM(cosmiconfig);
7
+ let cosmiconfig_typescript_loader = require("cosmiconfig-typescript-loader");
8
+ cosmiconfig_typescript_loader = require_rolldown_runtime.__toESM(cosmiconfig_typescript_loader);
9
+ let es_toolkit = require("es-toolkit");
10
+ es_toolkit = require_rolldown_runtime.__toESM(es_toolkit);
11
+ let fast_glob = require("fast-glob");
12
+ fast_glob = require_rolldown_runtime.__toESM(fast_glob);
13
+
14
+ //#region src/loadConfig.ts
15
+ const getDefaultPlatformConfig = () => {
16
+ let infoPlistPaths = [];
17
+ try {
18
+ const plistFiles = fast_glob.default.sync("**/Info.plist", {
19
+ cwd: path.default.join(require_cwd.getCwd(), "ios"),
20
+ absolute: false,
21
+ onlyFiles: true,
22
+ ignore: [
23
+ "**/Pods/**",
24
+ "**/build/**",
25
+ "**/Build/**",
26
+ "**/*.app/**",
27
+ "**/*.xcarchive/**"
28
+ ]
29
+ });
30
+ if (plistFiles.length > 0) infoPlistPaths = plistFiles.map((file) => `ios/${file}`);
31
+ } catch {}
32
+ let stringResourcePaths = [];
33
+ try {
34
+ const stringsFiles = fast_glob.default.sync(path.default.join("**", "strings.xml"), {
35
+ cwd: path.default.join(require_cwd.getCwd(), "android"),
36
+ absolute: false,
37
+ onlyFiles: true
38
+ });
39
+ if (stringsFiles.length > 0) stringResourcePaths = stringsFiles.map((file) => path.default.join("android", file));
40
+ } catch {}
41
+ return {
42
+ android: { stringResourcePaths },
43
+ ios: { infoPlistPaths }
44
+ };
45
+ };
46
+ const getDefaultConfig = () => {
47
+ return {
48
+ releaseChannel: "production",
49
+ updateStrategy: "appVersion",
50
+ compressStrategy: "zip",
51
+ fingerprint: { extraSources: [] },
52
+ console: { port: 1422 },
53
+ platform: getDefaultPlatformConfig(),
54
+ nativeBuild: { android: {
55
+ aab: true,
56
+ variant: "Release",
57
+ appModuleName: "app"
58
+ } },
59
+ build: () => {
60
+ throw new Error("build plugin is required");
61
+ },
62
+ storage: () => {
63
+ throw new Error("storage plugin is required");
64
+ },
65
+ database: () => {
66
+ throw new Error("database plugin is required");
67
+ }
68
+ };
69
+ };
70
+ const configOptions = {
71
+ stopDir: require_cwd.getCwd(),
72
+ searchPlaces: [
73
+ "hot-updater.config.js",
74
+ "hot-updater.config.cjs",
75
+ "hot-updater.config.ts",
76
+ "hot-updater.config.cts",
77
+ "hot-updater.config.cjs",
78
+ "hot-updater.config.mts"
79
+ ],
80
+ ignoreEmptySearchPlaces: false,
81
+ loaders: {
82
+ ".ts": (0, cosmiconfig_typescript_loader.TypeScriptLoader)(),
83
+ ".mts": (0, cosmiconfig_typescript_loader.TypeScriptLoader)(),
84
+ ".cts": (0, cosmiconfig_typescript_loader.TypeScriptLoader)()
85
+ }
86
+ };
87
+ const ensureConfig = (result, options) => {
88
+ const config = typeof result?.config === "function" ? result.config(options) : result?.config;
89
+ return (0, es_toolkit.merge)(getDefaultConfig(), config ?? {});
90
+ };
91
+ const loadConfig = async (options) => {
92
+ return ensureConfig(await (0, cosmiconfig.cosmiconfig)("hot-updater", configOptions).search(), options);
93
+ };
94
+ const loadConfigSync = (options) => {
95
+ return ensureConfig((0, cosmiconfig.cosmiconfigSync)("hot-updater", configOptions).search(), options);
96
+ };
97
+
98
+ //#endregion
99
+ exports.loadConfig = loadConfig;
100
+ exports.loadConfigSync = loadConfigSync;
@@ -0,0 +1,12 @@
1
+ import { ConfigInput, Platform, RequiredDeep } from "@hot-updater/plugin-core";
2
+
3
+ //#region src/loadConfig.d.ts
4
+ type HotUpdaterConfigOptions = {
5
+ platform: Platform;
6
+ channel: string;
7
+ } | null;
8
+ type ConfigResponse = RequiredDeep<ConfigInput>;
9
+ declare const loadConfig: (options: HotUpdaterConfigOptions) => Promise<ConfigResponse>;
10
+ declare const loadConfigSync: (options: HotUpdaterConfigOptions) => ConfigResponse;
11
+ //#endregion
12
+ export { ConfigResponse, HotUpdaterConfigOptions, loadConfig, loadConfigSync };
@@ -0,0 +1,12 @@
1
+ import { ConfigInput, Platform, RequiredDeep } from "@hot-updater/plugin-core";
2
+
3
+ //#region src/loadConfig.d.ts
4
+ type HotUpdaterConfigOptions = {
5
+ platform: Platform;
6
+ channel: string;
7
+ } | null;
8
+ type ConfigResponse = RequiredDeep<ConfigInput>;
9
+ declare const loadConfig: (options: HotUpdaterConfigOptions) => Promise<ConfigResponse>;
10
+ declare const loadConfigSync: (options: HotUpdaterConfigOptions) => ConfigResponse;
11
+ //#endregion
12
+ export { ConfigResponse, HotUpdaterConfigOptions, loadConfig, loadConfigSync };
@@ -0,0 +1,93 @@
1
+ import { getCwd } from "./cwd.js";
2
+ import path from "path";
3
+ import { cosmiconfig, cosmiconfigSync } from "cosmiconfig";
4
+ import { TypeScriptLoader } from "cosmiconfig-typescript-loader";
5
+ import { merge } from "es-toolkit";
6
+ import fg from "fast-glob";
7
+
8
+ //#region src/loadConfig.ts
9
+ const getDefaultPlatformConfig = () => {
10
+ let infoPlistPaths = [];
11
+ try {
12
+ const plistFiles = fg.sync("**/Info.plist", {
13
+ cwd: path.join(getCwd(), "ios"),
14
+ absolute: false,
15
+ onlyFiles: true,
16
+ ignore: [
17
+ "**/Pods/**",
18
+ "**/build/**",
19
+ "**/Build/**",
20
+ "**/*.app/**",
21
+ "**/*.xcarchive/**"
22
+ ]
23
+ });
24
+ if (plistFiles.length > 0) infoPlistPaths = plistFiles.map((file) => `ios/${file}`);
25
+ } catch {}
26
+ let stringResourcePaths = [];
27
+ try {
28
+ const stringsFiles = fg.sync(path.join("**", "strings.xml"), {
29
+ cwd: path.join(getCwd(), "android"),
30
+ absolute: false,
31
+ onlyFiles: true
32
+ });
33
+ if (stringsFiles.length > 0) stringResourcePaths = stringsFiles.map((file) => path.join("android", file));
34
+ } catch {}
35
+ return {
36
+ android: { stringResourcePaths },
37
+ ios: { infoPlistPaths }
38
+ };
39
+ };
40
+ const getDefaultConfig = () => {
41
+ return {
42
+ releaseChannel: "production",
43
+ updateStrategy: "appVersion",
44
+ compressStrategy: "zip",
45
+ fingerprint: { extraSources: [] },
46
+ console: { port: 1422 },
47
+ platform: getDefaultPlatformConfig(),
48
+ nativeBuild: { android: {
49
+ aab: true,
50
+ variant: "Release",
51
+ appModuleName: "app"
52
+ } },
53
+ build: () => {
54
+ throw new Error("build plugin is required");
55
+ },
56
+ storage: () => {
57
+ throw new Error("storage plugin is required");
58
+ },
59
+ database: () => {
60
+ throw new Error("database plugin is required");
61
+ }
62
+ };
63
+ };
64
+ const configOptions = {
65
+ stopDir: getCwd(),
66
+ searchPlaces: [
67
+ "hot-updater.config.js",
68
+ "hot-updater.config.cjs",
69
+ "hot-updater.config.ts",
70
+ "hot-updater.config.cts",
71
+ "hot-updater.config.cjs",
72
+ "hot-updater.config.mts"
73
+ ],
74
+ ignoreEmptySearchPlaces: false,
75
+ loaders: {
76
+ ".ts": TypeScriptLoader(),
77
+ ".mts": TypeScriptLoader(),
78
+ ".cts": TypeScriptLoader()
79
+ }
80
+ };
81
+ const ensureConfig = (result, options) => {
82
+ const config = typeof result?.config === "function" ? result.config(options) : result?.config;
83
+ return merge(getDefaultConfig(), config ?? {});
84
+ };
85
+ const loadConfig = async (options) => {
86
+ return ensureConfig(await cosmiconfig("hot-updater", configOptions).search(), options);
87
+ };
88
+ const loadConfigSync = (options) => {
89
+ return ensureConfig(cosmiconfigSync("hot-updater", configOptions).search(), options);
90
+ };
91
+
92
+ //#endregion
93
+ export { loadConfig, loadConfigSync };
package/dist/log.cjs ADDED
@@ -0,0 +1,16 @@
1
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
+ let picocolors = require("picocolors");
3
+ picocolors = require_rolldown_runtime.__toESM(picocolors);
4
+
5
+ //#region src/log.ts
6
+ const log = {
7
+ normal: (message) => console.log(message),
8
+ success: (message) => console.log(picocolors.default.green(message)),
9
+ info: (message) => console.log(picocolors.default.blue(message)),
10
+ error: (message) => console.log(picocolors.default.red(message)),
11
+ warn: (message) => console.log(picocolors.default.yellow(message)),
12
+ debug: (message) => console.log(picocolors.default.gray(message))
13
+ };
14
+
15
+ //#endregion
16
+ exports.log = log;
package/dist/log.d.cts ADDED
@@ -0,0 +1,11 @@
1
+ //#region src/log.d.ts
2
+ declare const log: {
3
+ normal: (message: string | number | null | undefined) => void;
4
+ success: (message: string | number | null | undefined) => void;
5
+ info: (message: string | number | null | undefined) => void;
6
+ error: (message: string | number | null | undefined) => void;
7
+ warn: (message: string | number | null | undefined) => void;
8
+ debug: (message: string | number | null | undefined) => void;
9
+ };
10
+ //#endregion
11
+ export { log };
package/dist/log.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ //#region src/log.d.ts
2
+ declare const log: {
3
+ normal: (message: string | number | null | undefined) => void;
4
+ success: (message: string | number | null | undefined) => void;
5
+ info: (message: string | number | null | undefined) => void;
6
+ error: (message: string | number | null | undefined) => void;
7
+ warn: (message: string | number | null | undefined) => void;
8
+ debug: (message: string | number | null | undefined) => void;
9
+ };
10
+ //#endregion
11
+ export { log };
package/dist/log.js ADDED
@@ -0,0 +1,14 @@
1
+ import picocolors from "picocolors";
2
+
3
+ //#region src/log.ts
4
+ const log = {
5
+ normal: (message) => console.log(message),
6
+ success: (message) => console.log(picocolors.green(message)),
7
+ info: (message) => console.log(picocolors.blue(message)),
8
+ error: (message) => console.log(picocolors.red(message)),
9
+ warn: (message) => console.log(picocolors.yellow(message)),
10
+ debug: (message) => console.log(picocolors.gray(message))
11
+ };
12
+
13
+ //#endregion
14
+ export { log };
@@ -0,0 +1,57 @@
1
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
+ let fs_promises = require("fs/promises");
3
+ fs_promises = require_rolldown_runtime.__toESM(fs_promises);
4
+
5
+ //#region src/makeEnv.ts
6
+ const makeEnv = async (newEnvVars, filePath = ".env.hotupdater") => {
7
+ try {
8
+ const existingContent = await fs_promises.default.readFile(filePath, "utf-8").catch(() => "");
9
+ const lines = existingContent ? existingContent.split("\n") : [];
10
+ const processedKeys = /* @__PURE__ */ new Set();
11
+ const updatedLines = [];
12
+ for (let i = 0; i < lines.length; i++) {
13
+ const line = lines[i] ?? "";
14
+ const trimmedLine = line.trim();
15
+ if (trimmedLine === "") {
16
+ updatedLines.push(line);
17
+ continue;
18
+ }
19
+ if (trimmedLine.startsWith("#")) {
20
+ if (i + 1 < lines.length) {
21
+ const nextLine = (lines[i + 1] ?? "").trim();
22
+ if (nextLine && !nextLine.startsWith("#") && nextLine.includes("=")) {
23
+ const [possibleKey = ""] = nextLine.split("=");
24
+ if (Object.hasOwn(newEnvVars, possibleKey.trim())) continue;
25
+ }
26
+ }
27
+ updatedLines.push(line);
28
+ continue;
29
+ }
30
+ if (trimmedLine.includes("=")) {
31
+ const [keyPart] = line.split("=");
32
+ const key = keyPart?.trim() ?? "";
33
+ if (Object.hasOwn(newEnvVars, key)) {
34
+ processedKeys.add(key);
35
+ const newValue = newEnvVars[key];
36
+ if (typeof newValue === "object" && newValue !== null) {
37
+ updatedLines.push(`# ${newValue.comment}`);
38
+ updatedLines.push(`${key}=${newValue.value}`);
39
+ } else updatedLines.push(`${key}=${newValue}`);
40
+ } else updatedLines.push(line);
41
+ } else updatedLines.push(line);
42
+ }
43
+ for (const [key, val] of Object.entries(newEnvVars)) if (!processedKeys.has(key)) if (typeof val === "object" && val !== null) {
44
+ updatedLines.push(`# ${val.comment}`);
45
+ updatedLines.push(`${key}=${val.value}`);
46
+ } else updatedLines.push(`${key}=${val}`);
47
+ const updatedContent = updatedLines.join("\n");
48
+ await fs_promises.default.writeFile(filePath, updatedContent, "utf-8");
49
+ return updatedContent;
50
+ } catch (error) {
51
+ console.error("Error while updating .env.hotupdater file:", error);
52
+ throw error;
53
+ }
54
+ };
55
+
56
+ //#endregion
57
+ exports.makeEnv = makeEnv;
@@ -0,0 +1,8 @@
1
+ //#region src/makeEnv.d.ts
2
+ type EnvVarValue = string | {
3
+ comment: string;
4
+ value: string;
5
+ };
6
+ declare const makeEnv: (newEnvVars: Record<string, EnvVarValue>, filePath?: string) => Promise<string>;
7
+ //#endregion
8
+ export { makeEnv };
@@ -0,0 +1,8 @@
1
+ //#region src/makeEnv.d.ts
2
+ type EnvVarValue = string | {
3
+ comment: string;
4
+ value: string;
5
+ };
6
+ declare const makeEnv: (newEnvVars: Record<string, EnvVarValue>, filePath?: string) => Promise<string>;
7
+ //#endregion
8
+ export { makeEnv };
@@ -0,0 +1,55 @@
1
+ import fs from "fs/promises";
2
+
3
+ //#region src/makeEnv.ts
4
+ const makeEnv = async (newEnvVars, filePath = ".env.hotupdater") => {
5
+ try {
6
+ const existingContent = await fs.readFile(filePath, "utf-8").catch(() => "");
7
+ const lines = existingContent ? existingContent.split("\n") : [];
8
+ const processedKeys = /* @__PURE__ */ new Set();
9
+ const updatedLines = [];
10
+ for (let i = 0; i < lines.length; i++) {
11
+ const line = lines[i] ?? "";
12
+ const trimmedLine = line.trim();
13
+ if (trimmedLine === "") {
14
+ updatedLines.push(line);
15
+ continue;
16
+ }
17
+ if (trimmedLine.startsWith("#")) {
18
+ if (i + 1 < lines.length) {
19
+ const nextLine = (lines[i + 1] ?? "").trim();
20
+ if (nextLine && !nextLine.startsWith("#") && nextLine.includes("=")) {
21
+ const [possibleKey = ""] = nextLine.split("=");
22
+ if (Object.hasOwn(newEnvVars, possibleKey.trim())) continue;
23
+ }
24
+ }
25
+ updatedLines.push(line);
26
+ continue;
27
+ }
28
+ if (trimmedLine.includes("=")) {
29
+ const [keyPart] = line.split("=");
30
+ const key = keyPart?.trim() ?? "";
31
+ if (Object.hasOwn(newEnvVars, key)) {
32
+ processedKeys.add(key);
33
+ const newValue = newEnvVars[key];
34
+ if (typeof newValue === "object" && newValue !== null) {
35
+ updatedLines.push(`# ${newValue.comment}`);
36
+ updatedLines.push(`${key}=${newValue.value}`);
37
+ } else updatedLines.push(`${key}=${newValue}`);
38
+ } else updatedLines.push(line);
39
+ } else updatedLines.push(line);
40
+ }
41
+ for (const [key, val] of Object.entries(newEnvVars)) if (!processedKeys.has(key)) if (typeof val === "object" && val !== null) {
42
+ updatedLines.push(`# ${val.comment}`);
43
+ updatedLines.push(`${key}=${val.value}`);
44
+ } else updatedLines.push(`${key}=${val}`);
45
+ const updatedContent = updatedLines.join("\n");
46
+ await fs.writeFile(filePath, updatedContent, "utf-8");
47
+ return updatedContent;
48
+ } catch (error) {
49
+ console.error("Error while updating .env.hotupdater file:", error);
50
+ throw error;
51
+ }
52
+ };
53
+
54
+ //#endregion
55
+ export { makeEnv };
@@ -0,0 +1,2 @@
1
+ import * as p from "@clack/prompts";
2
+ export { p };
@@ -0,0 +1,2 @@
1
+ import * as p from "@clack/prompts";
2
+ export { p };
@@ -0,0 +1,3 @@
1
+ import * as p from "@clack/prompts";
2
+
3
+ export { p };
@@ -0,0 +1,14 @@
1
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
+ let fs = require("fs");
3
+ fs = require_rolldown_runtime.__toESM(fs);
4
+ let oxc_transform = require("oxc-transform");
5
+ oxc_transform = require_rolldown_runtime.__toESM(oxc_transform);
6
+
7
+ //#region src/transformEnv.ts
8
+ const transformEnv = (filename, env) => {
9
+ const code = fs.default.readFileSync(filename, "utf-8");
10
+ return (0, oxc_transform.transform)(filename, code, { define: Object.fromEntries(Object.entries(env).map(([key, value]) => [`HotUpdater.${key}`, JSON.stringify(value)])) })?.code || code;
11
+ };
12
+
13
+ //#endregion
14
+ exports.transformEnv = transformEnv;
@@ -0,0 +1,4 @@
1
+ //#region src/transformEnv.d.ts
2
+ declare const transformEnv: <T extends Record<string, string>>(filename: string, env: T) => string;
3
+ //#endregion
4
+ export { transformEnv };
@@ -0,0 +1,4 @@
1
+ //#region src/transformEnv.d.ts
2
+ declare const transformEnv: <T extends Record<string, string>>(filename: string, env: T) => string;
3
+ //#endregion
4
+ export { transformEnv };
@@ -0,0 +1,11 @@
1
+ import fs from "fs";
2
+ import { transform } from "oxc-transform";
3
+
4
+ //#region src/transformEnv.ts
5
+ const transformEnv = (filename, env) => {
6
+ const code = fs.readFileSync(filename, "utf-8");
7
+ return transform(filename, code, { define: Object.fromEntries(Object.entries(env).map(([key, value]) => [`HotUpdater.${key}`, JSON.stringify(value)])) })?.code || code;
8
+ };
9
+
10
+ //#endregion
11
+ export { transformEnv };
@@ -0,0 +1,22 @@
1
+
2
+ //#region src/transformTemplate.ts
3
+ /**
4
+ * Replaces placeholders in the format %%key%% in a template string with values from the values object.
5
+ * Uses generic type T to automatically infer placeholder keys from the template string to ensure type safety.
6
+ *
7
+ * @example
8
+ * const str = "Hello %%name%%, you are %%age%% years old."
9
+ * const result = transformTemplate(str, { name: "John", age: "20" })
10
+ * // Result: "Hello John, you are 20 years old."
11
+ */
12
+ function transformTemplate(templateString, values) {
13
+ let result = templateString;
14
+ for (const key in values) {
15
+ const placeholder = `%%${key}%%`;
16
+ result = result.replace(new RegExp(placeholder, "g"), values[key]);
17
+ }
18
+ return result;
19
+ }
20
+
21
+ //#endregion
22
+ exports.transformTemplate = transformTemplate;
@@ -0,0 +1,15 @@
1
+ //#region src/transformTemplate.d.ts
2
+ type ExtractPlaceholders<T extends string> = T extends `${infer _Start}%%${infer Key}%%${infer Rest}` ? Key | ExtractPlaceholders<Rest> : never;
3
+ type TransformTemplateArgs<T extends string> = { [Key in ExtractPlaceholders<T>]: string };
4
+ /**
5
+ * Replaces placeholders in the format %%key%% in a template string with values from the values object.
6
+ * Uses generic type T to automatically infer placeholder keys from the template string to ensure type safety.
7
+ *
8
+ * @example
9
+ * const str = "Hello %%name%%, you are %%age%% years old."
10
+ * const result = transformTemplate(str, { name: "John", age: "20" })
11
+ * // Result: "Hello John, you are 20 years old."
12
+ */
13
+ declare function transformTemplate<T extends string>(templateString: T, values: TransformTemplateArgs<T>): string;
14
+ //#endregion
15
+ export { transformTemplate };
@@ -0,0 +1,15 @@
1
+ //#region src/transformTemplate.d.ts
2
+ type ExtractPlaceholders<T extends string> = T extends `${infer _Start}%%${infer Key}%%${infer Rest}` ? Key | ExtractPlaceholders<Rest> : never;
3
+ type TransformTemplateArgs<T extends string> = { [Key in ExtractPlaceholders<T>]: string };
4
+ /**
5
+ * Replaces placeholders in the format %%key%% in a template string with values from the values object.
6
+ * Uses generic type T to automatically infer placeholder keys from the template string to ensure type safety.
7
+ *
8
+ * @example
9
+ * const str = "Hello %%name%%, you are %%age%% years old."
10
+ * const result = transformTemplate(str, { name: "John", age: "20" })
11
+ * // Result: "Hello John, you are 20 years old."
12
+ */
13
+ declare function transformTemplate<T extends string>(templateString: T, values: TransformTemplateArgs<T>): string;
14
+ //#endregion
15
+ export { transformTemplate };
@@ -0,0 +1,21 @@
1
+ //#region src/transformTemplate.ts
2
+ /**
3
+ * Replaces placeholders in the format %%key%% in a template string with values from the values object.
4
+ * Uses generic type T to automatically infer placeholder keys from the template string to ensure type safety.
5
+ *
6
+ * @example
7
+ * const str = "Hello %%name%%, you are %%age%% years old."
8
+ * const result = transformTemplate(str, { name: "John", age: "20" })
9
+ * // Result: "Hello John, you are 20 years old."
10
+ */
11
+ function transformTemplate(templateString, values) {
12
+ let result = templateString;
13
+ for (const key in values) {
14
+ const placeholder = `%%${key}%%`;
15
+ result = result.replace(new RegExp(placeholder, "g"), values[key]);
16
+ }
17
+ return result;
18
+ }
19
+
20
+ //#endregion
21
+ export { transformTemplate };