Skip to content

Commit

Permalink
feat: convert to typescript and oclif
Browse files Browse the repository at this point in the history
  • Loading branch information
jayree committed Jan 22, 2020
1 parent 62805aa commit b03b4b6
Show file tree
Hide file tree
Showing 36 changed files with 3,613 additions and 1,455 deletions.
61 changes: 61 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
version: 2
jobs:
node-latest: &test
docker:
- image: node:latest
working_directory: ~/cli
steps:
- checkout
- restore_cache: &restore_cache
keys:
- v1-npm-{{checksum ".circleci/config.yml"}}-{{checksum "yarn.lock"}}
- v1-npm-{{checksum ".circleci/config.yml"}}
- run:
name: Install dependencies
command: yarn
- run: ./bin/run --version
- run: ./bin/run --help
- run:
name: Testing
command: yarn test
- run:
name: Submitting code coverage to codecov
command: |
./node_modules/.bin/nyc report --reporter text-lcov > coverage.lcov
curl -s https://codecov.io/bash | bash
node-12:
<<: *test
docker:
- image: node:12
node-10:
<<: *test
docker:
- image: node:10
cache:
<<: *test
steps:
- checkout
- run:
name: Install dependencies
command: yarn
- save_cache:
key: v1-npm-{{checksum ".circleci/config.yml"}}-{{checksum "yarn.lock"}}
paths:
- ~/cli/node_modules
- /usr/local/share/.cache/yarn
- /usr/local/share/.config/yarn

workflows:
version: 2
'sfdx-md-merge-driver':
jobs:
- node-latest
- node-12
- node-10
- cache:
filters:
tags:
only: /^v.*/
branches:
ignore: /.*/
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
root = true

[*]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/lib
29 changes: 15 additions & 14 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
{
"env": {
"es6": true,
"node": true
},
"extends": ["standard"],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"extends": ["oclif", "oclif-typescript"],
"rules": {
"space-before-function-paren": "off",
"no-console": "off"
"indent": "off",
"operator-linebreak": "off",
"node/no-missing-require": [
"error",
{
"tryExtensions": [".ts", ".js"]
}
],
"node/no-missing-import": [
"error",
{
"tryExtensions": [".ts", ".js"]
}
]
}
}
12 changes: 9 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
/node_modules
*-debug.log
*-error.log
/.nyc_output
/test/cache
/dist
/lib
/package-lock.json
/tmp
/node_modules
/sfdx-md-merge-driver.1
.vscode
/.vscode
/coverage
4 changes: 4 additions & 0 deletions .lintstagedrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
'*.ts': ['prettier --write', 'git add'],
'**/*.ts?(x)': () => 'tsc -p tsconfig.json --noEmit',
}
4 changes: 4 additions & 0 deletions .nycrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "@istanbuljs/nyc-config-typescript",
"reporter": ["html","text"]
}
5 changes: 3 additions & 2 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"trailingComma": "none",
"semi": false,
"singleQuote": true,
"semi": false
"trailingComma": "all",
"bracketSpacing": false
}
14 changes: 14 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
language: node_js
node_js:
- node

cache: yarn

script:
- ./bin/run --version
- ./bin/run --help
- yarn run test

