24
function execHelper(command, options, streamStdout = false) {
25
return new Promise((resolve, reject) => {
26
const proc = cp.exec(command, options, (error, stdout) =>
27
- error ? reject(error) : resolve(stdout.trim())
27
+ error ? reject(error) : resolve(stdout.trim()),
28
);
29
if (streamStdout) {
30
proc.stdout.pipe(process.stdout);
38
39
async function getDateStringForCommit(commit) {
40
let dateString = await execHelper(
41
- `git show -s --no-show-signature --format=%cd --date=format:%Y%m%d ${commit}`
41
+ `git show -s --no-show-signature --format=%cd --date=format:%Y%m%d ${commit}`,
42
);
43
44
// On CI environment, this string is wrapped with quotes '...'s
92
.parseSync();
93
94
const { packages, forReal, debug } = argv;
95
+ let pkgNames = packages;
96
+ if (Array.isArray(packages) === false) {
97
+ pkgNames = [packages];
98
+ }
99
const spinner = ora(
100
`Preparing to publish ${
101
forReal === true ? "(for real)" : "(dry run)"
98
- } [debug=${debug}]`
102
+ } [debug=${debug}]`,
103
).info();
104
105
spinner.info("Building packages");
102
- for (const pkgName of packages) {
106
+ for (const pkgName of pkgNames) {
107
const command = `yarn workspace ${pkgName} run build`;
108
spinner.start(`Running: ${command}\n`);
109
try {
118
119
if (forReal === false) {
120
spinner.info("Dry run: Report tarball contents");
117
- for (const pkgName of packages) {
121
+ for (const pkgName of pkgNames) {
122
console.log(`\n========== ${pkgName} ==========\n`);
123
spinner.start(`Running npm pack --dry-run\n`);
124
try {
133
spinner.stop(`Successfully packed ${pkgName} (dry run)`);
134
}
135
spinner.succeed(
132
- "Please confirm contents of packages before publishing. You can run this command again with --for-real to publish to npm"
136
+ "Please confirm contents of packages before publishing. You can run this command again with --for-real to publish to npm",
137
);
138
}
139
142
"git show -s --no-show-signature --format=%h",
143
{
144
cwd: path.resolve(__dirname, ".."),
141
- }
145
+ },
146
);
147
const dateString = await getDateStringForCommit(commit);
148
145
- for (const pkgName of packages) {
149
+ for (const pkgName of pkgNames) {
150
const pkgDir = path.resolve(__dirname, `../packages/${pkgName}`);
151
const { hash } = await hashElement(pkgDir, {
152
encoding: "hex",
161
`yarn version --new-version ${newVersion} --no-git-tag-version`,
162
{
163
cwd: pkgDir,
160
- }
164
+ },
165
);
166
await execHelper(
167
`git add package.json && git commit -m "Bump version to ${newVersion}"`,
168
{
169
cwd: pkgDir,
166
- }
170
+ },
171
);
172
} catch (e) {
173
spinner.fail(e.toString());
174
throw e;
175
}
176
spinner.succeed(
173
- `Bumped ${pkgName} to ${newVersion} and added a git commit`
177
+ `Bumped ${pkgName} to ${newVersion} and added a git commit`,
178
);
179
}
180
182
spinner.info(
183
`🚨🚨🚨 About to publish to npm in ${
184
TIME_TO_RECONSIDER / 1000
181
- } seconds. You still have time to kill this script!`
185
+ } seconds. You still have time to kill this script!`,
186
);
187
await sleep(TIME_TO_RECONSIDER);
188
}
189
186
- for (const pkgName of packages) {
190
+ for (const pkgName of pkgNames) {
191
const pkgDir = path.resolve(__dirname, `../packages/${pkgName}`);
192
console.log(`\n========== ${pkgName} ==========\n`);
193
spinner.start(`Publishing ${pkgName} to npm\n`);
194
195
const opts = debug === true ? ["publish", "--dry-run"] : ["publish"];
196
try {
193
- await execHelper(`npm ${opts.join(" ")}`, { cwd: pkgDir });
197
+ await spawnHelper("npm", [...opts, "--registry=http://registry.npmjs.org"], {
198
+ cwd: pkgDir,
199
+ stdio: "inherit",
200
+ });
201
console.log("\n");
202
} catch (e) {
203
spinner.fail(e.toString());