@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.
- package/README.md +164 -47
- package/dist/index.js +0 -0
- package/package.json +12 -11
package/README.md
CHANGED
|
@@ -1,48 +1,95 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
# ðĪ `@saptools/cf-export`
|
|
4
4
|
|
|
5
|
-
|
|
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
|
-
|
|
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
|
-
|
|
9
|
+
[](https://www.npmjs.com/package/@saptools/cf-export)
|
|
10
|
+
[](./LICENSE)
|
|
11
|
+
[](https://nodejs.org)
|
|
12
|
+
[](https://packagephobia.com/result?p=@saptools/cf-export)
|
|
13
|
+
[](https://www.typescriptlang.org)
|
|
10
14
|
|
|
11
|
-
|
|
15
|
+
[Install](#-install) âĒ [Quick Start](#-quick-start) âĒ [CLI](#-cli) âĒ [API](#-programmatic-usage) âĒ [Development](#-development)
|
|
12
16
|
|
|
13
|
-
|
|
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
|
-
|
|
19
|
+
---
|
|
23
20
|
|
|
24
|
-
##
|
|
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
|
-
|
|
29
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
83
|
+
```bash
|
|
84
|
+
cf-export [options]
|
|
85
|
+
```
|
|
39
86
|
|
|
40
|
-
|
|
87
|
+
### Common examples
|
|
41
88
|
|
|
42
|
-
|
|
89
|
+
**Export everything (recommended default)**
|
|
43
90
|
|
|
44
91
|
```bash
|
|
45
|
-
|
|
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
|
-
|
|
100
|
+
**With custom remote root**
|
|
54
101
|
|
|
55
102
|
```bash
|
|
56
|
-
|
|
57
|
-
--remote-root /home/vcap/app
|
|
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
|
-
|
|
108
|
+
**Selective export**
|
|
62
109
|
|
|
63
110
|
```bash
|
|
64
|
-
|
|
111
|
+
cf-export ... --file package.json --file default-env.json
|
|
65
112
|
```
|
|
66
113
|
|
|
67
|
-
|
|
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
|
-
|
|
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",
|
|
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(
|
|
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
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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`
|
|
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
|
-
|
|
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
|
-
|
|
196
|
+
---
|
|
104
197
|
|
|
105
198
|
## Security
|
|
106
199
|
|
|
107
|
-
- `default-env.json` and `.npmrc` are written with mode `0600`.
|
|
108
|
-
-
|
|
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
|
-
|
|
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.
|
|
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
|
-
"
|
|
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
|
+
}
|