after_success:
- ./node_modules/.bin/nyc report --reporter text-lcov > coverage.lcov
- bash < (curl -s https://codecov.io/bash)
170 changes: 114 additions & 56 deletions README.md
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
<!-- [![npm](https://img.shields.io/jayree/v/sfdx-md-merge-driver.svg)](https://npm.im/sfdx-md-merge-driver) [![license](https://img.shields.io/jayree/l/sfdx-md-merge-driver.svg)](https://npm.im/sfdx-md-merge-driver) [![Travis](https://img.shields.io/travis/jayree/sfdx-md-merge-driver.svg)](https://travis-ci.org/jayree/sfdx-md-merge-driver) [![AppVeyor](https://ci.appveyor.com/api/projects/status/github/jayree/sfdx-md-merge-driver?svg=true)](https://ci.appveyor.com/project/jayree/sfdx-md-merge-driver) [![Coverage Status](https://coveralls.io/repos/github/jayree/sfdx-md-merge-driver/badge.svg?branch=latest)](https://coveralls.io/github/jayree/sfdx-md-merge-driver?branch=latest) -->
# sfdx-md-merge-driver

# sfdx-md-merge-driver(1) -- Salesforce Metadata Specific Git Merge Driver
[![oclif](https://img.shields.io/badge/cli-oclif-brightgreen.svg)](https://oclif.io)
[![Version](https://img.shields.io/npm/v/sfdx-md-merge-driver.svg)](https://npmjs.org/package/sfdx-md-merge-driver)
[![CircleCI](https://circleci.com/gh/jayree/sfdx-md-merge-driver/tree/master.svg?style=shield)](https://circleci.com/gh/jayree/sfdx-md-merge-driver/tree/master)
[![Appveyor CI](https://ci.appveyor.com/api/projects/status/github/jayree/sfdx-md-merge-driver?branch=master&svg=true)](https://ci.appveyor.com/project/jayree/sfdx-md-merge-driver/branch/master)
[![Codecov](https://codecov.io/gh/jayree/sfdx-md-merge-driver/branch/master/graph/badge.svg)](https://codecov.io/gh/jayree/sfdx-md-merge-driver)
[![Downloads/week](https://img.shields.io/npm/dw/sfdx-md-merge-driver.svg)](https://npmjs.org/package/sfdx-md-merge-driver)
[![License](https://img.shields.io/npm/l/sfdx-md-merge-driver.svg)](https://github.com/jayree/sfdx-md-merge-driver/blob/master/package.json)

This is a git merge driver specific for Salesforce.com Metadata (Profiles, Permission Sets, Custom Labels).

The merge is done based on the nodes of the files, checking if any node changed in both the local copy and the branch we're trying to merge, and merging automatically whenever there is no conflict.
The merge is done based on the nodes of the files, checking if any node changed in both the local copy and the branch we're trying to merge, and automatically merging whenever there is no conflict.

In the case of a node being modified in our local workspace and in the branch we try to merge both nodes are marked with a conflict that specifies from which change the node comes so it makes it easier to identify and resolve the conflict.
In the case of a node being modified in our local workspace and in the branch we try to merge, both nodes are marked with a conflict that specifies from which change the node comes, so it makes it easier to identify and resolve the conflict.

### Automatic Setup (recommended):
<!-- toc -->
* [sfdx-md-merge-driver](#sfdx-md-merge-driver)
* [Automatic Setup (recommended)](#automatic-setup-recommended)
* [Install as Dependency](#install-as-dependency)
* [Uninstalling](#uninstalling)
* [Commands](#commands)
* [Author](#author)
<!-- tocstop -->

# Automatic Setup (recommended)

To start using it right away:

Expand All @@ -25,10 +40,7 @@ $ npx sfdx-md-merge-driver install

...And you're good to go!

<!-- Next time your lockfile has a conflict, it will be automatically fixed. You
don't need to do anything else. -->

### Example
## Example

```
$ npx sfdx-md-merge-driver install
Expand All @@ -40,86 +52,132 @@ Auto-merging force-app/main/default/profiles/Standard.profile-meta.xml
Automatic merge failed; fix conflicts and then commit the result.
```

### Advanced
# Install as Dependency

The following section is only for advanced configuration of the driver if you
have specific needs.
To avoid regular `npx` installs, consider installing the driver:

#### Setup Options
<!-- usage -->
```sh-session
$ npm install -g sfdx-md-merge-driver
$ sfdx-md-merge-driver COMMAND
running command...
$ sfdx-md-merge-driver (-v|--version|version)
sfdx-md-merge-driver/0.1.1 darwin-x64 node-v12.13.0
$ sfdx-md-merge-driver --help [COMMAND]
USAGE
$ sfdx-md-merge-driver COMMAND
...
```
<!-- usagestop -->

`sfdx-md-merge-driver install` supports a couple of config options:
# Uninstalling

`--driver` - string to install as the driver in the git configuration
To remove an installed merge driver, use `sfdx-md-merge-driver uninstall`:

`--driver-name` - string to use as the merge driver name in your configuration
```
$ npx sfdx-md-merge-driver uninstall [--global] [--driver-name=sfdx-md-merge-driver]
```

`--files` - list of files that will trigger this driver
**Or** remove the package:

#### Install as Dependency
```
$ npm uninstall -g sfdx-md-merge-driver
```

To avoid regular `npx` installs, consider installing the driver:
# Commands

`$ yarn [global|--dev] add sfdx-md-merge-driver`
<!-- commands -->
* [`sfdx-md-merge-driver help [COMMAND]`](#sfdx-md-merge-driver-help-command)
* [`sfdx-md-merge-driver install`](#sfdx-md-merge-driver-install)
* [`sfdx-md-merge-driver merge %O %A %B [%P]`](#sfdx-md-merge-driver-merge-o-a-b-p)
* [`sfdx-md-merge-driver uninstall`](#sfdx-md-merge-driver-uninstall)

#### Manual Setup (advanced):
## `sfdx-md-merge-driver help [COMMAND]`

`sfdx-md-merge-driver` requires two git configurations to work: a git configuration
to add the driver to git, which is by default your local `.git/config` file, and
a `gitattributes(5)` configuration, which is by default your local
`.git/info/attributes`.
display help for sfdx-md-merge-driver

If you **do not** want `sfdx-md-merge-driver` to install itself for you:
```
USAGE
$ sfdx-md-merge-driver help [COMMAND]
Add the driver to `.git/config`:
ARGUMENTS
COMMAND command to show help for
OPTIONS
--all see all commands in CLI
```
$ git config merge."sfdx-md-merge-driver".name \
"A custom merge driver for Salesforce profiles"
$ git config merge."sfdx-md-merge-driver".driver \
"npx sfdx-md-merge-driver merge %O %A %B %P"
$ git config merge."sfdx-md-merge-driver".recursive \
"binary"

_See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v2.2.3/src/commands/help.ts)_

## `sfdx-md-merge-driver install`

Set up the merge driver in the current git repository.

```
USAGE
$ sfdx-md-merge-driver install
OPTIONS
-d, --driver=driver
[default: npx sfdx-md-merge-driver merge %O %A %B %P] string to install as the driver in the git configuration
This will configure the merge driver to run merges on the metadata files.
-g, --global
install to your user-level git configuration
Add the relevant attributes to `.gitattributes` or `.git/info/attributes`:
-h, --help
show CLI help
-n, --name=name
[default: sfdx-md-merge-driver] String to use as the merge driver name in your configuration.
-t, --files=*.profile|*.profile-meta.xml|*.permissionset|*.permissionset-meta.xml|*.labels|*.labels-meta.xml
[default: *.profile,*.profile-meta.xml,*.permissionset,*.permissionset-meta.xml,*.labels,*.labels-meta.xml]
Filenames that will trigger this driver.
```
*.profile merge=sfdx-md-merge-driver
*.profile-meta.xml merge=sfdx-md-merge-driver
*.permissionset merge=sfdx-md-merge-driver
*.permissionset-meta.xml merge=sfdx-md-merge-driver
*.labels merge=sfdx-md-merge-driver
*.labels-meta.xml merge=sfdx-md-merge-driver

_See code: [src/commands/install.ts](https://github.com/jayree/sfdx-md-merge-driver/blob/v0.1.1/src/commands/install.ts)_

## `sfdx-md-merge-driver merge %O %A %B [%P]`

Check for conflicts and merge them if possible.

```
USAGE
$ sfdx-md-merge-driver merge %O %A %B [%P]
This will instruct git that all the Salesforce files should be merged using the new merge drivers.
You can also choose which metadata you want to use this driver to.
ARGUMENTS
%O ancestor’s version
%A current version
%B other branches' version
%P pathname in which the merged result will be stored
<!-- #### Configure the driver
The merge driver uses the configuration in the file `.git/scritps/sfdx-merge/conf/merge-<metadataType>-config.json` to know what nodes to merge and how to identify if the nodes are the same node and if they are equal between the branches.
OPTIONS
-h, --help show CLI help
```

If a node type is not configured there, the merge driver will choose the one in the current branch.
-->
_See code: [src/commands/merge.ts](https://github.com/jayree/sfdx-md-merge-driver/blob/v0.1.1/src/commands/merge.ts)_

#### Uninstalling
## `sfdx-md-merge-driver uninstall`

To remove an installed merge driver, use `sfdx-md-merge-driver uninstall`:
Remove a previously configured driver

```
$ npx sfdx-md-merge-driver uninstall [--global] [--driver-name=sfdx-md-merge-driver]
USAGE
$ sfdx-md-merge-driver uninstall
OPTIONS
-g, --global install to your user-level git configuration
-h, --help show CLI help
-n, --name=name [default: sfdx-md-merge-driver] String to use as the merge driver name in your configuration.
```

## AUTHOR
_See code: [src/commands/uninstall.ts](https://github.com/jayree/sfdx-md-merge-driver/blob/v0.1.1/src/commands/uninstall.ts)_
<!-- commandsstop -->

# Author

Written by [jayree](https://github.com/jayree)

Based on code from [Amguerrero's](https://github.com/amguerrero) repository [sfdc_merge](https://github.com/amguerrero/sfdc_merge) and forks from [Dhanielk](https://github.com/Dhanielk/sfdc_merge) and [KevinGossentCap](https://github.com/KevinGossentCap/sfdc_merge).

Node.js Installer framework based on code from [Zkat's](https://github.com/zkat) repository [npm-merge-driver](https://github.com/npm/npm-merge-driver)

## SEE ALSO

- `git-config(1)`
- `gitattributes(5)`
2 changes: 1 addition & 1 deletion _config.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
theme: jekyll-theme-cayman
theme: jekyll-theme-cayman
Loading

0 comments on commit b03b4b6

Please sign in to comment.