Skip to content

Commit

Permalink
feat: Support workspaces configuration from package.json (yarn/npm/mo…
Browse files Browse the repository at this point in the history
…norepo)
  • Loading branch information
Romakita committed May 19, 2021
1 parent aa04486 commit b6ac454
Show file tree
Hide file tree
Showing 69 changed files with 5,022 additions and 1,402 deletions.
5 changes: 5 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
**/node_modules
docs
examples
packages/**/{test,dist}/**/*.ts
24 changes: 24 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"extends": [
"plugin:prettier/recommended"
],
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"env": {
"node": true,
"es6": true
},
"rules": {
"no-case-declarations": "off",
"no-empty": "off",
"prefer-const": "off",
"no-fallthrough": "off"
},
"ignorePatterns": [
"**/lib/**/*.ts",
"**/test/**/*.ts",
"**/node_modules/**/*.ts"
]
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### Node template
.DS_Store
.husky
# Logs
logs
*.log
Expand Down Expand Up @@ -34,6 +35,7 @@ node_modules
.vscode
/.nyc_output/
dist
lib

# Typings
typings/
Expand Down
7 changes: 7 additions & 0 deletions .lintstagedrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"packages/*/src/**/*.js": [
"prettier --write",
"eslint --fix",
"git add"
]
}
5 changes: 5 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
dist
docs
node_modules
*-lock.json
*.lock
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"printWidth": 140,
"bracketSpacing": false,
"trailingComma": "none",
"arrowParens": "always"
}
21 changes: 17 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@
"description": "Monorepo CLI and utils to deploy packages on NPM",
"private": true,
"scripts": {
"test": "exit 0",
"build": "node packages/monorepo/bin/monorepo-build.js",
"clean": "node packages/monorepo/bin/monorepo-clean workspace",
"test": "yarn test:lint",
"test:lint": "eslint '{packages,test}/**/*.js' --ext .ts",
"test:lint:fix": "eslint '{packages,test}/**/*.js' --fix",
"prettier": "prettier '{packages,test}/**/*.js' --write",
"build": "node packages/monorepo/bin/monorepo-build.js --verbose",
"publish": "node packages/monorepo/bin/monorepo-publish.js --dry-run",
"release": "semantic-release",
"release:dryRun": "semantic-release --dry-run"
"release:dryRun": "semantic-release --dry-run",
"prepare": "husky install"
},
"repository": {
"type": "git",
Expand All @@ -25,7 +30,15 @@
"lerna": "3.22.0"
},
"devDependencies": {
"semantic-release": "17.0.8"
"microbundle": "0.13.0",
"semantic-release": "17.4.3",
"eslint": "^7.10.0",
"eslint-config-prettier": "6.12.0",
"eslint-plugin-jest": "24.2.1",
"eslint-plugin-prettier": "3.3.1",
"prettier": "2.2.1",
"husky": "^6.0.0",
"lint-staged": "10.5.4"
},
"workspaces": {
"packages": [
Expand Down
12 changes: 6 additions & 6 deletions packages/monorepo/bin/monorepo-build.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env node
const commander = require('commander')
const { commands, runCommand } = require('../src')
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)
.usage("monorepo build [options]")
.option("-v, --verbose", "Enable verbose log", (v, t) => t + 1, 0)
.parse(process.argv);

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

commander
.usage('monorepo ci <type> [options]')
.arguments('<type>')
.option('-v, --verbose', 'Enable verbose log', (v, t) => t + 1, 0)
.usage("monorepo ci <type> [options]")
.arguments("<type>")
.option("-v, --verbose", "Enable verbose log", (v, t) => t + 1, 0)
.action((type) => {
runCommand(commands.CICmd, {
type,
verbose: !!commander.opts().verbose
})
});
})
.parse(process.argv)
.parse(process.argv);
14 changes: 7 additions & 7 deletions packages/monorepo/bin/monorepo-clean.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#!/usr/bin/env node
const commander = require('commander')
const { commands, runCommand } = require('../src')
const commander = require("commander");
const {commands, runCommand} = require("../src");

commander
.usage('monorepo clean <type> [options]')
.arguments('<type>')
.option('-v, --verbose', 'Enable verbose log', (v, t) => t + 1, 0)
.usage("monorepo clean <type> [options]")
.arguments("<type>")
.option("-v, --verbose", "Enable verbose log", (v, t) => t + 1, 0)
.action((type) => {
runCommand(commands.CleanCmd, {
type,
verbose: !!commander.opts().verbose
})
});
})
.parse(process.argv)
.parse(process.argv);
19 changes: 9 additions & 10 deletions packages/monorepo/bin/monorepo-publish.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
#!/usr/bin/env node
const commander = require('commander')
const { commands, runCommand } = require('../src')
const commander = require("commander");
const {commands, runCommand} = require("../src");

