Skip to content

Commit

Permalink
feat: Manage repo with new API. Add semantic-release support
Browse files Browse the repository at this point in the history
  • Loading branch information
Romain Lenzotti committed Jun 6, 2020
1 parent 1ae7a3a commit 1d854ac
Show file tree
Hide file tree
Showing 62 changed files with 8,924 additions and 851 deletions.
19 changes: 19 additions & 0 deletions .gflowrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"flow": "gflow",
"remote": "origin",
"develop": "master",
"production": "master",
"ignores": [],
"syncAfterFinish": false,
"postFinish": "",
"skipTest": false,
"charReplacement": "-",
"charBranchNameSeparator": "-",
"branchTypes": {
"feat": "feat",
"fix": "fix",
"chore": "chore",
"docs": "docs"
},
"refs": {}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ node_modules
.npmrc
.vscode
/.nyc_output/
dist

# Typings
typings/
Expand Down
11 changes: 11 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
language: node_js
cache: yarn

node_js:
- '12'

script: yarn test && yarn release

branches:
except:
- /^v\d+\.\d+\.\d+$/
15 changes: 15 additions & 0 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"npmClient": "yarn",
"useWorkspaces": true,
"packages": [
"packages/*"
],
"version": "1.3.3",
"command": {
"bootstrap": {
"npmClientArgs": [
"--no-package-lock"
]
}
}
}
33 changes: 19 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
{
"name": "@tsed/monorepo-utils",
"name": "@tsed/root",
"version": "1.3.3",
"description": "Mono repo utils",
"main": "src/index.js",
"scripts": {},
"private": true,
"scripts": {
"test": "exit 0",
"build": "node packages/monorepo/bin/monorepo-publish.js",
"release": "semantic-release",
"release:dryRun": "semantic-release --dry-run"
},
"repository": {
"type": "git",
"url": "https://github.com/TypedProject/tsed-monorepo-utils.git"
Expand All @@ -16,17 +21,17 @@
},
"homepage": "http://tsed.io/",
"dependencies": {
"chalk": "3.0.0",
"execa": "4.0.0",
"fancy-log": "1.3.3",
"fs-extra": "9.0.0",
"globby": "11.0.0",
"normalize-path": "3.0.0",
"read-package-json": "2.1.1",
"semver": "latest"
"lerna": "3.22.0"
},
"devDependencies": {
"semantic-release": "17.0.8"
},
"workspaces": {
"packages": [
"packages/*"
]
},
"devDependencies": {},
"directories": {
"src": "src"
"monorepo": {
"npmAccess": "public"
}
}
Empty file added packages/monorepo/.npmignore
Empty file.
10 changes: 10 additions & 0 deletions packages/monorepo/bin/monorepo-build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env node
const commander = require('commander')
const { commands, runCommand } = require('../src')

commander
.usage('monorepo build [options]')
.option('-v, --verbose', 'Enable verbose log', (v, t) => t + 1, 0)
.parse(process.argv)

runCommand(commands.BuildCmd, commander)
11 changes: 11 additions & 0 deletions packages/monorepo/bin/monorepo-publish.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env node
const commander = require('commander')
const { commands, runCommand } = require('../src')

commander
.usage('monorepo publish [options]')
.option('-v, --verbose', 'Enable verbose log', (v, t) => t + 1, 0)
.option('-d, --dry-run', 'Run publish in dryRun mode', (v, t) => t + 1, 0)
.parse(process.argv)

runCommand(commands.PublishCmd, commander)
17 changes: 17 additions & 0 deletions packages/monorepo/bin/monorepo-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env node
const commander = require('commander')
const { commands, runCommand } = require('../src')

commander
.usage('monorepo version <version>')
.arguments('<version>')
.option('-v, --verbose', 'Enable verbose log', (v, t) => t + 1, 0)
.action((version) => {
runCommand(commands.VersionCmd, {
version,
verbose: !!commander.verbose
})
})
.parse(process.argv)


11 changes: 11 additions & 0 deletions packages/monorepo/bin/monorepo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env node

const commander = require('commander')
const cliPkg = require('../../../package.json')

commander
.version(cliPkg.version)
.command('build', 'Build packages')
.command('publish', 'Publish packages')
.command('publish', 'Publish packages')
.parse(process.argv)
45 changes: 45 additions & 0 deletions packages/monorepo/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"name": "@tsed/monorepo-utils",
"version": "1.3.3",
"description": "Mono repo utils",
"private": false,
"main": "./src/index.js",
"repository": {
"type": "git",
"url": "https://github.com/TypedProject/tsed-monorepo-utils.git"
},
"keywords": [],
"author": "Romain Lenzotti",
"license": "MIT",
"bugs": {
"url": "https://github.com/TypedProject/tsed-monorepo-utils/issues"
},
"homepage": "http://tsed.io/",
"dependencies": {
"axios": "0.19.2",
"listr": "0.14.3",
"figures": "3.2.0",
"inquirer": "7.1.0",
"commander": "5.1.0",
"lodash": "4.17.15",
"chalk": "3.0.0",
"esm": "3.2.25",
"execa": "4.0.0",
"fancy-log": "1.3.3",
"fs-extra": "9.0.0",
"globby": "11.0.0",
"has-yarn": "^2.1.0",
"normalize-path": "3.0.0",
"read-package-json": "2.1.1",
"semver": "7.3.2"
},
"directories": {
"src": "./src",
"bin": "./bin"
},
"bin": {
"monorepo": "./bin/monorepo.js"
},
"devDependencies": {},
"peerDependencies": {}
}
61 changes: 61 additions & 0 deletions packages/monorepo/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# @tsed/monorepo-utils

