1+ ( async ( ) => {
2+ // const chalk = require('chalk')
3+ // const execa = require('execa')
4+ const path = require ( 'path' )
5+ const semanticRelease = require ( 'semantic-release' )
6+ // const { WritableStreamBuffer } = require('stream-buffers');
7+ // const stdoutBuffer = WritableStreamBuffer();
8+ // const stderrBuffer = WritableStreamBuffer();
9+
10+ const args = require ( 'minimist' ) ( process . argv . slice ( 2 ) )
11+ const target = args . _ [ 0 ]
12+ const pkg = require ( path . resolve ( __dirname , `../packages/${ target } ` , 'package.json' ) )
13+ const releaserc = {
14+ branches : [
15+ 'master' ,
16+ 'next' ,
17+ 'next-major' ,
18+ { name : 'beta' , prerelease : true } ,
19+ { name : 'alpha' , prerelease : true }
20+ ] ,
21+ plugins : [
22+ '@semantic-release/commit-analyzer' ,
23+ '@semantic-release/release-notes-generator' ,
24+ [
25+ "@semantic-release/exec" ,
26+ {
27+ prepareCmd : "npx ts-node ../../scripts/build.ts --nextVersion ${nextRelease.version}"
28+ }
29+ ] ,
30+ '@semantic-release/npm' ,
31+ [
32+ '@semantic-release/github' ,
33+ {
34+ assets : [
35+ {
36+ path : `${ target } -dist.zip` ,
37+ name : `${ target } -dist-\$\{nextRelease.gitTag\}.zip` ,
38+ label : 'Distribution code (zip)'
39+ }
40+ ]
41+ }
42+ ]
43+ ]
44+ }
45+
46+ await run ( )
47+
48+ async function run ( ) {
49+ // const nextVersion = await getNextVersion()
50+ // console.log(nextVersion)
51+ // await prepare(target)
52+ await release ( )
53+ }
54+
55+ // async function prepare(target: string/*, nextVersion: string*/) {
56+ // try {
57+ // // const buildScript = path.resolve(__dirname, 'build.ts')
58+ // // console.log(chalk.bgCyan("Build package"))
59+ // // execa.sync('npx', ['ts-node', buildScript, '--nextVersion', nextVersion])
60+ // console.log(chalk.bgCyan("Zipping distribution file"))
61+ // execa.sync('zip', ['-r', `${target}-dist.zip`, '.', '-i', 'dist'])
62+ // } catch (err) {
63+ // console.log(`>>>>>>>>>>>>> ${err}`)
64+ // }
65+ // }
66+
67+ async function release ( ) {
68+ const rootDir = path . resolve ( __dirname , '..' )
69+ try {
70+ console . log ( `>>>>>>>>>>>>> Semantic release` )
71+ const result = await semanticRelease ( {
72+ // Core options
73+ branches : releaserc . branches ,
74+ repositoryUrl : pkg . repository . url ,
75+ plugins : releaserc . plugins
76+ } , {
77+ // Run semantic-release from `/path/to/git/repo/root` without having to change local process `cwd` with `process.chdir()`
78+ cwd : rootDir ,
79+ // Pass the variable `MY_ENV_VAR` to semantic-release without having to modify the local `process.env`
80+ env : { ...process . env } ,
81+ // Store stdout and stderr to use later instead of writing to `process.stdout` and `process.stderr`
82+ // stdout: stdoutBuffer,
83+ // stderr: stderrBuffer
84+ } ) ;
85+
86+ if ( result ) {
87+ console . log ( `>>>>>>>>>>>>> Result` )
88+ const { lastRelease, commits, nextRelease, releases } = result ;
89+
90+ console . log ( `Published ${ nextRelease . type } release version ${ nextRelease . version } containing ${ commits . length } commits.` ) ;
91+
92+ if ( lastRelease . version ) {
93+ console . log ( `The last release was "${ lastRelease . version } ".` ) ;
94+ }
95+
96+ for ( const release of releases ) {
97+ console . log ( `The release was published with plugin "${ release . pluginName } ".` ) ;
98+ }
99+ } else {
100+ console . log ( 'No release published.' ) ;
101+ }
102+
103+ // Get stdout and stderr content
104+ // const logs = stdoutBuffer.getContentsAsString('utf8');
105+ // const errors = stderrBuffer.getContentsAsString('utf8');
106+ // console.log(logs, errors);
107+
108+ } catch ( err ) {
109+ console . error ( 'The automated release failed with %O' , err )
110+ }
111+ }
112+
113+ // async function getNextVersion(): Promise<string> {
114+ // try {
115+ // const { nextRelease } = await semanticRelease({
116+ // branches: releaserc.branches,
117+ // repositoryUrl: pkg.repository.url,
118+ // dryRun: true,
119+ // ci: false,
120+ // plugins: [
121+ // '@semantic-release/commit-analyzer',
122+ // [
123+ // "@semantic-release/exec",
124+ // {
125+ // prepareCmd: "npx ts-node ../../scripts/build.ts --nextVersion ${nextRelease.version}"
126+ // }
127+ // ]
128+ // ]
129+ // }, {
130+ // cwd: '../../',
131+ // env: { ...process.env }
132+ // })
133+ // if (nextRelease) return nextRelease.version
134+ // else console.log('No release will bepublished')
135+ // } catch (err) {
136+ // console.error('Failed to retrieve next version with %O', err)
137+ // }
138+ // return pkg.version
139+ // }
140+ } ) ( )
0 commit comments