sfdx-predeploy-hook-org-env 1.0.5 → 1.0.7

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 CHANGED
@@ -1,12 +1,6 @@
1
1
  # sfdx-predeploy-hook-org-env
2
2
 
3
- > sfdx predeploy hook to export target org details as environment variables
4
-
5
- > [!IMPORTANT]
6
- >
7
- > This plugin currently only works with `sfdx force:source:push` and `sfdx force:source:deploy`.
8
- >
9
- > The `sf project deploy start` command does not (yet) emit the `predeploy` hook.
3
+ > sf predeploy hook to export target org details as environment variables
10
4
 
11
5
  ## Use Case
12
6
 
@@ -34,8 +28,8 @@ Let's assume that for a Scratch Org we create, we simply want to make the defaul
34
28
  So in this example, we'll set the environment variable `ORG_USERNAME`, but first we need to get the default scratch org username from the org:
35
29
 
36
30
  ```console
37
- export ORG_USERNAME="$(node -pe 'JSON.parse(fs.readFileSync(0, "utf8")).result.username' < <(sfdx force:org:display -u my-target-org --json))"
38
- sfdx force source deploy -p "force-app/main/default/portals/Customer Portal.portal-meta.xml" -u my-target-org
31
+ export ORG_USERNAME="$(node -pe 'JSON.parse(fs.readFileSync(0, "utf8")).result.username' < <(sf org display --target-org my-target-org --json))"
32
+ sf project deploy start --source-dir "force-app/main/default/portals/Customer Portal.portal-meta.xml" --target-org my-target-org
39
33
  ```
40
34
 
41
35
  Although this works just fine, we need to remember to set this environment variable before deploying or pushing.
@@ -44,17 +38,17 @@ Although this works just fine, we need to remember to set this environment varia
44
38
  >
45
39
  > For common things like username, email address, org id, it would be handy to have these environment variables with target specific values built-in.
46
40
  >
47
- > And this is exactly what this sfdx plugin does!
41
+ > And this is exactly what this sf plugin does!
48
42
 
49
43
  ## Installation
50
44
 
51
45
  ```console
52
- sfdx plugins install sfdx-predeploy-hook-org-env
46
+ sf plugins install sfdx-predeploy-hook-org-env
53
47
  ```
54
48
 
55
49
  ## Usage
56
50
 
57
- Once you've installed this sfdx plugin, you can immediately use the following environment variables mentioned for the Metadata String Replacements:
51
+ Once you've installed this sf plugin, you can immediately use the following environment variables mentioned for the Metadata String Replacements:
58
52
 
59
53
  | Environment Variable | Description | Example |
60
54
  | ---------------------------------- | --------------------------------------- | -------------------- |
@@ -98,16 +92,16 @@ Make sure your `sfdx-project.json` contains some `replacements` using one of the
98
92
  "replaceWithEnv": "SFDX_TARGET_ORG_USER_EMAIL"
99
93
  }
100
94
  ],
101
- "sourceApiVersion": "57.0"
95
+ "sourceApiVersion": "62.0"
102
96
  }
103
97
  ```
104
98
 
105
- Now you can run `sfdx force source push` or `sfdx force source deploy` and the Metadata replacement will automatically use the dynamically generated environment variables for the given target org:
99
+ Now you can run `sf project deploy start` and the Metadata replacement will automatically use the dynamically generated environment variables for the given target org:
106
100
 
107
101
  ```console
108
- sfdx force source deploy -p "Portal:Customer Portal" -u my-target-org1
109
- sfdx force source deploy -p "Portal:Customer Portal" -u my-target-org2
110
- sfdx force source deploy -p "Portal:Customer Portal" -u my-target-org3
102
+ sf project deploy start -m "Portal:Customer Portal" --target-org my-target-org1
103
+ sf project deploy start -m "Portal:Customer Portal" --target-org my-target-org2
104
+ sf project deploy start -m "Portal:Customer Portal" --target-org my-target-org3
111
105
  ```
112
106
 
113
107
  ## Debugging
@@ -119,27 +113,27 @@ To preview the environment variables, set the environment variable `DEBUG` to `*
119
113
  MacOS/Linux:
120
114
 
121
115
  ```console
122
- $ DEBUG="*:sfdx-predeploy-hook-org-env:*" sfdx force source deploy --checkonly -u mytargetorg -p force-app
116
+ $ DEBUG="*:sfdx-predeploy-hook-org-env:*" sf project deploy start --source-dir force-app --dry-run --target-org mytargetorg
123
117
  ```
124
118
 
125
119
  Windows PowerShell:
126
120
 
127
121
  ```powershell
128
122
  $env:DEBUG="*:sfdx-predeploy-hook-org-env:*"
129
- sfdx force source deploy --checkonly -u mytargetorg -p force-app
123
+ sf project deploy start --source-dir force-app --dry-run --target-org mytargetorg
130
124
  ```
131
125
 
132
126
  This will output something like:
133
127
 
