Skip to content

Commit 931d67c

Browse files
committed
chore: make manual publishing a bit better
1 parent a2e62db commit 931d67c

2 files changed

Lines changed: 51 additions & 37 deletions

File tree

gulpfile.js

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function checkLicenses() {
4848
/**
4949
* Prepare for publishing. Must be run before any manual publish command.
5050
*
51-
* Clones blockly-samples, runs build and tests, logs into npm publish service.
51+
* Clones blockly-samples, runs build and tests.
5252
* @param {Function} done Completed callback.
5353
*/
5454
function prepareForPublish(done) {
@@ -82,11 +82,6 @@ function prepareForPublish(done) {
8282
console.log('Testing all plugins.');
8383
execSync('npm run test', {cwd: releaseDir, stdio: 'inherit'});
8484

85-
// Login to npm.
86-
console.log('Logging in to npm.');
87-
execSync(`npm login`, {
88-
stdio: 'inherit',
89-
});
9085
done();
9186
}
9287

@@ -100,16 +95,15 @@ function exitIfNoReleaseDir(releaseDir, done) {
10095
if (!fs.existsSync(releaseDir)) {
10196
console.error(
10297
`No release directory ${releaseDir} exists. ` +
103-
`Did you run 'npm run publish:prepare'?`,
98+
`blockly-samples may not have been cloned correctly.`,
10499
);
105100
done();
106101
process.exit(1);
107102
}
108103
}
109104

110105
/**
111-
* This script does not log into the npm publish service. If you haven't run
112-
* the prepare script recently, publishing will fail for that reason.
106+
* Publishes plugins using lerna. MUST be run after `prepareForPublish`.
113107
* @param {boolean=} force True for forcing all plugins to publish, even ones
114108
* that have not changed.
115109
* @returns {Function} Gulp task.
@@ -141,8 +135,8 @@ function publish(force) {
141135
* @param {Function} done Completed callback.
142136
* @returns {Function} Gulp task.
143137
*/
144-
function publishManual(done) {
145-
return publish(false)(done);
138+
function prepareAndPublish(done) {
139+
return gulp.series(prepareForPublish, publish(false))(done);
146140
}
147141

148142
/**
@@ -151,8 +145,8 @@ function publishManual(done) {
151145
* @param {Function} done Completed callback.
152146
* @returns {Function} Gulp task.
153147
*/
154-
function forcePublish(done) {
155-
return publish(true)(done);
148+
function prepareAndForcePublish(done) {
149+
return gulp.series(prepareForPublish, publish(true))(done);
156150
}
157151

158152
/**
@@ -178,6 +172,16 @@ function publishFromPackage(done) {
178172
done();
179173
}
180174

175+
/**
176+
* Publishes plugins that haven't been previously uploaded to npm.
177+
* Also runs the prepare scripts to ensure plugins have been built and tested before publishing.
178+
* @param {Function} done Completed callback.
179+
* @returns {Function} Gulp task.
180+
*/
181+
function prepareAndPublishFromPackage(done) {
182+
return gulp.series(prepareForPublish, publishFromPackage)(done);
183+
}
184+
181185
/**
182186
* Runs lerna version to check which version numbers would be updated.
183187
* The version numbers will not be pushed and no tags or releases will
@@ -202,6 +206,15 @@ function checkVersions(done) {
202206
done();
203207
}
204208

209+
/**
210+
* Runs prepareForPublish and then checkVersions.
211+
* @param {Function} done Completed callback.
212+
* @returns {Function} Gulp task.
213+
*/
214+
function prepareAndCheckVersions(done) {
215+
return gulp.series(prepareForPublish, checkVersions)(done);
216+
}
217+
205218
/**
206219
* Deploy all plugins to gh-pages.
207220
* @param {string=} repo The repo to deploy to.
@@ -312,10 +325,10 @@ module.exports = {
312325
deployUpstream: deployToGhPagesUpstream,
313326
predeploy: predeployTasks.predeployAll,
314327
prepareForPublish: prepareForPublish,
315-
publishManual: publishManual,
316-
forcePublish: forcePublish,
317-
publishFromPackage: publishFromPackage,
318-
checkVersions: checkVersions,
328+
publishManual: prepareAndPublish,
329+
forcePublish: prepareAndForcePublish,
330+
publishFromPackage: prepareAndPublishFromPackage,
331+
checkVersions: prepareAndCheckVersions,
319332
testGhPagesBeta: testGhPagesLocally(true),
320333
testGhPages: testGhPagesLocally(false),
321334
};

scripts.md

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -52,55 +52,42 @@ This script builds all files needed to deploy plugins and examples to GitHub Pag
5252

5353
This script installs a beta version of Blockly, builds all files needed to deploy plugins and examples to GitHub Pages, then starts a local server with that content.
5454

55-
### `npm run publish:prepare`
56-
57-
This script will clone a copy of blockly-samples to a directory called `dist`,
58-
run `npm ci`, build and test all plugins, and then log in to the npm publishing
59-
service. It must be run before any of the other manual publishing commands are
60-
run.
61-
62-
If any plugin fails to build or some tests fail, this script should fail. Since
63-
nothing has been pushed to npm or github, you can simply correct the error and
64-
try again.
65-
6655
### `npm run publish:manual`
6756

68-
This script assumes that you have already run `npm run publish:prepare`. It will
57+
This script will first run `npm run publish:prepare`. It will
6958
publish all of the changed plugins since the last release, using the `dist`
7059
directory. It runs the lerna command that uses conventional commits to determine
7160
a new version number for each plugin, and publishes the new versions to npm and
72-
to a github release and tag. Plugins do not automatically build themselves
73-
before publishing. You must have run `npm run publish:prepare` script ahead of
74-
time for this reason.
61+
to a github release and tag.
7562

7663
If there is some error with npm while running this command, you may end up in a
7764
state where some plugins have been published to npm and not others, after lerna
7865
has already tagged the new releases. You can recover from this state by fixing
79-
the error, and then running `npm run publish:prepare` again followed by
66+
the error, and then running either
8067
`npm run publish:unpublishedOnly` or `npm run publish:force`.
8168

8269
### `npm run publish:unpublishedOnly`
8370

84-
This script assumes that you have already run `npm run publish:prepare`. It uses the `dist`
71+
This script will first run `npm run publish:prepare`. It uses the `dist`
8572
directory created in that script. It uses lerna to check each plugin to see if the version
8673
in `package.json` matches the version on npm. If a version is not yet on npm, it will publish
8774
that plugin without updating its version number. Thus, this script should only be used
8875
after `lerna version` has been run in some form (most commonly, during a run of
8976
`npm run publish:manual` that subsequently failed).
9077

91-
If this script fails, correct the error and re-run `npm run publish:prepare` and
78+
If this script fails, correct the error and re-run
9279
`npm run publish:unpublishedOnly`.
9380

9481
### `npm run publish:force`
9582

96-
This script assumes you have already run `npm run publish:prepare`. It will use lerna
83+
This script will first run `npm run publish:prepare`. It will use lerna
9784
to force publish all packages, even those that have not changed. You can use this
9885
if you run into publishing problems to recover from error states, but you should prefer
9986
to use `npm run publish:unpublishedOnly` if possible.
10087

10188
### `npm run publish:checkVersions`
10289

103-
This script assumes you have already run `npm run publish:prepare`. It will run `lerna
90+
This script will first run `npm run publish:prepare`. It will run `lerna
10491
version` to generate the new version numbers using conventional commits that would be
10592
created during a full publish action, but it will not actually push the changes nor
10693
create any tags. This can be used to check which plugins would be published and under
@@ -109,6 +96,20 @@ latest tags pulled. This is taken care of by the `publish:prepare` script.
10996

11097
## Other Scripts
11198

99+
### `npm run publish:prepare`
100+
101+
This script will clone a copy of blockly-samples to a directory called `dist`,
102+
run `npm ci`, build and test all plugins, and then log in to the npm publishing
103+
service. It must be run before any of the other manual publishing commands are
104+
run.
105+
106+
If any plugin fails to build or some tests fail, this script should fail. Since
107+
nothing has been pushed to npm or github, you can simply correct the error and
108+
try again.
109+
110+
This script will be run automatically before any of the other publish scripts,
111+
so you do not need to run it manually first.
112+
112113
### `npm run deploy:prepare`
113114

114115
This script prepares each of the plugins for deployment. In general, the script

0 commit comments

Comments
 (0)