commander
.usage('monorepo publish <type> [options]')
.arguments('<type>')
.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)
.usage("monorepo publish <type> [options]")
.arguments("<type>")
.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)
.action((type) => {
const options = commander.opts()
const options = commander.opts();
runCommand(commands.PublishCmd, {
type,
verbose: !!options.verbose,
dryRun: !!options.dryRun
})
});
})
.parse(process.argv)

.parse(process.argv);
16 changes: 8 additions & 8 deletions packages/monorepo/bin/monorepo-sync.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#!/usr/bin/env node
const commander = require('commander')
const { commands, runCommand } = require('../src')
const commander = require("commander");
const {commands, runCommand} = require("../src");

commander
.usage('monorepo sync <type> [options]')
.arguments('<type>')
.option('-v, --verbose', 'Enable verbose log', (v, t) => t + 1, 0)
.usage("monorepo sync <type> [options]")
.arguments("<type>")
.option("-v, --verbose", "Enable verbose log", (v, t) => t + 1, 0)
.action((type) => {
const options = commander.opts()
const options = commander.opts();
runCommand(commands.SyncCmd, {
type,
verbose: !!options.verbose
})
});
})
.parse(process.argv)
.parse(process.argv);
17 changes: 7 additions & 10 deletions packages/monorepo/bin/monorepo-version.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
#!/usr/bin/env node
const commander = require('commander')
const { commands, runCommand } = require('../src')
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)
.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.opts().verbose
})
});
})
.parse(process.argv)


.parse(process.argv);
18 changes: 9 additions & 9 deletions packages/monorepo/bin/monorepo.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#!/usr/bin/env node

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

commander
.version(cliPkg.version)
.command('ci <type>', 'Perform ci actions (configure)')
.command('build <type>', 'Build artifacts (workspace, packages)')
.command('clean <type>', 'Clean artifacts (workspace, docker)')
.command('publish <type>', 'Publish artifacts (packages, examples, ghpages, docker, heroku)')
.command('sync <type>', 'Perform synchronisation on given type (repository, packages, examples)')
.command('version <version>', 'Update packages version')
.parse(process.argv)
.command("ci <type>", "Perform ci actions (configure)")
.command("build <type>", "Build artifacts (workspace, packages)")
.command("clean <type>", "Clean artifacts (workspace, docker)")
.command("publish <type>", "Publish artifacts (packages, examples, ghpages, docker, heroku)")
.command("sync <type>", "Perform synchronisation on given type (repository, packages, examples)")
.command("version <version>", "Update packages version")
.parse(process.argv);
10 changes: 6 additions & 4 deletions packages/monorepo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
"fancy-log": "1.3.3",
"figures": "3.2.0",
"fs-extra": "9.0.0",
"globby": "11.0.0",
"globby": "11.0.3",
"has-yarn": "^2.1.0",
"inquirer": "7.1.0",
"listr": "0.14.3",
"lodash": "4.17.19",
"lodash": "4.17.21",
"normalize-path": "3.0.0",
"read-package-json": "2.1.1",
"read-package-json": "2.1.2",
"semver": "7.3.2"
},
"directories": {
Expand All @@ -41,5 +41,7 @@
"monorepo": "./bin/monorepo.js"
},
"devDependencies": {},
"peerDependencies": {}
"peerDependencies": {
"semantic-release": "17.4.3"
}
}
32 changes: 16 additions & 16 deletions packages/monorepo/semantic-release.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
const { MonoRepo } = require('./src')
const {MonoRepo} = require("./src");

let monoRepo
let monoRepo;

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

await monoRepo.configureWorkspace({
dryRun: pluginConfig.dryRun
})
});
},

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

await monoRepo.newVersion({ version })
await monoRepo.build('workspace')
await monoRepo.commitChanges({ version })
await monoRepo.newVersion({version});
await monoRepo.build("workspace");
await monoRepo.commitChanges({version});
},

async publish (pluginConfig) {
return monoRepo.publish('packages', { dryRun: pluginConfig.dryRun })
async publish(pluginConfig) {
return monoRepo.publish("packages", {dryRun: pluginConfig.dryRun});
},

async success (pluginConfig) {
async success(pluginConfig) {
if (!pluginConfig.dryRun) {
return monoRepo.sync('repository')
return monoRepo.sync("repository");
}
}
}
};
Loading

0 comments on commit b6ac454

Please sign in to comment.