-
-
Notifications
You must be signed in to change notification settings - Fork 293
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
1 parent
62dc820
commit ae00c70
Showing
3 changed files
with
109 additions
and
14 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 |
---|---|---|
@@ -1,18 +1,114 @@ | ||
(() => { | ||
const chalk = require('chalk') | ||
const execa = require('execa') | ||
const path = require('path') | ||
const semanticRelease = require('semantic-release') | ||
// const { WritableStreamBuffer } = require('stream-buffers'); | ||
// const stdoutBuffer = WritableStreamBuffer(); | ||
// const stderrBuffer = WritableStreamBuffer(); | ||
|
||
const args = require('minimist')(process.argv.slice(2)) | ||
const targets = args._ | ||
|
||
if (process.env.CI && targets[0]) { | ||
console.log("execute zip >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") | ||
execa.sync('zip', ['-r', `${targets[0]}-dist.zip`, '.', '-i', 'dist']) | ||
console.log("execute semantic-release >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") | ||
const a = execa.sync('npx', ['semantic-release']) | ||
console.log("A", a) | ||
console.log("finished execution >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") | ||
} else { | ||
console.log(chalk.redBright("You can't run semantic-release locally")) | ||
const target = args._[0] | ||
const pkg = require(path.resolve(__dirname, `../packages/${target}`, 'package.json')) | ||
const releaserc = { | ||
branches: [ | ||
'master', | ||
'next', | ||
'next-major', | ||
{ name: 'beta', prerelease: true }, | ||
{ name: 'alpha', prerelease: true } | ||
], | ||
plugins: [ | ||
'@semantic-release/commit-analyzer', | ||
'@semantic-release/release-notes-generator', | ||
'@semantic-release/npm', | ||
[ | ||
'@semantic-release/github', | ||
{ | ||
assets: [ | ||
{ | ||
path: `${target}-dist.zip`, | ||
name: `${target}-dist-\$\{nextRelease.gitTag\}.zip`, | ||
label: 'Distribution code (zip)' | ||
} | ||
] | ||
} | ||
] | ||
] | ||
} | ||
|
||
run(target) | ||
|
||
async function run(target: string) { | ||
const nextVersion = await getNextVersion() | ||
await prepare(target, nextVersion) | ||
await release() | ||
} | ||
|
||
async function prepare(target: string, nextVersion: string) { | ||
const buildScript = path.resolve(__dirname, 'build.js') | ||
execa.sync('npx', ['ts-node', buildScript, '--nextVersion', nextVersion]) | ||
execa.sync('zip', ['-r', `${target}-dist.zip`, '.', '-i', 'dist']) | ||
execa.sync('npx', ['semantic-release']) | ||
} | ||
|
||
async function release() { | ||
try { | ||
const result = await semanticRelease({ | ||
// Core options | ||
branches: releaserc.branches, | ||
repositoryUrl: pkg.repository.url, | ||
plugins: releaserc.plugins | ||
}, { | ||
// Run semantic-release from `/path/to/git/repo/root` without having to change local process `cwd` with `process.chdir()` | ||
cwd: '', | ||
// Pass the variable `MY_ENV_VAR` to semantic-release without having to modify the local `process.env` | ||
env: { ...process.env }, | ||
// Store stdout and stderr to use later instead of writing to `process.stdout` and `process.stderr` | ||
// stdout: stdoutBuffer, | ||
// stderr: stderrBuffer | ||
}); | ||
|
||
if (result) { | ||
const { lastRelease, commits, nextRelease, releases } = result; | ||
|
||
console.log(`Published ${nextRelease.type} release version ${nextRelease.version} containing ${commits.length} commits.`); | ||
|
||
if (lastRelease.version) { | ||
console.log(`The last release was "${lastRelease.version}".`); | ||
} | ||
|
||
for (const release of releases) { | ||
console.log(`The release was published with plugin "${release.pluginName}".`); | ||
} | ||
} else { | ||
console.log('No release published.'); | ||
} | ||
|
||
// Get stdout and stderr content | ||
// const logs = stdoutBuffer.getContentsAsString('utf8'); | ||
// const errors = stderrBuffer.getContentsAsString('utf8'); | ||
// console.log(logs, errors); | ||
|
||
} catch (err) { | ||
console.error('The automated release failed with %O', err) | ||
} | ||
} | ||
|
||
async function getNextVersion(): Promise<string> { | ||
try { | ||
const { nextRelease } = await semanticRelease({ | ||
branches: releaserc.branches, | ||
repositoryUrl: pkg.repository.url, | ||
dryRun: true, | ||
ci: false, | ||
plugins: ['@semantic-release/commit-analyzer'] | ||
}) | ||
if (nextRelease) return nextRelease.version | ||
else console.log('No release will bepublished') | ||
} catch (err) { | ||
console.error('Failed to retrieve next version with %O', err) | ||
} | ||
return pkg.version | ||
} | ||
})() |