A tool to build and publish packages (Typescript or Javascript) on npm for projects based on
mono repository (lerna).

## Installation

Run:
```bash
npm install --save-dev @tsed/monorepo-utils
```

### Configuration without Semantic-release

Add these tasks to your package.json:

```
{
"scripts": {
"test": "",
"version:patch": "monorepo version patch", // update version
"version:minor": "monorepo version minor",
"version:major": "monorepo version major",
"build": "monorepo build", // build packages
"test:e2e: "",
"publish": "monorepo publish" // publish on NPM
}
}
```

### Configuration with Semantic-release

MonoRepoUtils is also compatible with semantic-release.

Install semantic-release and add repo.config.js file and add these lines:

```javascript
module.exports = {
branch: 'master',
verifyConditions: ['@semantic-release/github', '@semantic-release/npm', '@tsed/monorepo-utils/semantic-release'],
analyzeCommits: ['@semantic-release/commit-analyzer'],
verifyRelease: [],
generateNotes: ['@semantic-release/release-notes-generator'],
prepare: ['@semantic-release/npm', '@tsed/monorepo-utils/semantic-release'],
publish: ['@tsed/monorepo-utils/semantic-release', '@semantic-release/github'],
success: ['@semantic-release/github', '@tsed/monorepo-utils/semantic-release'],
fail: ['@semantic-release/github'],
npmPublish: false
}
```

Add these tasks to your package.json:

```
{
"scripts": {
"build": "monorepo build", // Will be called automatically semantic-release
"release": "semantic-release"
}
}
```
34 changes: 34 additions & 0 deletions packages/monorepo/semantic-release.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const { MonoRepo } = require('./src')

let monoRepo

module.exports = {
async verifyConditions (pluginConfig, context) {
monoRepo = new MonoRepo({
...pluginConfig,
rootDir: context.cwd
})

await monoRepo.configureWorkspace({ branchName: context.branch.name })
},

async prepare (pluginConfig, context) {
const {
nextRelease: { version }
} = context

await monoRepo.newVersion({ version })
await monoRepo.buildWorkspace()
await monoRepo.commitChanges({ version })
},

async publish (pluginConfig) {
return monoRepo.publish({ dryRun: pluginConfig.dryRun })
},

async success (pluginConfig) {
if (!pluginConfig.dryRun) {
return monoRepo.syncRepository()
}
}
}
Loading

0 comments on commit 1d854ac

Please sign in to comment.