# organic-stack-upgrade

> lib for upgrading organic stem skeletons

Latest version **2.1.0** (published 2021-12-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install organic-stack-upgrade
pnpm add organic-stack-upgrade
yarn add organic-stack-upgrade
bun add organic-stack-upgrade
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.0 |
| Published | 2021-12-10 |
| First published | 2018-03-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 10 |
| Unpacked size | 24.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Boris Filipov |
| Maintainers | outbounder |

## Links

- npm: https://www.npmjs.com/package/organic-stack-upgrade
- Repository: https://github.com/node-organic/organic-stack-upgrade
- Homepage: https://github.com/node-organic/organic-stack-upgrade#readme
- Issues: https://github.com/node-organic/organic-stack-upgrade/issues
- npm.io page: https://npm.io/package/organic-stack-upgrade

## Dependencies (10)

- [async](https://npm.io/package/async.md) ^3.2.2
- [lodash](https://npm.io/package/lodash.md) ^4.17.21
- [mkdirp](https://npm.io/package/mkdirp.md) ^1.0.4
- [semver](https://npm.io/package/semver.md) ^7.3.5
- [fs-extra](https://npm.io/package/fs-extra.md) ^10.0.0
- [inquirer](https://npm.io/package/inquirer.md) ^8.2.0
- [merge-util](https://npm.io/package/merge-util.md) ^0.3.1
- [glob-stream](https://npm.io/package/glob-stream.md) ^7.0.0
- [p-iteration](https://npm.io/package/p-iteration.md) ^1.1.8
- [istextorbinary](https://npm.io/package/istextorbinary.md) ^6.0.0

## Recent versions

- 2.1.0 (latest) — 2021-12-10
- 2.0.1 — 2018-10-09
- 2.0.0 — 2018-09-30
- 1.3.0 — 2018-05-08
- 1.2.0 — 2018-04-11
- 1.1.1 — 2018-04-07
- 1.1.0 — 2018-04-06
- 1.0.1 — 2018-03-30
- 1.0.0 — 2018-03-30

## README

# organic-stack-upgrade

lib for upgrading organic stem skeletons

## StackUpgrade class

### constructor({destDir, name, version})

Constructs class instance with `destDir`, `name` and `version` properties

```
let stack = new StackUpgrade({
  destDir: process.cwd(),
  name: 'myStack',
  version: '1.0.0'
})
```

### constructor({destDir, packagejson})

Constructs class instance with `destDir` property. Fills `name` and `version` properties by reading `packagejson` as .json file

```
let stack = new StackUpgrade({
  destDir: process.cwd(),
  packagejson: __dirname + '/package.json'
})
```

### async configure({sourceDir, answers}): result_answers

Configures stack upgrade. This method does the following:

1. globs in `sourceDir` for any
placeholders such as `{{{variable-name}}}` within file contents or file/directory paths
2. uses `answers` hash to provide values for found placeholders
3. prompts the user via `inquirer` to provide any missing answers to placeholders found from step 1
4. returns all placeholders with their respective answer values as `result_answers` hash

```
let stack = new StackUpgrade(...)
let answers = await stack.configure({
  sourceDir: path.join(__dirname, 'seedTemplateFolder')
})

// `answers` will be a hash with provided answers to 
// any placeholders been found within `seedTemplateFolder`
```

### async merge({sourceDir, answers})

Merges stack upgrade into `destDir`. This method does the following:

1. globs in `sourceDir` for all files and folders and replaces any placeholders such as `{{{variable-name}}}` in all
file/directory path or file contents
2. writes resulted files and directories do the `destDir` by using the following merge strategies:
  * for `.json` files it does deep object merge and overrides existing keys
  * for `.gitignore` files it reconstructs the file by appending to the using existing file the content provided from `sourceDir`. It eliminates duplicated lines
  * for `gitignore` files it outputs `.gitignore` following the same rules as previous point
  * for all other files it just overrides

```
let stack = new StackUpgrade({
  destDir: ...,
  ...
})
await stack.merge({
  sourceDir: path.join(__dirname, 'seedTemplateFolder'),
  answers: {...}
})

// will merge `seedTemplateFolder` into `destDir`
// replacing any placeholders been found with provided `answers` hash
```

### async updateJSON()

Updates `<destDir>/package.json` by adding stack upgrade `name` and `version` within `stackUpgrades` key. This is useful way to record that given stack upgrade by name/version has been applied to the `destDir`

```
let stack = new StackUpgrade({
  destDir: process.cwd(),
  name: "my-upgrade",
  version: "1.0.1"
})
stack.updateJSON()

// will create or append the following to destDir/package.json
/*
{
  "stackUpgrades": {
    "my-upgrade": "1.0.1"
  }
}
*/
```

### async checkUpgrade(name, version): Boolean

Checks `<destDir>/package.json` for specific `stackUpgrades` key matching `name` having respective `version` compared via [compare-versions](https://www.npmjs.com/package/compare-versions)

Returns `true` when respective `version` is equal or greater than destination's

```
let stack = new StackUpgrade({
  destDir: process.cwd()
})

stack.checkUpgrade('my-upgrade', '^1.0.0') 

// returns 'true' when destDir has package.json like
/*
{
  "stackUpgrades": {
    "my-upgrade": "1.0.0"
  }
}
*/
```

### async exec(cmd)

Helper method to execute `cmd` on `destDir` and to pipe the output to `console`. Note that `destDir` is created if not exists.

```
let stack = new StackUpgrade({
  destDir: process.cwd()
})

stack.exec('echo TEST')
// will execute `echo TEST` command witin `destDir` 
// inheriting any process env variables
```

### async ensureDestDir()

Helper method to create destination directory if not found

### async ask(question, defaultValue) 

Helper method to use `inquirer` prompt and return the resulted answer

---
_Source: https://npm.io/package/organic-stack-upgrade · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
