@saptools/cf-export 0.1.0 → 0.1.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.
Files changed (3) hide show
  1. package/README.md +164 -47
  2. package/dist/index.js +0 -0
  3. package/package.json +12 -11
package/README.md CHANGED
@@ -1,48 +1,95 @@
1
- # @saptools/cf-export
1
+ <div align="center">
2
2
 
3
- Export CAP / Cloud Foundry project configuration files from a **running** SAP BTP Cloud Foundry application.
3
+ # ðŸ“Ī `@saptools/cf-export`
4
4
 
5
- ## Why
5
+ **Export CAP / Cloud Foundry project artifacts (package.json, lockfiles, .cdsrc.json, default-env.json, .npmrc) from a running SAP BTP Cloud Foundry application.** (v0.1.1+)
6
6
 
7
- During development or incident response you often need the exact `package.json`, lockfiles, `.cdsrc.json`, `.npmrc` and a usable `default-env.json` that reflects the live binding environment of a deployed CAP/CF app.
7
+ Pull the exact files you need for local development or debugging directly from a live CF container using `cf ssh` + CF API.
8
8
 
9
- This package provides both a CLI and a library to pull those artifacts over `cf ssh` + CF API (V3 env), with explicit support for custom container root paths.
9
+ [![npm version](https://img.shields.io/npm/v/@saptools/cf-export.svg?style=flat&color=CB3837&logo=npm)](https://www.npmjs.com/package/@saptools/cf-export)
10
+ [![license](https://img.shields.io/npm/l/@saptools/cf-export.svg?style=flat&color=blue)](./LICENSE)
11
+ [![node](https://img.shields.io/node/v/@saptools/cf-export.svg?style=flat&color=339933&logo=node.js&logoColor=white)](https://nodejs.org)
12
+ [![install size](https://packagephobia.com/badge?p=@saptools/cf-export)](https://packagephobia.com/result?p=@saptools/cf-export)
13
+ [![types](https://img.shields.io/npm/types/@saptools/cf-export.svg?style=flat&color=3178C6&logo=typescript&logoColor=white)](https://www.typescriptlang.org)
10
14
 
11
- ## Supported artifacts
15
+ [Install](#-install) â€Ē [Quick Start](#-quick-start) â€Ē [CLI](#-cli) â€Ē [API](#-programmatic-usage) â€Ē [Development](#-development)
12
16
 
13
- | File | Source | Notes |
14
- |--------------------|----------------------------|------------------------------------|
15
- | `package.json` | cf ssh cat | optional |
16
- | `package-lock.json`| cf ssh cat | optional |
17
- | `pnpm-lock.yaml` | cf ssh cat | optional |
18
- | `.cdsrc.json` | cf ssh cat | optional |
19
- | `default-env.json` | `cf curl /v3/apps/.../env` | synthesized (VCAP + env vars) |
20
- | `.npmrc` | cf ssh cat | optional, written 0600 |
17
+ </div>
21
18
 
22
- Missing optional files are skipped gracefully.
19
+ ---
23
20
 
24
- ## Installation
21
+ ## âœĻ Features
22
+
23
+ - ðŸ“Ķ **Selective artifact export** — default exports everything, or pick exactly what you need with `--file`
24
+ - 🌍 **Remote root support** — specify `--remote-root` (or "root url") to locate files when they are not at the standard `/home/vcap/app`
25
+ - 🔄 **Synthesized `default-env.json`** — built from live `cf curl /v3/apps/.../env` (full VCAP_SERVICES + env vars)
26
+ - ðŸ›Ąïļ **Best-effort for optional files** — missing files (package.json, locks, .cdsrc.json, .npmrc) are skipped gracefully
27
+ - 🧰 **CLI + typed library** — use from terminal or Node.js/TypeScript with full types
28
+ - 🔐 **Secure by default** — sensitive files (`default-env.json`, `.npmrc`) written with `0600` permissions
29
+ - ðŸŠķ **Lightweight** — only depends on `commander` + reuses `@saptools/cf-files`
30
+
31
+ ---
32
+
33
+ ## ðŸ“Ķ Install
25
34
 
26
35
  ```bash
36
+ # Global CLI
27
37
  npm install -g @saptools/cf-export
28
- # or
29
- pnpm add -g @saptools/cf-export
38
+
39
+ # Or as a library
40
+ npm install @saptools/cf-export
41
+ # pnpm add @saptools/cf-export
42
+ ```
43
+
44
+ > [!NOTE]
45
+ > Requires **Node.js â‰Ĩ 20** and the official **`cf` CLI** on `PATH`.
46
+
47
+ ---
48
+
49
+ ## 🚀 Quick Start
50
+
51
+ ```bash
52
+ # Export credentials (used only during the operation)
53
+ export SAP_EMAIL="you@company.com"
54
+ export SAP_PASSWORD="your-sap-password"
55
+
56
+ # (Recommended) Set your CF target once — then you can skip region/org/space
57
+ cf target -o my-org -s dev
58
+
59
+ # Export all artifacts — region/org/space are auto-detected from `cf target`!
60
+ cf-export -a my-cap-app --out ./exported
61
+
62
+ # You can still pass them explicitly when needed
63
+ cf-export -r ap10 -o my-org -s dev -a my-cap-app --out ./exported
64
+
65
+ # Export with a custom remote root
66
+ cf-export -a my-cap-app \
67
+ --remote-root /home/vcap/app/srv \
68
+ --out ./exported
69
+
70
+ # Export only specific files
71
+ cf-export -a my-cap-app \
72
+ --file package.json --file pnpm-lock.yaml --file default-env.json
30
73
  ```
31
74
 
32
- ## Requirements
75
+ After export you will have the requested files locally, ready for local CAP development or attaching to tickets.
76
+
77
+ ---
78
+
79
+ ## 🧰 CLI
33
80
 
34
- - Node.js >= 20
35
- - `cf` CLI installed and in PATH
36
- - `SAP_EMAIL` and `SAP_PASSWORD` environment variables (for `cf auth`)
81
+ The default (and only) command is `export`.
37
82
 
38
- ## CLI
83
+ ```bash
84
+ cf-export [options]
85
+ ```
39
86
 
40
- Default command is `export`.
87
+ ### Common examples
41
88
 
42
- ### Export everything (default)
89
+ **Export everything (recommended default)**
43
90
 
44
91
  ```bash
45
- saptools-cf-export \
92
+ cf-export \
46
93
  -r ap10 \
47
94
  -o my-org \
48
95
  -s dev \
@@ -50,23 +97,48 @@ saptools-cf-export \
50
97
  --out ./exported-artifacts
51
98
  ```
52
99
 
53
- ### Export with custom remote root (the "root url")
100
+ **With custom remote root**
54
101
 
55
102
  ```bash
56
- saptools-cf-export -r ap10 -o my-org -s dev -a my-cap-app \
57
- --remote-root /home/vcap/app/srv \
103
+ cf-export -r ap10 -o my-org -s dev -a my-cap-app \
104
+ --remote-root /home/vcap/app \
58
105
  --out ./out
59
106
  ```
60
107
 
61
- ### Export only specific files
108
+ **Selective export**
62
109
 
63
110
  ```bash
64
- saptools-cf-export ... --file package.json --file pnpm-lock.yaml --file default-env.json
111
+ cf-export ... --file package.json --file default-env.json
65
112
  ```
66
113
 
67
- Valid names: `package.json`, `package-lock.json`, `pnpm-lock.yaml`, `.cdsrc.json`, `default-env.json`, `.npmrc`.
114
+ ### Options
115
+
116
+ Region/org/space flags are **optional**. They are auto-detected from your current `cf target` (recommended: run `cf target -o ORG -s SPACE` first).
117
+
118
+ | Flag | Description | Required |
119
+ |-----------------------|-----------------------------------------------------------------------------|----------|
120
+ | `-r, --region <key>` | CF region key (e.g. `ap10`, `eu10`). Auto-detected from current `cf target` | No |
121
+ | `-o, --org <name>` | CF org name. Auto-detected from current `cf target` | No |
122
+ | `-s, --space <name>` | CF space name. Auto-detected from current `cf target` | No |
123
+ | `-a, --app <name>` | CF app name | Yes |
124
+ | `--out <dir>` | Output directory (default: current working directory) | No |
125
+ | `--remote-root <path>`| Hint for the base directory inside the container (the "root url") | No |
126
+ | `--file <name>` | Artifact to export (repeatable). Omit to export all | No |
127
+ | `--all` | Explicitly request all supported artifacts (default behavior) | No |
128
+
129
+ **Supported artifact names** (use with `--file`):
130
+ - `package.json`
131
+ - `package-lock.json`
132
+ - `pnpm-lock.yaml`
133
+ - `.cdsrc.json`
134
+ - `default-env.json`
135
+ - `.npmrc`
136
+
137
+ Missing optional files are skipped (only `default-env.json` failures when explicitly selected will surface clearly).
68
138
 
69
- ## Programmatic usage
139
+ ---
140
+
141
+ ## 🧑‍ðŸ’ŧ Programmatic Usage
70
142
 
71
143
  ```ts
72
144
  import { exportArtifacts, formatExportCompletionMessage } from "@saptools/cf-export";
@@ -79,41 +151,86 @@ const result = await exportArtifacts({
79
151
  app: "my-cap-app",
80
152
  },
81
153
  outDir: "./export-dir",
82
- remoteRoot: "/home/vcap/app", // optional
154
+ remoteRoot: "/home/vcap/app", // optional "root url"
83
155
  // artifacts: ["default-env.json", "pnpm-lock.yaml"], // optional subset
84
156
  });
85
157
 
86
- console.log(formatExportCompletionMessage("my-cap-app", result.writtenFiles, result.skipped));
158
+ console.log(
159
+ formatExportCompletionMessage(
160
+ "my-cap-app",
161
+ result.writtenFiles,
162
+ result.skipped
163
+ )
164
+ );
87
165
  ```
88
166
 
167
+ **Exported types & helpers** (see `src/index.ts` for full list):
168
+ - `exportArtifacts(options)`
169
+ - `formatExportCompletionMessage(appName, written, skipped)`
170
+ - `CfTarget`, `ArtifactName`, `ExportArtifactsOptions`, etc.
171
+ - Low-level: `fetchDefaultEnvJson`, `fetchRemoteTextFile`, `buildRemoteFilePaths`, `openCfSession`, etc.
172
+
173
+ ---
174
+
89
175
  ## Environment variables
90
176
 
91
- - `SAP_EMAIL`, `SAP_PASSWORD` — required for authentication
92
- - `CF_EXPORT_CF_HOME` — reuse an existing `CF_HOME` directory instead of creating a temporary one
93
- - `CF_EXPORT_CF_BIN` — override the `cf` binary (mainly for testing)
177
+ | Variable | Purpose |
178
+ |----------------------|----------------------------------------------------------------------|
179
+ | `SAP_EMAIL` | SAP SSO email (required for `cf auth`) |
180
+ | `SAP_PASSWORD` | SAP SSO password |
181
+ | `CF_EXPORT_CF_HOME` | Reuse an existing `CF_HOME` (advanced) |
182
+ | `CF_EXPORT_CF_BIN` | Override the `cf` binary path (mainly for testing / fake-cf) |
183
+
184
+ ---
94
185
 
95
186
  ## How remote root works
96
187
 
97
- When `--remote-root` (or `remoteRoot`) is supplied, that prefix is tried first:
188
+ When `--remote-root` is provided, candidate paths are tried in this order:
189
+
190
+ 1. `${remoteRoot}/<filename>`
191
+ 2. `/home/vcap/app/<filename>`
192
+ 3. `<filename>` (relative, last resort)
98
193
 
99
- 1. `${remoteRoot}/<file>`
100
- 2. `/home/vcap/app/<file>`
101
- 3. `<file>` (relative)
194
+ This matches the strategy used by the "Export" feature in the SAP Tools VS Code extension.
102
195
 
103
- This matches the resolution strategy used by the SAP Tools VS Code "Export" button.
196
+ ---
104
197
 
105
198
  ## Security
106
199
 
107
- - `default-env.json` and `.npmrc` are written with mode `0600`.
108
- - Temporary `CF_HOME` directories are cleaned up after use.
109
- - Credentials are never logged.
200
+ - `default-env.json` and `.npmrc` are always written with mode `0600`.
201
+ - Every operation uses an isolated temporary `CF_HOME` (unless you explicitly override via env).
202
+ - Credentials are never logged or written to disk by this tool.
203
+ - Treat any exported `default-env.json` as a secret.
110
204
 
111
- ## Development (inside monorepo)
205
+ ---
206
+
207
+ ## 🛠ïļ Development (inside monorepo)
112
208
 
113
209
  ```bash
210
+ pnpm install
114
211
  pnpm --filter @saptools/cf-export build
115
212
  pnpm --filter @saptools/cf-export typecheck
116
213
  pnpm --filter @saptools/cf-export lint
117
214
  pnpm --filter @saptools/cf-export test:unit
118
215
  pnpm --filter @saptools/cf-export test:e2e:fake
119
216
  ```
217
+
218
+ The fake-backed e2e tests do not require real SAP credentials.
219
+
220
+ ---
221
+
222
+ ## 🌐 Related packages
223
+
224
+ - ðŸ“Ĩ [`@saptools/cf-files`](https://www.npmjs.com/package/@saptools/cf-files) — download files & generate `default-env.json` from CF
225
+ - 🔄 [`@saptools/cf-sync`](https://www.npmjs.com/package/@saptools/cf-sync) — full CF topology + HANA binding sync
226
+ - 🧰 [Full saptools monorepo](https://github.com/dongitran/saptools)
227
+
228
+ ---
229
+
230
+ ## 📄 License
231
+
232
+ MIT ÂĐ Dong Tran
233
+
234
+ ---
235
+
236
+ Made to make SAP BTP CF development less painful âœĻ
package/dist/index.js CHANGED
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saptools/cf-export",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Export CAP/CF project artifacts (package.json, lockfiles, .cdsrc.json, default-env.json, .npmrc) from running SAP BTP Cloud Foundry apps",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -8,7 +8,7 @@
8
8
  "registry": "https://registry.npmjs.org/"
9
9
  },
10
10
  "bin": {
11
- "saptools-cf-export": "dist/cli.js"
11
+ "cf-export": "dist/cli.js"
12
12
  },
13
13
  "main": "./dist/index.js",
14
14
  "types": "./dist/index.d.ts",
@@ -24,14 +24,6 @@
24
24
  "engines": {
25
25
  "node": ">=20.0.0"
26
26
  },
27
- "scripts": {
28
- "build": "tsup",
29
- "typecheck": "tsc --noEmit",
30
- "lint": "eslint src tests --ignore-pattern tests/e2e/fixtures/fake-cf.mjs",
31
- "test:unit": "vitest run --coverage",
32
- "test:e2e": "playwright test",
33
- "test:e2e:fake": "playwright test tests/e2e/cf-export.e2e.ts"
34
- },
35
27
  "keywords": [
36
28
  "sap",
37
29
  "cloud-foundry",
@@ -55,6 +47,7 @@
55
47
  },
56
48
  "dependencies": {
57
49
  "@saptools/cf-files": "^0.3.3",
50
+ "@saptools/cf-sync": "^0.4.13",
58
51
  "commander": "^13.0.0"
59
52
  },
60
53
  "devDependencies": {
@@ -62,5 +55,13 @@
62
55
  "@vitest/coverage-v8": "^3.0.0",
63
56
  "tsup": "^8.3.0",
64
57
  "vitest": "^3.0.0"
58
+ },
59
+ "scripts": {
60
+ "build": "tsup",
61
+ "typecheck": "tsc --noEmit",
62
+ "lint": "eslint src tests --ignore-pattern tests/e2e/fixtures/fake-cf.mjs",
63
+ "test:unit": "vitest run --coverage",
64
+ "test:e2e": "playwright test",
65
+ "test:e2e:fake": "playwright test tests/e2e/cf-export.e2e.ts"
65
66
  }
66
- }
67
+ }