134
128
  ```
135
129
  ...
136
- sfdx:sfdx-predeploy-hook-org-env:hooks:predeploy Setting environment variables for target org +2s
137
- sfdx:sfdx-predeploy-hook-org-env:hooks:predeploy SFDX_TARGET_ORG_ID="00D7g0000006RKmEAM"
138
- sfdx:sfdx-predeploy-hook-org-env:hooks:predeploy SFDX_TARGET_ORG_USERNAME="john.doe@example.com"
139
- sfdx:sfdx-predeploy-hook-org-env:hooks:predeploy SFDX_TARGET_ORG_USER_ID="0058F000002RfcKQAS"
140
- sfdx:sfdx-predeploy-hook-org-env:hooks:predeploy SFDX_TARGET_ORG_USER_EMAIL="john.doe@gmail.com"
141
- sfdx:sfdx-predeploy-hook-org-env:hooks:predeploy SFDX_TARGET_ORG_USER_FIRSTNAME="John"
142
- sfdx:sfdx-predeploy-hook-org-env:hooks:predeploy SFDX_TARGET_ORG_USER_LASTNAME="Doe"
143
- sfdx:sfdx-predeploy-hook-org-env:hooks:predeploy SFDX_TARGET_ORG_USER_DISPLAYNAME="John Doe" +0ms
130
+ sf:oclif:sfdx-predeploy-hook-org-env:hooks:prerun Setting environment variables for target org
131
+ sf:oclif:sfdx-predeploy-hook-org-env:hooks:prerun SFDX_TARGET_ORG_ID="00D7g0000006RKmEAM"
132
+ sf:oclif:sfdx-predeploy-hook-org-env:hooks:prerun SFDX_TARGET_ORG_USERNAME="john.doe@example.com"
133
+ sf:oclif:sfdx-predeploy-hook-org-env:hooks:prerun SFDX_TARGET_ORG_USER_ID="0058F000002RfcKQAS"
134
+ sf:oclif:sfdx-predeploy-hook-org-env:hooks:prerun SFDX_TARGET_ORG_USER_EMAIL="john.doe@gmail.com"
135
+ sf:oclif:sfdx-predeploy-hook-org-env:hooks:prerun SFDX_TARGET_ORG_USER_FIRSTNAME="John"
136
+ sf:oclif:sfdx-predeploy-hook-org-env:hooks:prerun SFDX_TARGET_ORG_USER_LASTNAME="Doe"
137
+ sf:oclif:sfdx-predeploy-hook-org-env:hooks:prerun SFDX_TARGET_ORG_USER_DISPLAYNAME="John Doe"
144
138
  ...
145
139
  ```
@@ -1,4 +1,4 @@
1
1
  {
2
- "version": "0.0.0-development",
3
- "commands": {}
2
+ "commands": {},
3
+ "version": "0.0.0-development"
4
4
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "sfdx-predeploy-hook-org-env",
3
- "version": "1.0.5",
4
- "description": "sfdx predeploy hook to export target org details as environment variables",
3
+ "version": "1.0.7",
4
+ "description": "sf predeploy hook to export target org details as environment variables",
5
5
  "license": "MIT",
6
6
  "repository": "amtrack/sfdx-predeploy-hook-org-env",
7
7
  "files": [
@@ -9,13 +9,13 @@
9
9
  "/oclif.manifest.json"
10
10
  ],
11
11
  "oclif": {
12
- "bin": "sfdx",
12
+ "bin": "sf",
13
13
  "hooks": {
14
- "predeploy": "./src/hook.mjs"
14
+ "prerun": "./src/hook.mjs"
15
15
  }
16
16
  },
17
17
  "dependencies": {
18
- "@salesforce/sf-plugins-core": "12.0.9"
18
+ "@salesforce/sf-plugins-core": "12.1.1"
19
19
  },
20
20
  "scripts": {
21
21
  "test:e2e": "bash scripts/test-e2e.sh"
@@ -23,6 +23,7 @@
23
23
  "keywords": [
24
24
  "sfdx",
25
25
  "sfdx-plugin",
26
+ "sf-plugin",
26
27
  "sfdx-hook",
27
28
  "hook"
28
29
  ]
package/src/hook.mjs CHANGED
@@ -1,6 +1,15 @@
1
1
  import { getTargetOrgFromHook } from "./target-org.mjs";
2
2
 
3
+ const SUPPORTED_COMMANDS = [
4
+ "project:deploy:start",
5
+ "force:source:deploy",
6
+ "force:source:push",
7
+ ];
8
+
3
9
  export async function hook(options) {
10
+ if (!SUPPORTED_COMMANDS.includes(options?.Command?.id)) {
11
+ return;
12
+ }
4
13
  const org = await getTargetOrgFromHook(options);
5
14
  const identity = await org.getConnection().identity();
6
15
  const env = {
@@ -2,7 +2,7 @@ import { Parser } from "@oclif/core";
2
2
  import { Org } from "@salesforce/core";
3
3
 
4
4
  export async function getTargetOrgFromHook(hookOptions) {
5
- // dynamically parse the flags for the source deploy/push/delete commands
5
+ // dynamically parse the flags for the `sf project deploy start` command
6
6
  const { flags } = await Parser.parse(hookOptions.argv, hookOptions.Command);
7
7
  if (flags["target-org"] && typeof flags["target-org"] !== "string") {
8
8
  return flags["target-org"];
@@ -11,7 +11,7 @@ export async function getTargetOrgFromHook(hookOptions) {
11
11
  const org = aliasOrUsername
12
12
  ? // use the command line flag if given
13
13
  await Org.create({ aliasOrUsername })
14
- : // fallback to SFDX_DEFAULTUSERNAME environment variable or default org
14
+ : // fallback to SF_TARGET_ORG environment variable or default org
15
15
  await Org.create();
16
16
  return org;
17
17
  }