-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
133 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"version": "1.1.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import path from 'path' | ||
|
||
export const resolveRoot = (...paths: string[]) => { | ||
return path.resolve(__dirname, '../../../', ...paths) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import fs from 'fs-extra' | ||
import path from 'path' | ||
import semver from 'semver' | ||
import execa from 'execa' | ||
import { resolveRoot } from './util' | ||
import config from './config.json' | ||
|
||
const { version: currentVersion } = config | ||
|
||
type Options = { | ||
releaseType: semver.ReleaseType | ||
preid?: string | ||
} | ||
|
||
const getNewVersion = ({ releaseType, preid }: Options) => { | ||
return semver.inc(currentVersion, releaseType, preid) | ||
} | ||
|
||
const updatePackage = async (version: string) => { | ||
const packagesPath = resolveRoot('packages') | ||
const packages = fs.opendirSync(packagesPath) | ||
|
||
for await (const item of packages) { | ||
if (item.isDirectory()) { | ||
const pkgPath = path.resolve(packagesPath, item.name, 'package.json') | ||
const pkgObj = fs.readJSONSync(pkgPath) | ||
|
||
fs.writeJsonSync( | ||
pkgPath, | ||
{ | ||
...pkgObj, | ||
version | ||
}, | ||
{ | ||
spaces: 2 | ||
} | ||
) | ||
} | ||
} | ||
} | ||
|
||
const updateConfig = (version: string) => { | ||
const configPath = path.resolve(__dirname, 'config.json') | ||
const configObj = fs.readJSONSync(configPath) | ||
|
||
fs.writeJsonSync( | ||
configPath, | ||
{ | ||
...configObj, | ||
version | ||
}, | ||
{ | ||
spaces: 2 | ||
} | ||
) | ||
} | ||
|
||
const tagGit = (version: string) => { | ||
execa.sync('git', ['add', '-A']) | ||
execa.sync('git', ['commit', '-m', `chore: publish ${version}`]) | ||
execa.sync('git', ['tag', version]) | ||
} | ||
|
||
;(() => { | ||
const [, , releaseType = 'minor', preid = 'alpha'] = process.argv | ||
|
||
const version = getNewVersion({ | ||
releaseType: releaseType as semver.ReleaseType, | ||
preid | ||
}) | ||
|
||
updatePackage(version) | ||
updateConfig(version) | ||
tagGit(version) | ||
})() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.