16
16
// 3. restore the original package.json
17
17
//
18
18
19
- import type PackageJson from '../../package.json'
20
19
import * as child_process from 'child_process'
21
20
import * as fs from 'fs-extra'
22
-
23
- // Importing from `src` isn't great but it does make things simple
24
- import { betaUrl } from '../../src/dev/config'
25
-
26
- const packageJsonFile = './package.json'
27
- const webpackConfigJsFile = './webpack.base.config.js'
21
+ import * as path from 'path'
28
22
29
23
function parseArgs ( ) {
30
24
// Invoking this script with argument "foo":
@@ -80,7 +74,15 @@ function isRelease(): boolean {
80
74
* Whether or not this a private beta build
81
75
*/
82
76
function isBeta ( ) : boolean {
83
- return ! ! betaUrl
77
+ try {
78
+ // This path only exists for packages/toolkit.
79
+ // As noted before: "Importing from `src` isn't great but it does make things simple"
80
+ // TODO: Generalize betaUrl for all packages.
81
+ const betaUrl = require ( path . resolve ( './src/dev/config' ) ) . betaUrl
82
+ return ! ! betaUrl
83
+ } catch {
84
+ return false
85
+ }
84
86
}
85
87
86
88
/**
@@ -103,6 +105,14 @@ function getVersionSuffix(feature: string, debug: boolean): string {
103
105
104
106
function main ( ) {
105
107
const args = parseArgs ( )
108
+ // It is expected that this will package from a packages/{subproject} folder.
109
+ // There is a base config in packages/
110
+ const packageJsonFile = './package.json'
111
+ const webpackConfigJsFile = '../webpack.base.config.js'
112
+ if ( ! fs . existsSync ( packageJsonFile ) ) {
113
+ throw new Error ( `package.json not found, cannot package this directory: ${ process . cwd ( ) } ` )
114
+ }
115
+
106
116
let release = true
107
117
108
118
try {
@@ -113,12 +123,10 @@ function main() {
113
123
}
114
124
115
125
if ( ! release || args . debug ) {
116
- // Create backup files so we can restore the originals later.
126
+ // Create backup file so we can restore the originals later.
117
127
fs . copyFileSync ( packageJsonFile , `${ packageJsonFile } .bk` )
118
- fs . copyFileSync ( webpackConfigJsFile , `${ webpackConfigJsFile } .bk` )
119
- fs . copyFileSync ( '../../CHANGELOG.md' , 'CHANGELOG.md' )
120
128
121
- const packageJson : typeof PackageJson = JSON . parse ( fs . readFileSync ( packageJsonFile , { encoding : 'utf-8' } ) )
129
+ const packageJson = JSON . parse ( fs . readFileSync ( packageJsonFile , { encoding : 'utf-8' } ) )
122
130
const versionSuffix = getVersionSuffix ( args . feature , args . debug )
123
131
const version = packageJson . version
124
132
if ( isBeta ( ) ) {
@@ -138,26 +146,34 @@ function main() {
138
146
fs . writeFileSync ( packageJsonFile , JSON . stringify ( packageJson , undefined , ' ' ) )
139
147
140
148
if ( args . debug ) {
149
+ fs . copyFileSync ( webpackConfigJsFile , `${ webpackConfigJsFile } .bk` )
141
150
const webpackConfigJs = fs . readFileSync ( webpackConfigJsFile , { encoding : 'utf-8' } )
142
151
fs . writeFileSync ( webpackConfigJsFile , webpackConfigJs . replace ( / m i n i m i z e : t r u e / , 'minimize: false' ) )
143
152
}
144
153
}
154
+ // Always include CHANGELOG.md until we can have separate changelogs for packages
155
+ fs . copyFileSync ( '../../CHANGELOG.md' , 'CHANGELOG.md' )
145
156
146
157
child_process . execSync ( `vsce package` , { stdio : 'inherit' } )
147
158
const packageJson = JSON . parse ( fs . readFileSync ( packageJsonFile , { encoding : 'utf-8' } ) )
148
159
console . log ( `VSIX Version: ${ packageJson . version } ` )
149
160
150
- const vsixName = `aws-toolkit-vscode-${ packageJson . version } .vsix`
161
+ // Hoist .vsix to root folder, because the release infra expects it to be there.
162
+ // TODO: Once we can support releasing multiple artifacts,
163
+ // let's just keep the .vsix in its respective project folder in packages/
164
+ const vsixName = `${ packageJson . name } -${ packageJson . version } .vsix`
151
165
fs . moveSync ( vsixName , `../../${ vsixName } ` , { overwrite : true } )
152
166
} catch ( e ) {
153
167
console . log ( e )
154
168
throw Error ( 'package.ts: failed' )
155
169
} finally {
170
+ // Restore the original files.
156
171
if ( ! release ) {
157
- // Restore the original files.
158
172
fs . copyFileSync ( `${ packageJsonFile } .bk` , packageJsonFile )
159
- fs . copyFileSync ( `${ webpackConfigJsFile } .bk` , webpackConfigJsFile )
160
173
fs . unlinkSync ( `${ packageJsonFile } .bk` )
174
+ }
175
+ if ( args . debug ) {
176
+ fs . copyFileSync ( `${ webpackConfigJsFile } .bk` , webpackConfigJsFile )
161
177
fs . unlinkSync ( `${ webpackConfigJsFile } .bk` )
162
178
}
163
179
}
0 commit comments