@@ -10,15 +10,16 @@ import { execSync } from "child_process";
1010import fs from "fs" ;
1111import path from "path" ;
1212
13- import pkg from "../lerna.json" ;
13+ import { yellow } from "chalk" ;
14+
15+ import { version } from "../lerna.json" ;
1416import { createDryRun } from "./utils/dry-run" ;
1517import { getOutput } from "./utils/get-output" ;
1618import { printBanner } from "./utils/print-utils" ;
1719
1820const ORG = "cloud-annotations" ;
1921const REPO = "docusaurus-plugin-openapi" ;
20- const BUILD_PATH = "build" ;
21- const REPO_ROOT = path . join ( BUILD_PATH , REPO ) ;
22+ let REPO_ROOT = undefined ;
2223
2324// Makes the script crash on unhandled rejections instead of silently
2425// ignoring them. In the future, promise rejections that are not handled will
@@ -28,7 +29,7 @@ process.on("unhandledRejection", (err) => {
2829} ) ;
2930
3031const safeExec = createDryRun ( execSync ) ;
31- const safeRmdir = createDryRun ( fs . rmdirSync ) ;
32+ const safeRmdir = createDryRun ( fs . rmSync ) ;
3233const safeMkdir = createDryRun ( fs . mkdirSync ) ;
3334
3435function getGitUserName ( ) {
@@ -40,21 +41,33 @@ function getGitUserEmail() {
4041}
4142
4243function ensureCleanDir ( path : string ) {
43- safeRmdir ( path , { recursive : true } ) ;
44- safeMkdir ( path ) ;
44+ if ( fs . existsSync ( path ) ) {
45+ safeRmdir ( path , { recursive : true } ) ;
46+ }
47+ safeMkdir ( path , { recursive : true } ) ;
4548}
4649
4750function checkoutCode ( ) {
4851 printBanner ( "Retrieving source code" ) ;
4952
53+ const BUILD_PATH = "build" ;
5054 ensureCleanDir ( BUILD_PATH ) ;
5155
52- const gitUserName = getGitUserName ( ) ;
53- const gitUserEmail = getGitUserEmail ( ) ;
54-
5556 safeExec ( `git clone [email protected] :${ ORG } /${ REPO } .git ${ REPO } ` , { 5657 cwd : BUILD_PATH ,
5758 } ) ;
59+
60+ REPO_ROOT = path . join ( BUILD_PATH , REPO ) ;
61+
62+ safeExec ( `yarn install` , {
63+ cwd : REPO_ROOT ,
64+ stdio : "ignore" ,
65+ } ) ;
66+ }
67+
68+ function configureGit ( ) {
69+ const gitUserName = getGitUserName ( ) ;
70+ const gitUserEmail = getGitUserEmail ( ) ;
5871 safeExec ( `git config user.name ${ gitUserName } ` , {
5972 cwd : REPO_ROOT ,
6073 } ) ;
@@ -66,28 +79,20 @@ function checkoutCode() {
6679function buildAndPublish ( ) {
6780 printBanner ( "Building Packages" ) ;
6881
69- safeExec ( `yarn install` , {
70- cwd : REPO_ROOT ,
71- stdio : "ignore" ,
72- } ) ;
73-
7482 safeExec ( `yarn lerna run build --no-private` , {
7583 cwd : REPO_ROOT ,
7684 } ) ;
7785
7886 printBanner ( "Publishing Packages" ) ;
7987
80- safeExec (
81- `lerna publish --yes from-package --no-git-tag-version --no-verify-access --no-push` ,
82- {
83- cwd : REPO_ROOT ,
84- }
85- ) ;
88+ safeExec ( `lerna publish --yes from-package` , {
89+ cwd : REPO_ROOT ,
90+ } ) ;
8691}
8792
8893function tag ( ) {
89- const tag = `v${ pkg . version } ` ;
90- const message = `Version ${ pkg . version } ` ;
94+ const tag = `v${ version } ` ;
95+ const message = `Version ${ version } ` ;
9196 safeExec ( `git tag -a ${ tag } -m "${ message } "` , {
9297 cwd : REPO_ROOT ,
9398 } ) ;
@@ -96,8 +101,19 @@ function tag() {
96101 } ) ;
97102}
98103
104+ function versions ( ) {
105+ return getOutput ( `git tag --list 'v*'` ) . split ( "\n" ) ;
106+ }
107+
99108function main ( ) {
100- checkoutCode ( ) ;
109+ if ( versions ( ) . includes ( `v${ version } ` ) ) {
110+ console . log ( yellow ( `SKIPPING: Version ${ version } already exists.` ) ) ;
111+ return ;
112+ }
113+ if ( ! process . env . CI ) {
114+ checkoutCode ( ) ;
115+ }
116+ configureGit ( ) ;
101117 buildAndPublish ( ) ;
102118 tag ( ) ;
103119}
0 commit comments