envilder 0.5.0 → 0.5.2
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 +80 -29
- package/lib/cli/cli.d.ts +10 -0
- package/lib/cli/cli.d.ts.map +1 -0
- package/lib/cli/cli.js +76 -0
- package/lib/cli/cli.js.map +1 -0
- package/lib/index.d.ts +11 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +116 -0
- package/lib/index.js.map +1 -0
- package/package.json +29 -6
- package/.gitattributes +0 -67
- package/.gitconfig +0 -2
- package/.github/dependabot.yml +0 -40
- package/.github/pull_request_template.md +0 -20
- package/.github/workflows/cli-validation.yml +0 -58
- package/.github/workflows/codeql-analysis.yml +0 -49
- package/.github/workflows/coverage-report.yml +0 -73
- package/.github/workflows/publish.yml +0 -80
- package/.github/workflows/unit-tests.yml +0 -52
- package/.secretlintrc.json +0 -7
- package/biome.json +0 -30
- package/scripts/chmod-cli.js +0 -24
- package/scripts/validate-cli.ts +0 -141
- package/src/cli/cli.ts +0 -76
- package/src/index.ts +0 -119
- package/tests/cli/cli.test.ts +0 -59
- package/tests/index.test.ts +0 -150
- package/tests/sample/autogenerated.env +0 -1
- package/tests/sample/cli-validation.env +0 -1
- package/tests/sample/param-map.json +0 -3
- package/tsconfig.build.json +0 -14
- package/tsconfig.json +0 -30
- package/vite.config.ts +0 -17
- package/vitest.config.js +0 -12
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
name: 🍄 Test CLI
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
workflow_dispatch: {}
|
|
5
|
-
|
|
6
|
-
pull_request:
|
|
7
|
-
branches:
|
|
8
|
-
- "*"
|
|
9
|
-
types:
|
|
10
|
-
- opened
|
|
11
|
-
- reopened
|
|
12
|
-
- synchronize
|
|
13
|
-
- ready_for_review
|
|
14
|
-
paths:
|
|
15
|
-
- ".github/workflows/cli-validation.yml"
|
|
16
|
-
- "src/**"
|
|
17
|
-
- "scripts/**"
|
|
18
|
-
- "tests/**"
|
|
19
|
-
|
|
20
|
-
jobs:
|
|
21
|
-
validate:
|
|
22
|
-
runs-on: ubuntu-24.04
|
|
23
|
-
if: ${{ !github.event.pull_request.draft }}
|
|
24
|
-
timeout-minutes: 30
|
|
25
|
-
|
|
26
|
-
steps:
|
|
27
|
-
- name: 🚀 ♂️ Checkout
|
|
28
|
-
uses: actions/checkout@v4
|
|
29
|
-
|
|
30
|
-
- name: 🛠️ Setup Node.js with Cache
|
|
31
|
-
uses: actions/setup-node@v4
|
|
32
|
-
with:
|
|
33
|
-
node-version: '20.x'
|
|
34
|
-
cache: 'yarn'
|
|
35
|
-
|
|
36
|
-
- name: 💉 Configure AWS credentials
|
|
37
|
-
uses: aws-actions/configure-aws-credentials@v4
|
|
38
|
-
with:
|
|
39
|
-
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
|
40
|
-
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
|
41
|
-
aws-region: "eu-west-1"
|
|
42
|
-
|
|
43
|
-
- name: 🪙 Collect dependencies
|
|
44
|
-
run: yarn install --frozen-lockfile
|
|
45
|
-
|
|
46
|
-
- name: 🏗️ Build the castle
|
|
47
|
-
run: yarn build
|
|
48
|
-
|
|
49
|
-
- name: 🧩 Ensure executable permissions
|
|
50
|
-
run: |
|
|
51
|
-
chmod +x ./lib/cli/cli.js
|
|
52
|
-
|
|
53
|
-
- name: 🌈 Install envilder globally (with npm)
|
|
54
|
-
run: |
|
|
55
|
-
sudo npm install -g .
|
|
56
|
-
|
|
57
|
-
- name: 🎮 Test cli envilder
|
|
58
|
-
run: yarn validate-cli
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
name: CodeQL
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
workflow_dispatch:
|
|
5
|
-
|
|
6
|
-
pull_request:
|
|
7
|
-
branches: [main]
|
|
8
|
-
paths:
|
|
9
|
-
- ".github/workflows/codeql-analysis.yml"
|
|
10
|
-
|
|
11
|
-
push:
|
|
12
|
-
branches: [main]
|
|
13
|
-
paths:
|
|
14
|
-
- ".github/workflows/codeql-analysis.yml"
|
|
15
|
-
- "src/**"
|
|
16
|
-
- "test/**"
|
|
17
|
-
|
|
18
|
-
concurrency:
|
|
19
|
-
group: ${{ github.workflow }}-${{ github.head_ref || github.sha }}
|
|
20
|
-
cancel-in-progress: true
|
|
21
|
-
|
|
22
|
-
jobs:
|
|
23
|
-
analyze:
|
|
24
|
-
strategy:
|
|
25
|
-
fail-fast: false
|
|
26
|
-
matrix:
|
|
27
|
-
language: ["javascript"]
|
|
28
|
-
|
|
29
|
-
permissions:
|
|
30
|
-
security-events: write
|
|
31
|
-
|
|
32
|
-
runs-on: ubuntu-22.04
|
|
33
|
-
|
|
34
|
-
steps:
|
|
35
|
-
- name: Checkout Repository
|
|
36
|
-
uses: actions/checkout@v4
|
|
37
|
-
with:
|
|
38
|
-
lfs: true
|
|
39
|
-
|
|
40
|
-
- name: Initialize CodeQL
|
|
41
|
-
uses: github/codeql-action/init@v3
|
|
42
|
-
with:
|
|
43
|
-
languages: ${{ matrix.language }}
|
|
44
|
-
|
|
45
|
-
- name: Autobuild
|
|
46
|
-
uses: github/codeql-action/autobuild@v3
|
|
47
|
-
|
|
48
|
-
- name: Perform CodeQL Analysis
|
|
49
|
-
uses: github/codeql-action/analyze@v3
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
name: 🔦 code-coverage
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
workflow_dispatch:
|
|
5
|
-
|
|
6
|
-
pull_request:
|
|
7
|
-
paths:
|
|
8
|
-
- ".github/workflows/coverage-report.yml"
|
|
9
|
-
|
|
10
|
-
push:
|
|
11
|
-
branches:
|
|
12
|
-
- "main"
|
|
13
|
-
paths:
|
|
14
|
-
- ".github/workflows/coverage-report.yml"
|
|
15
|
-
- "src/**"
|
|
16
|
-
- "test/**"
|
|
17
|
-
|
|
18
|
-
concurrency:
|
|
19
|
-
group: "pages"
|
|
20
|
-
cancel-in-progress: false
|
|
21
|
-
|
|
22
|
-
permissions:
|
|
23
|
-
contents: read
|
|
24
|
-
pages: write
|
|
25
|
-
id-token: write
|
|
26
|
-
|
|
27
|
-
jobs:
|
|
28
|
-
build-coverage:
|
|
29
|
-
environment:
|
|
30
|
-
name: github-pages
|
|
31
|
-
url: ${{ steps.deployment.outputs.page_url }}
|
|
32
|
-
runs-on: ubuntu-latest
|
|
33
|
-
if: ${{ !github.event.pull_request.draft }}
|
|
34
|
-
steps:
|
|
35
|
-
- name: Check if PR is created by Dependabot
|
|
36
|
-
id: dependabot-check
|
|
37
|
-
run: |
|
|
38
|
-
if [[ "${{ github.actor }}" == *dependabot* ]]; then
|
|
39
|
-
echo "is_dependabot=true" >> "$GITHUB_OUTPUT"
|
|
40
|
-
else
|
|
41
|
-
echo "is_dependabot=false" >> "$GITHUB_OUTPUT"
|
|
42
|
-
fi
|
|
43
|
-
|
|
44
|
-
- name: Check if the workflow should run
|
|
45
|
-
if: ${{ steps.dependabot-check.outputs.is_dependabot == 'false' }}
|
|
46
|
-
run: echo "The workflow is allowed to run for this PR"
|
|
47
|
-
|
|
48
|
-
- name: 🧲 Checkout
|
|
49
|
-
uses: actions/checkout@v4
|
|
50
|
-
|
|
51
|
-
- name: 🛠️ Setup Node.js with Cache
|
|
52
|
-
uses: actions/setup-node@v4
|
|
53
|
-
with:
|
|
54
|
-
node-version: "20.x"
|
|
55
|
-
cache: "yarn"
|
|
56
|
-
|
|
57
|
-
- name: 📦 Install dependencies
|
|
58
|
-
run: yarn install
|
|
59
|
-
|
|
60
|
-
- name: 🔥 Run tests and collect coverage
|
|
61
|
-
run: yarn test
|
|
62
|
-
|
|
63
|
-
- name: Setup Pages
|
|
64
|
-
uses: actions/configure-pages@v5
|
|
65
|
-
|
|
66
|
-
- name: Upload artifact
|
|
67
|
-
uses: actions/upload-pages-artifact@v3
|
|
68
|
-
with:
|
|
69
|
-
path: "./coverage"
|
|
70
|
-
|
|
71
|
-
- name: Deploy to GitHub Pages
|
|
72
|
-
id: deployment
|
|
73
|
-
uses: actions/deploy-pages@v4
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
name: 🍄 Power-Up Publisher
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
branches:
|
|
6
|
-
- main
|
|
7
|
-
paths:
|
|
8
|
-
- 'src/**'
|
|
9
|
-
- 'package.json'
|
|
10
|
-
- '.github/workflows/publish.yml'
|
|
11
|
-
|
|
12
|
-
# Add explicit permissions for the GITHUB_TOKEN
|
|
13
|
-
permissions:
|
|
14
|
-
contents: write
|
|
15
|
-
packages: write
|
|
16
|
-
|
|
17
|
-
jobs:
|
|
18
|
-
publish:
|
|
19
|
-
runs-on: ubuntu-latest
|
|
20
|
-
steps:
|
|
21
|
-
- name: 🧱 Checkout repository
|
|
22
|
-
uses: actions/checkout@v3
|
|
23
|
-
with:
|
|
24
|
-
fetch-depth: 0
|
|
25
|
-
|
|
26
|
-
- name: 🔧 Setup Node.js
|
|
27
|
-
uses: actions/setup-node@v3
|
|
28
|
-
with:
|
|
29
|
-
node-version: '20'
|
|
30
|
-
registry-url: 'https://registry.npmjs.org'
|
|
31
|
-
cache: 'yarn'
|
|
32
|
-
|
|
33
|
-
- name: 🌟 Install dependencies
|
|
34
|
-
run: yarn install --frozen-lockfile
|
|
35
|
-
|
|
36
|
-
- name: 🔥 Lint
|
|
37
|
-
run: yarn lint
|
|
38
|
-
|
|
39
|
-
- name: 🍄 Run tests
|
|
40
|
-
run: yarn test
|
|
41
|
-
|
|
42
|
-
- name: 👑 Detect version bump
|
|
43
|
-
id: version-check
|
|
44
|
-
run: |
|
|
45
|
-
CURRENT_VERSION=$(node -p "require('./package.json').version")
|
|
46
|
-
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
|
|
47
|
-
LAST_TAG_VERSION=${LAST_TAG#v}
|
|
48
|
-
|
|
49
|
-
echo "Current version: $CURRENT_VERSION, Last tag version: $LAST_TAG_VERSION"
|
|
50
|
-
|
|
51
|
-
# Check if the current version is greater than the last tagged version
|
|
52
|
-
if [ "$CURRENT_VERSION" != "$LAST_TAG_VERSION" ]; then
|
|
53
|
-
echo "Version has been bumped from $LAST_TAG_VERSION to $CURRENT_VERSION"
|
|
54
|
-
echo "version_changed=true" >> $GITHUB_OUTPUT
|
|
55
|
-
echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
|
|
56
|
-
else
|
|
57
|
-
echo "Version not changed. Will not publish."
|
|
58
|
-
echo "version_changed=false" >> $GITHUB_OUTPUT
|
|
59
|
-
fi
|
|
60
|
-
|
|
61
|
-
- name: 🔨 Build package
|
|
62
|
-
if: steps.version-check.outputs.version_changed == 'true'
|
|
63
|
-
run: yarn build
|
|
64
|
-
|
|
65
|
-
- name: 🚩 Publish to npm
|
|
66
|
-
if: steps.version-check.outputs.version_changed == 'true'
|
|
67
|
-
run: yarn publish --non-interactive
|
|
68
|
-
env:
|
|
69
|
-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
70
|
-
|
|
71
|
-
- name: 🏰 Create GitHub Release
|
|
72
|
-
if: steps.version-check.outputs.version_changed == 'true'
|
|
73
|
-
uses: ncipollo/release-action@v1
|
|
74
|
-
with:
|
|
75
|
-
tag: "v${{ steps.version-check.outputs.current_version }}"
|
|
76
|
-
name: "🍄 Level Up Release v${{ steps.version-check.outputs.current_version }}"
|
|
77
|
-
generateReleaseNotes: true
|
|
78
|
-
token: ${{ secrets.GITHUB_TOKEN }}
|
|
79
|
-
makeLatest: legacy
|
|
80
|
-
replacesArtifacts: true
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
name: 🌱 unit-tests
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
workflow_dispatch: {}
|
|
5
|
-
|
|
6
|
-
pull_request:
|
|
7
|
-
branches:
|
|
8
|
-
- "*"
|
|
9
|
-
types:
|
|
10
|
-
- opened
|
|
11
|
-
- reopened
|
|
12
|
-
- synchronize
|
|
13
|
-
- ready_for_review
|
|
14
|
-
paths:
|
|
15
|
-
- ".github/workflows/unit-tests.yml"
|
|
16
|
-
- "src/**"
|
|
17
|
-
- "tests/**"
|
|
18
|
-
|
|
19
|
-
concurrency:
|
|
20
|
-
group: ${{ github.workflow }}-${{ github.head_ref || github.sha }}
|
|
21
|
-
cancel-in-progress: true
|
|
22
|
-
|
|
23
|
-
jobs:
|
|
24
|
-
envilder-test:
|
|
25
|
-
runs-on: ubuntu-24.04
|
|
26
|
-
if: ${{ !github.event.pull_request.draft }}
|
|
27
|
-
timeout-minutes: 30
|
|
28
|
-
|
|
29
|
-
steps:
|
|
30
|
-
- name: 🚀 ♂️ Checkout
|
|
31
|
-
uses: actions/checkout@v4
|
|
32
|
-
|
|
33
|
-
- name: 🛠️ Setup Node.js with Cache
|
|
34
|
-
uses: actions/setup-node@v4
|
|
35
|
-
with:
|
|
36
|
-
node-version: '20.x'
|
|
37
|
-
cache: 'yarn'
|
|
38
|
-
|
|
39
|
-
- name: 📦 Install packages
|
|
40
|
-
run: yarn install --frozen-lockfile
|
|
41
|
-
|
|
42
|
-
- name: 🔍 Run formatting checker
|
|
43
|
-
run: yarn format
|
|
44
|
-
|
|
45
|
-
- name: 🔍 Run code quality checker
|
|
46
|
-
run: yarn lint
|
|
47
|
-
|
|
48
|
-
- name: 🚧 Build
|
|
49
|
-
run: yarn build
|
|
50
|
-
|
|
51
|
-
- name: 🚴♀️ Run unit tests
|
|
52
|
-
run: yarn test
|
package/.secretlintrc.json
DELETED
package/biome.json
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://biomejs.dev/schemas/1.8.3/schema.json",
|
|
3
|
-
"files": {
|
|
4
|
-
"include": ["./src/**", "./tests/**", "./scripts/**"],
|
|
5
|
-
"ignore": ["**/node_modules/**", "**/lib/**", "**/dist/**", "**/coverage/**", "**/.lock", "**/.md"]
|
|
6
|
-
},
|
|
7
|
-
"organizeImports": {
|
|
8
|
-
"enabled": true
|
|
9
|
-
},
|
|
10
|
-
"linter": {
|
|
11
|
-
"enabled": true,
|
|
12
|
-
"rules": {
|
|
13
|
-
"recommended": true
|
|
14
|
-
}
|
|
15
|
-
},
|
|
16
|
-
"formatter": {
|
|
17
|
-
"enabled": true,
|
|
18
|
-
"formatWithErrors": false,
|
|
19
|
-
"indentStyle": "space",
|
|
20
|
-
"indentWidth": 2,
|
|
21
|
-
"lineWidth": 120
|
|
22
|
-
},
|
|
23
|
-
"javascript": {
|
|
24
|
-
"formatter": {
|
|
25
|
-
"quoteStyle": "single",
|
|
26
|
-
"trailingCommas": "all",
|
|
27
|
-
"semicolons": "always"
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
package/scripts/chmod-cli.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* Simple script to set executable permissions on the CLI entry point.
|
|
4
|
-
* Only runs the chmod command on Unix-based systems.
|
|
5
|
-
*/
|
|
6
|
-
import { chmod } from 'node:fs/promises';
|
|
7
|
-
import { join } from 'node:path';
|
|
8
|
-
import { fileURLToPath } from 'node:url';
|
|
9
|
-
|
|
10
|
-
// Get the project root directory
|
|
11
|
-
const rootDir = join(fileURLToPath(new URL('.', import.meta.url)), '..');
|
|
12
|
-
const cliFilePath = join(rootDir, 'lib', 'cli', 'cli.js');
|
|
13
|
-
|
|
14
|
-
// Only run on non-Windows platforms
|
|
15
|
-
if (process.platform !== 'win32') {
|
|
16
|
-
chmod(cliFilePath, 0o755) // rwxr-xr-x permissions
|
|
17
|
-
.then(() => console.log(`✅ Set executable permissions for: ${cliFilePath}`))
|
|
18
|
-
.catch((error) => {
|
|
19
|
-
console.error(`❌ Error setting permissions: ${error.message}`);
|
|
20
|
-
process.exit(1);
|
|
21
|
-
});
|
|
22
|
-
} else {
|
|
23
|
-
console.log('📋 Skipping executable permissions on Windows platform');
|
|
24
|
-
}
|
package/scripts/validate-cli.ts
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { spawn } from 'node:child_process';
|
|
3
|
-
import { existsSync } from 'node:fs';
|
|
4
|
-
import { dirname, join } from 'node:path';
|
|
5
|
-
import { fileURLToPath } from 'node:url';
|
|
6
|
-
|
|
7
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
8
|
-
const __dirname = dirname(__filename);
|
|
9
|
-
const rootDir = join(__dirname, '..');
|
|
10
|
-
const isGithubAction = process.env.GITHUB_ACTIONS === 'true';
|
|
11
|
-
const isWindows = process.platform === 'win32';
|
|
12
|
-
const findCommand = isWindows ? 'where' : 'which';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Run a command with the given arguments
|
|
16
|
-
*/
|
|
17
|
-
function runCommand(command: string, args: string[]): Promise<{ code: number; output: string }> {
|
|
18
|
-
return new Promise((resolve) => {
|
|
19
|
-
const proc = spawn(command, args, { shell: true });
|
|
20
|
-
let output = '';
|
|
21
|
-
|
|
22
|
-
proc.stdout.on('data', (data) => {
|
|
23
|
-
output += data.toString();
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
proc.stderr.on('data', (data) => {
|
|
27
|
-
output += data.toString();
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
proc.on('close', (code) => {
|
|
31
|
-
resolve({ code: code ?? 0, output });
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Try to run a command with both global and local CLI approaches
|
|
38
|
-
*/
|
|
39
|
-
async function tryCommandWithFallback(
|
|
40
|
-
args: string[],
|
|
41
|
-
): Promise<{ code: number; output: string; usedFallback: boolean }> {
|
|
42
|
-
// Try global command first
|
|
43
|
-
const globalResult = await runCommand('envilder', args);
|
|
44
|
-
|
|
45
|
-
if (globalResult.code === 0) {
|
|
46
|
-
return { ...globalResult, usedFallback: false };
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// Fall back to direct node execution
|
|
50
|
-
console.log('Global envilder command failed, trying direct Node.js execution...');
|
|
51
|
-
const directResult = await runCommand('node', ['./lib/cli/cli.js', ...args]);
|
|
52
|
-
|
|
53
|
-
return {
|
|
54
|
-
...directResult,
|
|
55
|
-
usedFallback: true,
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
async function validateCLI() {
|
|
60
|
-
console.log(`🔍 Validating envilder CLI installation${isGithubAction ? ' in GitHub Actions' : ''}...`);
|
|
61
|
-
|
|
62
|
-
try {
|
|
63
|
-
// Test 1: Check CLI version and accessibility
|
|
64
|
-
console.log('Testing envilder version command...');
|
|
65
|
-
const versionResult = await tryCommandWithFallback(['--version']);
|
|
66
|
-
|
|
67
|
-
if (versionResult.code !== 0) {
|
|
68
|
-
throw new Error(`❌ envilder version command failed: ${versionResult.output}`);
|
|
69
|
-
}
|
|
70
|
-
console.log('✅ envilder version command works');
|
|
71
|
-
|
|
72
|
-
// Test 2: Check help command
|
|
73
|
-
console.log('Testing envilder help command...');
|
|
74
|
-
const helpResult = await tryCommandWithFallback(['--help']);
|
|
75
|
-
|
|
76
|
-
if (helpResult.code !== 0) {
|
|
77
|
-
throw new Error(`❌ envilder help command failed: ${helpResult.output}`);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (!helpResult.output.includes('--map') || !helpResult.output.includes('--envfile')) {
|
|
81
|
-
throw new Error('❌ envilder help command output is missing expected options');
|
|
82
|
-
}
|
|
83
|
-
console.log('✅ envilder help command works');
|
|
84
|
-
|
|
85
|
-
// Test 3: Check sample file generation
|
|
86
|
-
const testEnvFile = join(rootDir, 'tests', 'sample', 'cli-validation.env');
|
|
87
|
-
console.log('Testing envilder file generation...');
|
|
88
|
-
|
|
89
|
-
const sampleResult = await tryCommandWithFallback([
|
|
90
|
-
'--map',
|
|
91
|
-
join(rootDir, 'tests', 'sample', 'param-map.json'),
|
|
92
|
-
'--envfile',
|
|
93
|
-
testEnvFile,
|
|
94
|
-
]);
|
|
95
|
-
|
|
96
|
-
if (sampleResult.code !== 0) {
|
|
97
|
-
throw new Error(`❌ envilder failed to generate environment file: ${sampleResult.output}`);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (!sampleResult.output.includes('Environment File generated')) {
|
|
101
|
-
throw new Error('❌ envilder did not output expected success message');
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if (!existsSync(testEnvFile)) {
|
|
105
|
-
throw new Error(`❌ envilder did not create the environment file at ${testEnvFile}`);
|
|
106
|
-
}
|
|
107
|
-
console.log('✅ envilder successfully generated environment file');
|
|
108
|
-
|
|
109
|
-
// Test 4: Check error handling for invalid arguments
|
|
110
|
-
console.log('Testing envilder with invalid arguments...');
|
|
111
|
-
const errorResult = await tryCommandWithFallback(['--invalid']);
|
|
112
|
-
|
|
113
|
-
if (errorResult.code === 0) {
|
|
114
|
-
throw new Error('❌ envilder should fail with invalid arguments');
|
|
115
|
-
}
|
|
116
|
-
console.log('✅ envilder properly handles invalid arguments');
|
|
117
|
-
|
|
118
|
-
// Test 5: Check error handling for missing required options
|
|
119
|
-
console.log('Testing envilder with missing required options...');
|
|
120
|
-
const missingResult = await tryCommandWithFallback([]);
|
|
121
|
-
|
|
122
|
-
if (missingResult.code === 0) {
|
|
123
|
-
throw new Error('❌ envilder should fail when required options are missing');
|
|
124
|
-
}
|
|
125
|
-
console.log('✅ envilder properly handles missing required options');
|
|
126
|
-
|
|
127
|
-
console.log('🎉 All CLI validation tests passed!');
|
|
128
|
-
} catch (error) {
|
|
129
|
-
if (error instanceof Error) {
|
|
130
|
-
console.error(error.message);
|
|
131
|
-
} else {
|
|
132
|
-
console.error('Unknown error occurred during CLI validation');
|
|
133
|
-
}
|
|
134
|
-
process.exit(1);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
validateCLI().catch((error) => {
|
|
139
|
-
console.error(error.message);
|
|
140
|
-
process.exit(1);
|
|
141
|
-
});
|
package/src/cli/cli.ts
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { existsSync, readFileSync } from 'node:fs';
|
|
3
|
-
import { dirname, join } from 'node:path';
|
|
4
|
-
import { fileURLToPath } from 'node:url';
|
|
5
|
-
import { Command } from 'commander';
|
|
6
|
-
import { run } from '../index.js';
|
|
7
|
-
|
|
8
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
9
|
-
const __dirname = dirname(__filename);
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Find the package.json file by traversing up directories
|
|
13
|
-
* @param startDir The directory to start searching from
|
|
14
|
-
* @param maxDepth Maximum number of parent directories to check
|
|
15
|
-
* @returns Path to package.json if found, or null if not found
|
|
16
|
-
*/
|
|
17
|
-
function findPackageJson(startDir: string, maxDepth = 5): string | null {
|
|
18
|
-
let currentDir = startDir;
|
|
19
|
-
let depth = 0;
|
|
20
|
-
|
|
21
|
-
while (depth < maxDepth) {
|
|
22
|
-
const packagePath = join(currentDir, 'package.json');
|
|
23
|
-
if (existsSync(packagePath)) {
|
|
24
|
-
return packagePath;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// Go up one directory
|
|
28
|
-
const parentDir = dirname(currentDir);
|
|
29
|
-
if (parentDir === currentDir) {
|
|
30
|
-
// We've reached the root
|
|
31
|
-
break;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
currentDir = parentDir;
|
|
35
|
-
depth++;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// Get package.json path by searching up from current file
|
|
42
|
-
const packageJsonPath = findPackageJson(__dirname) || join(__dirname, '..', '..', 'package.json');
|
|
43
|
-
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'));
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Parses CLI arguments and runs the environment file generator.
|
|
47
|
-
*
|
|
48
|
-
* Expects `--map` and `--envfile` options to be provided, with an optional `--profile` for AWS CLI profile selection. Invokes the main process to generate a `.env` file from AWS SSM parameters based on the provided mapping.
|
|
49
|
-
*
|
|
50
|
-
* @throws {Error} If either `--map` or `--envfile` arguments are missing.
|
|
51
|
-
*/
|
|
52
|
-
export async function main() {
|
|
53
|
-
const program = new Command();
|
|
54
|
-
program
|
|
55
|
-
.name('envilder')
|
|
56
|
-
.description('A CLI tool to generate .env files from AWS SSM parameters')
|
|
57
|
-
.version(packageJson.version)
|
|
58
|
-
.requiredOption('--map <path>', 'Path to the JSON file with environment variable mapping')
|
|
59
|
-
.requiredOption('--envfile <path>', 'Path to the .env file to be generated')
|
|
60
|
-
.option('--profile <name>', 'AWS CLI profile to use');
|
|
61
|
-
|
|
62
|
-
await program.parseAsync(process.argv);
|
|
63
|
-
const options = program.opts();
|
|
64
|
-
|
|
65
|
-
if (!options.map || !options.envfile) {
|
|
66
|
-
throw new Error('Missing required arguments: --map and --envfile');
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
await run(options.map, options.envfile, options.profile);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// Execute the CLI
|
|
73
|
-
main().catch((error) => {
|
|
74
|
-
console.error('🚨 Uh-oh! Looks like Mario fell into the wrong pipe! 🍄💥');
|
|
75
|
-
console.error(error);
|
|
76
|
-
});
|