diff --git a/changelog.md b/changelog.md index 35793a608..54c7bc1d9 100755 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,9 @@ ## Next +### Improvements + +- [internal] Improve publish script for creating github release ([#999](https://github.com/cssinjs/jss/pull/999)) + ### Bug fixes - [jss-starter-kit] Fix react-jss exports and add missing jss exports ([#1001](https://github.com/cssinjs/jss/pull/1001)) diff --git a/lerna.json b/lerna.json index b3e9fe625..fa1642cf1 100644 --- a/lerna.json +++ b/lerna.json @@ -1,11 +1,5 @@ { "npmClient": "yarn", "useWorkspaces": true, - "version": "10.0.0-alpha.9", - "command": { - "publish": { - "allowBranch": ["master"], - "forcePublish": "*" - } - } + "version": "10.0.0-alpha.9" } diff --git a/package.json b/package.json index 3c4f3e13e..a3af5f8ee 100644 --- a/package.json +++ b/package.json @@ -6,29 +6,22 @@ ], "scripts": { "build": "lerna run build", - "check:all": "yarn check:flow && yarn check:ts && yarn check:snapshots && yarn check:lint", "check:flow": "flow check --max-warnings=0", "check:ts": "tsc", "check:snapshots": "lerna run check-snapshot", "check:lint": "eslint scripts/ packages/ docs/ --ext js,md", - "format": "prettier \"*.{js,md,json}\" \"{docs,packages,scripts}/**/*.{js,md,json}\" --write", - "format:ci": "yarn format -- --list-different", - + "format:ci": "yarn format --list-different", "test": "karma start --single-run", "test:watch": "karma start", - "posttest": "[ -z \"$TRAVIS\" ] || codecov", - "codecov": "codecov", - "bench": "cross-env BENCHMARK=true karma start --single-run", - + "test:bench": "cross-env BENCHMARK=true karma start --single-run", "pre-commit": "lint-staged && yarn check:all", - "---Release Scripts---": "", "version": "yarn build && yarn test && node ./scripts/update-changelog && node ./scripts/add-git-files", "prerelease": "yarn check:all && yarn format:ci", - "release": "lerna publish --no-push --exact", - "postrelease": "node ./scripts/create-git-tag && git push --tags", + "release": "lerna publish --exact --force-publish * --allow-branch master", + "postrelease": "node ./scripts/create-github-release", "release:patch": "yarn release patch --dist-tag latest", "release:minor": "yarn release minor --dist-tag latest", "release:major": "yarn release major --dist-tag latest", @@ -60,6 +53,8 @@ "@babel/preset-env": "^7.0.0", "@babel/preset-flow": "^7.0.0", "@babel/preset-react": "^7.0.0", + "@lerna/prompt": "^3.6.0", + "axios": "^0.18.0", "babel-loader": "^8.0.4", "babel-plugin-dev-expression": "^0.2.1", "camelcase": "^5.0.0", @@ -89,6 +84,7 @@ "lerna": "^3.8.0", "lint-staged": "^3.2.2", "mocha": "^3.2.0", + "npmlog": "^4.1.2", "pre-commit": "^1.1.3", "prettier": "^1.13.5", "raf": "^3.4.0", diff --git a/scripts/create-git-tag.js b/scripts/create-git-tag.js deleted file mode 100644 index 83eb0918f..000000000 --- a/scripts/create-git-tag.js +++ /dev/null @@ -1,39 +0,0 @@ -const fs = require('fs') -const shell = require('shelljs') -const Path = require('path') - -const lerna = require('../lerna') -const {CHANGELOG_FILENAME} = require('./constants') - -function getChangelog() { - const content = fs.readFileSync(Path.join(process.cwd(), CHANGELOG_FILENAME), 'utf-8') - - const lines = content.split('\n') - let hasStarted = false - let hasFinished = false - - return lines - .filter(line => { - if (hasFinished) { - return false - } - - if (hasStarted) { - hasFinished = line.startsWith('## ') - - return !hasFinished - } - - hasStarted = line.startsWith(`## ${lerna.version}`) - - return false - }) - .join('\n') -} - -const changelog = getChangelog() -const {code} = shell.exec(`git tag v${lerna.version} -f -a -m "${changelog}"`) - -if (code !== 0) { - shell.exit(code) -} diff --git a/scripts/create-github-release.js b/scripts/create-github-release.js new file mode 100644 index 000000000..37585a62d --- /dev/null +++ b/scripts/create-github-release.js @@ -0,0 +1,61 @@ +const fs = require('fs') +const path = require('path') +const axios = require('axios') +const log = require('npmlog/log') +const {input} = require('@lerna/prompt') + +const lerna = require('../lerna') +const {CHANGELOG_FILENAME} = require('./constants') + +function getChangelog() { + const content = fs.readFileSync(path.join(process.cwd(), CHANGELOG_FILENAME), 'utf-8') + const lines = content.split('\n') + let hasStarted = false + let hasFinished = false + + return lines + .filter(line => { + if (hasFinished) { + return false + } + + if (hasStarted) { + hasFinished = line.startsWith('## ') + + return !hasFinished + } + + hasStarted = line.startsWith(`## ${lerna.version}`) + + return false + }) + .join('\n') +} + +input('Github Username:') + .then(username => + input('Github password:').then(password => ({ + username, + password + })) + ) + .then(auth => + axios.request({ + method: 'POST', + url: `/repos/cssinjs/jss/releases`, + baseURL: `https://api.github.com`, + data: { + tag_name: `v${lerna.version}`, + name: `v${lerna.version}`, + body: getChangelog(), + prerelease: lerna.version.includes('alpha') + }, + auth + }) + ) + .then(() => { + log.info('jss', 'Successfully created github release') + }) + .catch(err => { + log.error('jss', `Error while creating github release: ${err.message}`) + }) diff --git a/scripts/update-changelog.js b/scripts/update-changelog.js index c0f185334..1f9400fd7 100644 --- a/scripts/update-changelog.js +++ b/scripts/update-changelog.js @@ -1,24 +1,32 @@ const fs = require('fs') -const Path = require('path') +const path = require('path') +const log = require('npmlog/log') + const lerna = require('../lerna') const {CHANGELOG_FILENAME} = require('./constants') -const changelogPath = Path.join(process.cwd(), CHANGELOG_FILENAME) +const changelogPath = path.join(process.cwd(), CHANGELOG_FILENAME) const content = fs.readFileSync(changelogPath, 'utf-8') const lines = content .split('\n') .map(line => { - if (line.startsWith(`## ${lerna.version} (unreleased)`)) { + if (line === '## Next') { const today = new Date() - return line.replace( - 'unreleased', - `${today.getUTCFullYear()}-${today.getUTCMonth() + 1}-${today.getUTCDate()}` - ) + const date = `${today.getUTCFullYear()}-${today.getUTCMonth() + 1}-${today.getUTCDate()}` + + return `## ${lerna.version} (${date})` } return line }) .join('\n') -fs.writeFile(changelogPath, lines, 'utf-8') +fs.writeFile(changelogPath, lines, 'utf-8', err => { + if (err) { + log.error('jss', 'Error while updating changelog') + process.exit(1) + } else { + log.info('jss', 'Successfully updated changelog') + } +}) diff --git a/yarn.lock b/yarn.lock index fd494e355..8a5c5d85b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1177,7 +1177,7 @@ resolve-from "^4.0.0" write-json-file "^2.3.0" -"@lerna/prompt@3.6.0": +"@lerna/prompt@3.6.0", "@lerna/prompt@^3.6.0": version "3.6.0" resolved "https://registry.yarnpkg.com/@lerna/prompt/-/prompt-3.6.0.tgz#b17cc464dec9d830619723e879dc747367378217" integrity sha512-nyAjPMolJ/ZRAAVcXrUH89C4n1SiWvLh4xWNvWYKLcf3PI5yges35sDFP/HYrM4+cEbkNFuJCRq6CxaET4PRsg== @@ -2089,6 +2089,14 @@ aws4@^1.8.0: resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.8.0.tgz#f0e003d9ca9e7f59c7a508945d7b2ef9a04a542f" integrity sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ== +axios@^0.18.0: + version "0.18.0" + resolved "https://registry.yarnpkg.com/axios/-/axios-0.18.0.tgz#32d53e4851efdc0a11993b6cd000789d70c05102" + integrity sha1-MtU+SFHv3AoRmTts0AB4nXDAUQI= + dependencies: + follow-redirects "^1.3.0" + is-buffer "^1.1.5" + axobject-query@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/axobject-query/-/axobject-query-2.0.1.tgz#05dfa705ada8ad9db993fa6896f22d395b0b0a07" @@ -3356,7 +3364,7 @@ debug@2.6.8: dependencies: ms "2.0.0" -debug@3.1.0: +debug@3.1.0, debug@=3.1.0: version "3.1.0" resolved "https://registry.yarnpkg.com/debug/-/debug-3.1.0.tgz#5bb5a0672628b64149566ba16819e61518c67261" integrity sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g== @@ -4380,6 +4388,13 @@ follow-redirects@^1.0.0: dependencies: debug "^3.1.0" +follow-redirects@^1.3.0: + version "1.6.1" + resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.6.1.tgz#514973c44b5757368bad8bddfe52f81f015c94cb" + integrity sha512-t2JCjbzxQpWvbhts3l6SH1DKzSrx8a+SsaVf4h6bG4kOXUuPYS/kg2Lr4gQSb7eemaHqJkOThF1BGyjlUkO1GQ== + dependencies: + debug "=3.1.0" + for-in@^1.0.1, for-in@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80"