Skip to content

Commit

Permalink
Squash history
Browse files Browse the repository at this point in the history
  • Loading branch information
gdman committed Nov 26, 2020
1 parent 9280770 commit bd48247
Show file tree
Hide file tree
Showing 7 changed files with 251 additions and 141 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
/package-lock.json
/tmp
node_modules
*.tgz
oclif.manifest.json
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Andrew Goodman

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
109 changes: 66 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,58 +1,81 @@
sfdx-destruction
================

Destructive changes support for sfdx force:source:deploy
Destructive changes support for `sfdx force:source:deploy` via a predeploy hook.

At time of writing, the `sfdx force:source:deploy` command doesn't support destructive changes files out of the box. Therefore if deletions are required, either source metadata needs to be converted for use with `sfdx force:mdapi:deploy` or there'll need to be multiple deployments (with downtime, difficult rollbacks and multiple unit test cycles).

This simple plugin hooks into source deploy and drops `destructiveChangesPre.xml` and/or `destructiveChangesPost.xml` deletions manifests into the package before the deployment initiates.

[![Version](https://img.shields.io/npm/v/sfdx-destruction.svg)](https://npmjs.org/package/sfdx-destruction)
[![CircleCI](https://circleci.com/gh/gdman/sfdx-destruction/tree/master.svg?style=shield)](https://circleci.com/gh/gdman/sfdx-destruction/tree/master)
[![Appveyor CI](https://ci.appveyor.com/api/projects/status/github/gdman/sfdx-destruction?branch=master&svg=true)](https://ci.appveyor.com/project/heroku/sfdx-destruction/branch/master)
[![Codecov](https://codecov.io/gh/gdman/sfdx-destruction/branch/master/graph/badge.svg)](https://codecov.io/gh/gdman/sfdx-destruction)
[![Greenkeeper](https://badges.greenkeeper.io/gdman/sfdx-destruction.svg)](https://greenkeeper.io/)
[![Known Vulnerabilities](https://snyk.io/test/github/gdman/sfdx-destruction/badge.svg)](https://snyk.io/test/github/gdman/sfdx-destruction)
[![Downloads/week](https://img.shields.io/npm/dw/sfdx-destruction.svg)](https://npmjs.org/package/sfdx-destruction)
[![License](https://img.shields.io/npm/l/sfdx-destruction.svg)](https://github.com/gdman/sfdx-destruction/blob/master/package.json)

<!-- toc -->
* [Debugging your plugin](#debugging-your-plugin)
<!-- tocstop -->
<!-- install -->
<!-- usage -->
# Installation

```sh-session
$ npm install -g sfdx-destruction
$ sfdx COMMAND
running command...
$ sfdx (-v|--version|version)
sfdx-destruction/0.0.0 darwin-x64 node-v12.9.0
$ sfdx --help [COMMAND]
USAGE
$ sfdx COMMAND
...
$ sfdx plugins:install sfdx-destruction
```
<!-- usagestop -->
<!-- commands -->

<!-- commandsstop -->
<!-- debugging-your-plugin -->
# Debugging your plugin
We recommend using the Visual Studio Code (VS Code) IDE for your plugin development. Included in the `.vscode` directory of this plugin is a `launch.json` config file, which allows you to attach a debugger to the node process when running your commands.

To debug the `hello:org` command:
1. Start the inspector

If you linked your plugin to the sfdx cli, call your command with the `dev-suspend` switch:

# Usage

```sh-session
$ sfdx hello:org -u [email protected] --dev-suspend
$ SFDX_DESTRUCTION_ENABLE=true sfdx force:source:deploy
```

Alternatively, to call your command using the `bin/run` script, set the `NODE_OPTIONS` environment variable to `--inspect-brk` when starting the debugger:
```sh-session
$ NODE_OPTIONS=--inspect-brk bin/run hello:org -u [email protected]

# Configuration

Destructive changes functionality is disabled by default and therefore must be enabled by environment variable or in the project configuration file.

If the `SFDX_DESTRUCTION_ENABLE` environment variable is set, it will be used to determine whether to run the plugin (true or false and regardless of configuration file settings).
Else the `plugins` -> `sfdx-destruction` -> `enabledByDefault` variable in the project configuration file will be used (if set).
If neither is configured, the plugin will remain disabled.

The locations of the pre and post destructive changes files can also be specified by environment variable and/or configuration file. Environment variables take precedence over the configuration file. If neither is present, the plugin will have no effect.

Recommended usage is to use the configuration file to store the locations of the destructive changes files and the environment variable to enable at build time.

## Environment Variables

`SFDX_DESTRUCTION_ENABLE` - true or false to enable or disable the plugin

`SFDX_DESTRUCTIVE_PRE_FILE` - path to the destructive changes pre file i.e. deletions that will occur before the deployment

`SFDX_DESTRUCTIVE_POST_FILE` - path to the destructive changes post file i.e. deletions that will occur after the deployment

## Project Configuration File (sfdx-project.json)

`enabledByDefault` - true or false - will be used to determine whether the plugin should run if no environment variable is present (default: false - disabled)

`destructiveChangesPreFile` - path to the destructive changes pre file i.e. deletions that will occur before the deployment

`destructiveChangesPostFile` - path to the destructive changes post file i.e. deletions that will occur after the deployment

### Example:
```json
{
"packageDirectories": [
{
"default": true,
"path": "force-app"
}
],
"namespace": "",
"sfdcLoginUrl": "https://login.salesforce.com",
"sourceApiVersion": "50.0",
"plugins": {
"sfdx-destruction": {
"enabledByDefault": false,
"destructiveChangesPreFile": "{path-to-destructiveChangesPre.xml}",
"destructiveChangesPostFile": "{path-to-destructiveChangesPost.xml}"
}
}
}
```

2. Set some breakpoints in your command code
3. Click on the Debug icon in the Activity Bar on the side of VS Code to open up the Debug view.
4. In the upper left hand corner of VS Code, verify that the "Attach to Remote" launch configuration has been chosen.
5. Hit the green play button to the left of the "Attach to Remote" launch configuration window. The debugger should now be suspended on the first line of the program.
6. Hit the green play button at the top middle of VS Code (this play button will be to the right of the play button that you clicked in step #5).
<br><img src=".images/vscodeScreenshot.png" width="480" height="278"><br>
Congrats, you are debugging!
# Can I enable the plugin by command line argument?

No, unfortunately not.

This functionality is implemented as a hook and although it is possible to access argv, it doesn't seem to be possible to define additional arguments. Passing in an extra argument will return an error of `Unexpected argument`.
126 changes: 64 additions & 62 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,65 +1,67 @@
{
"name": "sfdx-destruction",
"description": "Destructive changes support for sfdx force:source:deploy",
"version": "0.0.0",
"author": "Andrew Goodman",
"bugs": "https://github.com/gdman/sfdx-destruction/issues",
"dependencies": {
"@oclif/command": "^1",
"@oclif/config": "^1",
"@oclif/errors": "^1",
"@salesforce/command": "^2",
"@salesforce/core": "^2",
"tslib": "^1"
},
"devDependencies": {
"@oclif/dev-cli": "^1",
"@oclif/plugin-help": "^2",
"@oclif/test": "^1",
"@salesforce/dev-config": "1.4.1",
"@types/chai": "^4",
"@types/mocha": "^5",
"@types/node": "^10",
"chai": "^4",
"globby": "^8",
"mocha": "^5",
"nyc": "^14",
"ts-node": "^8",
"tslint": "^5"
},
"engines": {
"node": ">=8.0.0"
},
"files": [
"/lib",
"/messages",
"/npm-shrinkwrap.json",
"/oclif.manifest.json"
],
"homepage": "https://github.com/gdman/sfdx-destruction",
"keywords": [
"sfdx-plugin"
],
"license": "MIT",
"oclif": {
"commands": "./lib/commands",
"bin": "sfdx",
"topics": {
"hello": {
"description": "Commands to say hello."
}
"name": "sfdx-destruction",
"description": "Destructive changes support for sfdx force:source:deploy",
"version": "1.0.0-beta.0",
"author": "Andrew Goodman",
"bugs": "https://github.com/gdman/sfdx-destruction/issues",
"dependencies": {
"@oclif/command": "^1",
"@oclif/config": "^1",
"@oclif/errors": "^1",
"@salesforce/command": "^2",
"@salesforce/core": "^2",
"tslib": "^1"
},
"devPlugins": [
"@oclif/plugin-help"
]
},
"repository": "gdman/sfdx-destruction",
"scripts": {
"lint": "tslint --project . --config tslint.json --format stylish",
"postpack": "rm -f oclif.manifest.json",
"posttest": "tslint -p test -t stylish",
"prepack": "rm -rf lib && tsc -b && oclif-dev manifest && oclif-dev readme",
"test": "nyc --extension .ts mocha --forbid-only \"test/**/*.test.ts\"",
"version": "oclif-dev readme && git add README.md"
}
"devDependencies": {
"@oclif/dev-cli": "^1",
"@oclif/plugin-help": "^2",
"@oclif/test": "^1",
"@salesforce/dev-config": "1.4.1",
"@types/chai": "^4",
"@types/mocha": "^5",
"@types/node": "^10",
"chai": "^4",
"globby": "^8",
"mocha": "^5",
"nyc": "^14",
"ts-node": "^8",
"tslint": "^5"
},
"engines": {
"node": ">=8.0.0"
},
"files": [
"/lib",
"/messages",
"/npm-shrinkwrap.json",
"/oclif.manifest.json"
],
"homepage": "https://github.com/gdman/sfdx-destruction",
"keywords": [
"sfdx-plugin", "salesforce", "sfdc", "sfdx", "plugin", "destructive", "changes", "deploy"
],
"license": "MIT",
"oclif": {
"bin": "sfdx",
"topics": {
"sfdx-destructive": {
"description": "Destructive changes support for sfdx force:source:deploy"
}
},
"hooks": {
"predeploy": "./lib/hooks/predeploy/destructive-changes"
},
"devPlugins": [
"@oclif/plugin-help"
]
},
"repository": "gdman/sfdx-destruction",
"scripts": {
"lint": "tslint --project . --config tslint.json --format stylish",
"postpack": "rm -f oclif.manifest.json",
"posttest": "tslint -p test -t stylish",
"prepack": "rm -rf lib && tsc -b && oclif-dev manifest && oclif-dev readme",
"test": "nyc --extension .ts mocha --forbid-only \"test/**/*.test.ts\"",
"version": "oclif-dev readme && git add README.md"
}
}
Loading

0 comments on commit bd48247

Please sign in to comment.