@marvalt/digivalt-core 0.1.4 → 0.1.6
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/package.json
CHANGED
|
@@ -10,39 +10,42 @@ import { execSync } from 'child_process';
|
|
|
10
10
|
* using Wrangler bulk secret injection.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
const envPath = path.resolve(process.cwd(), '.env.local');
|
|
14
|
-
|
|
15
|
-
if (!fs.existsSync(envPath)) {
|
|
16
|
-
console.error("❌ No .env.local file found in the root directory!");
|
|
17
|
-
console.log("👉 Please create a .env.local file with your production secrets.");
|
|
18
|
-
process.exit(1);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
console.log("🔍 Parsing .env.local secrets...");
|
|
22
|
-
const rawEnv = fs.readFileSync(envPath, 'utf8');
|
|
23
13
|
const secrets = {};
|
|
24
14
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
// Ignore comments and empty lines
|
|
28
|
-
if (!trimmed || trimmed.startsWith('#')) return;
|
|
15
|
+
const parseEnvFile = (filePath) => {
|
|
16
|
+
if (!fs.existsSync(filePath)) return;
|
|
29
17
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
//
|
|
36
|
-
if (
|
|
37
|
-
if (value.startsWith("'") && value.endsWith("'")) value = value.slice(1, -1);
|
|
18
|
+
console.log(`🔍 Parsing ${path.basename(filePath)} secrets...`);
|
|
19
|
+
const rawEnv = fs.readFileSync(filePath, 'utf8');
|
|
20
|
+
|
|
21
|
+
rawEnv.split('\n').forEach(line => {
|
|
22
|
+
const trimmed = line.trim();
|
|
23
|
+
// Ignore comments and empty lines
|
|
24
|
+
if (!trimmed || trimmed.startsWith('#')) return;
|
|
38
25
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
26
|
+
const match = trimmed.match(/^([^=]+)=(.*)$/);
|
|
27
|
+
if (match) {
|
|
28
|
+
const key = match[1].trim();
|
|
29
|
+
let value = match[2].trim();
|
|
30
|
+
|
|
31
|
+
// Strip surrounding quotes if present
|
|
32
|
+
if (value.startsWith('"') && value.endsWith('"')) value = value.slice(1, -1);
|
|
33
|
+
if (value.startsWith("'") && value.endsWith("'")) value = value.slice(1, -1);
|
|
34
|
+
|
|
35
|
+
secrets[key] = value;
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const defaultEnvPath = path.resolve(process.cwd(), '.env');
|
|
41
|
+
const localEnvPath = path.resolve(process.cwd(), '.env.local');
|
|
42
|
+
|
|
43
|
+
parseEnvFile(defaultEnvPath);
|
|
44
|
+
parseEnvFile(localEnvPath);
|
|
42
45
|
|
|
43
46
|
const secretCount = Object.keys(secrets).length;
|
|
44
47
|
if (secretCount === 0) {
|
|
45
|
-
console.log("⚠️ No valid SECRETS found in .env.local. Exiting.");
|
|
48
|
+
console.log("⚠️ No valid SECRETS found in .env or .env.local. Exiting.");
|
|
46
49
|
process.exit(0);
|
|
47
50
|
}
|
|
48
51
|
|
|
@@ -73,10 +76,14 @@ try {
|
|
|
73
76
|
// Construct the command string tightly bound to the exact workspace
|
|
74
77
|
let cmd = `npx wrangler pages secret bulk .tmp-cloudflare-secrets.json`;
|
|
75
78
|
if (projectName) cmd += ` --project-name ${projectName}`;
|
|
76
|
-
if (accountId) cmd += ` --account-id ${accountId}`;
|
|
77
79
|
|
|
78
|
-
// Execute Wrangler natively
|
|
79
|
-
|
|
80
|
+
// Execute Wrangler natively with the Account ID passed through the strict environment scope
|
|
81
|
+
const env = { ...process.env };
|
|
82
|
+
if (accountId) {
|
|
83
|
+
env.CLOUDFLARE_ACCOUNT_ID = accountId;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
execSync(cmd, { stdio: 'inherit', env });
|
|
80
87
|
console.log("✅ All secrets deployed successfully to Cloudflare!");
|
|
81
88
|
|
|
82
89
|
} catch (error) {
|