safelaunch 1.0.2 → 1.0.3

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.
@@ -1,14 +1,12 @@
1
1
  #!/usr/bin/env node
2
-
3
- const args = process.argv.slice(2);
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
- ' deploycheck validate Check your environment against the manifest\n'
13
- );
14
- }
10
+ console.log(' safelaunch init');
11
+ console.log(' safelaunch validate');
12
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "safelaunch",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Backend Reliability Infrastructure - catch what breaks production before it breaks",
5
5
  "main": "index.js",
6
6
  "bin": {
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();