safelaunch 1.0.2 → 1.0.4
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/README.md +20 -42
- package/bin/deploycheck.js +8 -10
- package/package.json +1 -1
- package/src/init.js +54 -0
package/README.md
CHANGED
|
@@ -5,46 +5,26 @@
|
|
|
5
5
|
safelaunch validates your local environment against a required environment contract before you push to production. No more missing variables. No more runtime mismatches. No more production surprises.
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
|
-
|
|
8
|
+
|
|
9
9
|
npm install -g safelaunch
|
|
10
|
-
```
|
|
11
10
|
|
|
12
11
|
## Quick Start
|
|
13
12
|
|
|
14
|
-
**Step 1:
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"DATABASE_URL": {
|
|
25
|
-
"required": true,
|
|
26
|
-
"description": "PostgreSQL connection string"
|
|
27
|
-
},
|
|
28
|
-
"REDIS_URL": {
|
|
29
|
-
"required": true,
|
|
30
|
-
"description": "Redis connection string"
|
|
31
|
-
},
|
|
32
|
-
"API_KEY": {
|
|
33
|
-
"required": true,
|
|
34
|
-
"description": "External API key"
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
**Step 2: Run the validator**
|
|
41
|
-
```bash
|
|
13
|
+
**Step 1: Generate your environment manifest automatically**
|
|
14
|
+
|
|
15
|
+
Run this in your project folder:
|
|
16
|
+
|
|
17
|
+
safelaunch init
|
|
18
|
+
|
|
19
|
+
safelaunch scans your entire codebase, finds every environment variable your app uses, and generates env.manifest.json automatically.
|
|
20
|
+
|
|
21
|
+
**Step 2: Validate before you push**
|
|
22
|
+
|
|
42
23
|
safelaunch validate
|
|
43
|
-
```
|
|
44
24
|
|
|
45
|
-
**Step 3: See exactly what
|
|
46
|
-
|
|
47
|
-
Running safelaunch
|
|
25
|
+
**Step 3: See exactly what will break**
|
|
26
|
+
|
|
27
|
+
Running safelaunch validate gives you:
|
|
48
28
|
|
|
49
29
|
❌ MISSING VARIABLES (2 found)
|
|
50
30
|
|
|
@@ -57,23 +37,21 @@ Running safelaunch...
|
|
|
57
37
|
|
|
58
38
|
Your environment is not ready for production.
|
|
59
39
|
Fix the issues above and run safelaunch again.
|
|
60
|
-
|
|
40
|
+
|
|
41
|
+
## Commands
|
|
42
|
+
|
|
43
|
+
safelaunch init scan project and generate env.manifest.json automatically
|
|
44
|
+
safelaunch validate validate your .env against the manifest
|
|
61
45
|
|
|
62
46
|
## CI Integration
|
|
63
47
|
|
|
64
48
|
Add this to your GitHub Actions workflow to block deployments automatically:
|
|
65
|
-
|
|
49
|
+
|
|
66
50
|
- name: Install safelaunch
|
|
67
51
|
run: npm install -g safelaunch
|
|
68
52
|
|
|
69
53
|
- name: Validate environment
|
|
70
54
|
run: safelaunch validate
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
## What it checks
|
|
74
|
-
|
|
75
|
-
- Missing required environment variables
|
|
76
|
-
- Runtime version mismatches between local and manifest
|
|
77
55
|
|
|
78
56
|
## Built by Orches
|
|
79
57
|
|
package/bin/deploycheck.js
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
const command = args[0];
|
|
5
|
-
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const command = process.argv[2];
|
|
6
4
|
if (command === 'validate') {
|
|
7
|
-
require('../src/validate.js');
|
|
5
|
+
require(path.join(__dirname, '../src/validate.js'));
|
|
6
|
+
} else if (command === 'init') {
|
|
7
|
+
require(path.join(__dirname, '../src/init.js'));
|
|
8
8
|
} else {
|
|
9
|
-
console.log('\ndeploycheck - Backend Reliability Infrastructure\n');
|
|
10
9
|
console.log('Usage:');
|
|
11
|
-
console.log(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
10
|
+
console.log(' safelaunch init');
|
|
11
|
+
console.log(' safelaunch validate');
|
|
12
|
+
}
|
package/package.json
CHANGED
package/src/init.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
function scanFiles(dir, extensions, found = new Set()) {
|
|
5
|
+
const items = fs.readdirSync(dir);
|
|
6
|
+
for (const item of items) {
|
|
7
|
+
if (item === 'node_modules' || item === '.git') continue;
|
|
8
|
+
const full = path.join(dir, item);
|
|
9
|
+
const stat = fs.statSync(full);
|
|
10
|
+
if (stat.isDirectory()) {
|
|
11
|
+
scanFiles(full, extensions, found);
|
|
12
|
+
} else if (extensions.some(ext => item.endsWith(ext))) {
|
|
13
|
+
const content = fs.readFileSync(full, 'utf8');
|
|
14
|
+
const matches = content.matchAll(/process\.env\.([A-Z_][A-Z0-9_]*)/g);
|
|
15
|
+
for (const match of matches) {
|
|
16
|
+
found.add(match[1]);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return found;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function init() {
|
|
24
|
+
console.log('\nscanning project for environment variables...\n');
|
|
25
|
+
const cwd = process.cwd();
|
|
26
|
+
const extensions = ['.js', '.ts', '.jsx', '.tsx'];
|
|
27
|
+
const found = scanFiles(cwd, extensions);
|
|
28
|
+
if (found.size === 0) {
|
|
29
|
+
console.log('no process.env references found.\n');
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const variables = {};
|
|
33
|
+
for (const key of [...found].sort()) {
|
|
34
|
+
variables[key] = { required: true, description: '' };
|
|
35
|
+
}
|
|
36
|
+
const manifest = {
|
|
37
|
+
version: '1',
|
|
38
|
+
runtime: { node: process.version.replace('v', '').split('.')[0] },
|
|
39
|
+
variables
|
|
40
|
+
};
|
|
41
|
+
const manifestPath = path.join(cwd, 'env.manifest.json');
|
|
42
|
+
if (fs.existsSync(manifestPath)) {
|
|
43
|
+
console.log('env.manifest.json already exists. delete it first.\n');
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2));
|
|
47
|
+
console.log('found ' + found.size + ' environment variables:\n');
|
|
48
|
+
for (const key of [...found].sort()) {
|
|
49
|
+
console.log(' ' + key);
|
|
50
|
+
}
|
|
51
|
+
console.log('\ncreated env.manifest.json\n');
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
init();
|