new license file version [CI SKIP]
This commit is contained in:
@@ -0,0 +1,223 @@
|
||||
# update-notifier
|
||||
|
||||
> Update notifications for your CLI app
|
||||
|
||||

|
||||
|
||||
Inform users of your package of updates in a non-intrusive way.
|
||||
|
||||
#### Contents
|
||||
|
||||
- [Install](#install)
|
||||
- [Usage](#usage)
|
||||
- [How](#how)
|
||||
- [API](#api)
|
||||
- [About](#about)
|
||||
- [Users](#users)
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install update-notifier
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### Simple
|
||||
|
||||
```js
|
||||
const updateNotifier = require('update-notifier');
|
||||
const pkg = require('./package.json');
|
||||
|
||||
updateNotifier({pkg}).notify();
|
||||
```
|
||||
|
||||
### Comprehensive
|
||||
|
||||
```js
|
||||
const updateNotifier = require('update-notifier');
|
||||
const pkg = require('./package.json');
|
||||
|
||||
// Checks for available update and returns an instance
|
||||
const notifier = updateNotifier({pkg});
|
||||
|
||||
// Notify using the built-in convenience method
|
||||
notifier.notify();
|
||||
|
||||
// `notifier.update` contains some useful info about the update
|
||||
console.log(notifier.update);
|
||||
/*
|
||||
{
|
||||
latest: '1.0.1',
|
||||
current: '1.0.0',
|
||||
type: 'patch', // Possible values: latest, major, minor, patch, prerelease, build
|
||||
name: 'pageres'
|
||||
}
|
||||
*/
|
||||
```
|
||||
|
||||
### Options and custom message
|
||||
|
||||
```js
|
||||
const notifier = updateNotifier({
|
||||
pkg,
|
||||
updateCheckInterval: 1000 * 60 * 60 * 24 * 7 // 1 week
|
||||
});
|
||||
|
||||
if (notifier.update) {
|
||||
console.log(`Update available: ${notifier.update.latest}`);
|
||||
}
|
||||
```
|
||||
|
||||
## How
|
||||
|
||||
Whenever you initiate the update notifier and it's not within the interval threshold, it will asynchronously check with npm in the background for available updates, then persist the result. The next time the notifier is initiated, the result will be loaded into the `.update` property. This prevents any impact on your package startup performance.
|
||||
The update check is done in a unref'ed [child process](https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options). This means that if you call `process.exit`, the check will still be performed in its own process.
|
||||
|
||||
The first time the user runs your app, it will check for an update, and even if an update is available, it will wait the specified `updateCheckInterval` before notifying the user. This is done to not be annoying to the user, but might surprise you as an implementer if you're testing whether it works. Check out [`example.js`](example.js) to quickly test out `update-notifier` and see how you can test that it works in your app.
|
||||
|
||||
## API
|
||||
|
||||
### notifier = updateNotifier(options)
|
||||
|
||||
Checks if there is an available update. Accepts options defined below. Returns an instance with an `.update` property if there is an available update, otherwise `undefined`.
|
||||
|
||||
### options
|
||||
|
||||
Type: `object`
|
||||
|
||||
#### pkg
|
||||
|
||||
Type: `object`
|
||||
|
||||
##### name
|
||||
|
||||
*Required*\
|
||||
Type: `string`
|
||||
|
||||
##### version
|
||||
|
||||
*Required*\
|
||||
Type: `string`
|
||||
|
||||
#### updateCheckInterval
|
||||
|
||||
Type: `number`\
|
||||
Default: `1000 * 60 * 60 * 24` *(1 day)*
|
||||
|
||||
How often to check for updates.
|
||||
|
||||
#### shouldNotifyInNpmScript
|
||||
|
||||
Type: `boolean`\
|
||||
Default: `false`
|
||||
|
||||
Allows notification to be shown when running as an npm script.
|
||||
|
||||
#### distTag
|
||||
|
||||
Type: `string`\
|
||||
Default: `'latest'`
|
||||
|
||||
Which [dist-tag](https://docs.npmjs.com/adding-dist-tags-to-packages) to use to find the latest version.
|
||||
|
||||
### notifier.fetchInfo()
|
||||
|
||||
Check update information.
|
||||
|
||||
Returns an `object` with:
|
||||
|
||||
- `latest` _(String)_ - Latest version.
|
||||
- `current` _(String)_ - Current version.
|
||||
- `type` _(String)_ - Type of current update. Possible values: `latest`, `major`, `minor`, `patch`, `prerelease`, `build`.
|
||||
- `name` _(String)_ - Package name.
|
||||
|
||||
### notifier.notify(options?)
|
||||
|
||||
Convenience method to display a notification message. *(See screenshot)*
|
||||
|
||||
Only notifies if there is an update and the process is [TTY](https://nodejs.org/api/process.html#process_a_note_on_process_i_o).
|
||||
|
||||
#### options
|
||||
|
||||
Type: `object`
|
||||
|
||||
##### defer
|
||||
|
||||
Type: `boolean`\
|
||||
Default: `true`
|
||||
|
||||
Defer showing the notification to after the process has exited.
|
||||
|
||||
##### message
|
||||
|
||||
Type: `string`\
|
||||
Default: [See above screenshot](https://github.com/yeoman/update-notifier#update-notifier-)
|
||||
|
||||
Message that will be shown when an update is available.
|
||||
|
||||
Available placeholders:
|
||||
|
||||
- `{packageName}` - Package name.
|
||||
- `{currentVersion}` - Current version.
|
||||
- `{latestVersion}` - Latest version.
|
||||
- `{updateCommand}` - Update command.
|
||||
|
||||
```js
|
||||
notifier.notify({message: 'Run `{updateCommand}` to update.'});
|
||||
|
||||
// Output:
|
||||
// Run `npm install update-notifier-tester@1.0.0` to update.
|
||||
```
|
||||
|
||||
##### isGlobal
|
||||
|
||||
Type: `boolean`\
|
||||
Default: Auto-detect
|
||||
|
||||
Include the `-g` argument in the default message's `npm i` recommendation. You may want to change this if your CLI package can be installed as a dependency of another project, and don't want to recommend a global installation. This option is ignored if you supply your own `message` (see above).
|
||||
|
||||
##### boxenOptions
|
||||
|
||||
Type: `object`\
|
||||
Default: `{padding: 1, margin: 1, align: 'center', borderColor: 'yellow', borderStyle: 'round'}` *(See screenshot)*
|
||||
|
||||
Options object that will be passed to [`boxen`](https://github.com/sindresorhus/boxen).
|
||||
|
||||
### User settings
|
||||
|
||||
Users of your module have the ability to opt-out of the update notifier by changing the `optOut` property to `true` in `~/.config/configstore/update-notifier-[your-module-name].json`. The path is available in `notifier.config.path`.
|
||||
|
||||
Users can also opt-out by [setting the environment variable](https://github.com/sindresorhus/guides/blob/main/set-environment-variables.md) `NO_UPDATE_NOTIFIER` with any value or by using the `--no-update-notifier` flag on a per run basis.
|
||||
|
||||
The check is also skipped automatically:
|
||||
- on CI
|
||||
- in unit tests (when the `NODE_ENV` environment variable is `test`)
|
||||
|
||||
## About
|
||||
|
||||
The idea for this module came from the desire to apply the browser update strategy to CLI tools, where everyone is always on the latest version. We first tried automatic updating, which we discovered wasn't popular. This is the second iteration of that idea, but limited to just update notifications.
|
||||
|
||||
## Users
|
||||
|
||||
There are a bunch projects using it:
|
||||
|
||||
- [npm](https://github.com/npm/npm) - Package manager for JavaScript
|
||||
- [Yeoman](https://yeoman.io) - Modern workflows for modern webapps
|
||||
- [AVA](https://avajs.dev) - Simple concurrent test runner
|
||||
- [XO](https://github.com/xojs/xo) - JavaScript happiness style linter
|
||||
- [Node GH](https://github.com/node-gh/gh) - GitHub command line tool
|
||||
|
||||
[And 2700+ more…](https://www.npmjs.org/browse/depended/update-notifier)
|
||||
|
||||
---
|
||||
|
||||
<div align="center">
|
||||
<b>
|
||||
<a href="https://tidelift.com/subscription/pkg/npm-update_notifier?utm_source=npm-update-notifier&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
|
||||
</b>
|
||||
<br>
|
||||
<sub>
|
||||
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
|
||||
</sub>
|
||||
</div>
|
||||
@@ -0,0 +1,110 @@
|
||||
/** PURE_IMPORTS_START tslib,_AsyncAction,_AsyncScheduler PURE_IMPORTS_END */
|
||||
import * as tslib_1 from "tslib";
|
||||
import { AsyncAction } from './AsyncAction';
|
||||
import { AsyncScheduler } from './AsyncScheduler';
|
||||
var VirtualTimeScheduler = /*@__PURE__*/ (function (_super) {
|
||||
tslib_1.__extends(VirtualTimeScheduler, _super);
|
||||
function VirtualTimeScheduler(SchedulerAction, maxFrames) {
|
||||
if (SchedulerAction === void 0) {
|
||||
SchedulerAction = VirtualAction;
|
||||
}
|
||||
if (maxFrames === void 0) {
|
||||
maxFrames = Number.POSITIVE_INFINITY;
|
||||
}
|
||||
var _this = _super.call(this, SchedulerAction, function () { return _this.frame; }) || this;
|
||||
_this.maxFrames = maxFrames;
|
||||
_this.frame = 0;
|
||||
_this.index = -1;
|
||||
return _this;
|
||||
}
|
||||
VirtualTimeScheduler.prototype.flush = function () {
|
||||
var _a = this, actions = _a.actions, maxFrames = _a.maxFrames;
|
||||
var error, action;
|
||||
while ((action = actions[0]) && action.delay <= maxFrames) {
|
||||
actions.shift();
|
||||
this.frame = action.delay;
|
||||
if (error = action.execute(action.state, action.delay)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (error) {
|
||||
while (action = actions.shift()) {
|
||||
action.unsubscribe();
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
VirtualTimeScheduler.frameTimeFactor = 10;
|
||||
return VirtualTimeScheduler;
|
||||
}(AsyncScheduler));
|
||||
export { VirtualTimeScheduler };
|
||||
var VirtualAction = /*@__PURE__*/ (function (_super) {
|
||||
tslib_1.__extends(VirtualAction, _super);
|
||||
function VirtualAction(scheduler, work, index) {
|
||||
if (index === void 0) {
|
||||
index = scheduler.index += 1;
|
||||
}
|
||||
var _this = _super.call(this, scheduler, work) || this;
|
||||
_this.scheduler = scheduler;
|
||||
_this.work = work;
|
||||
_this.index = index;
|
||||
_this.active = true;
|
||||
_this.index = scheduler.index = index;
|
||||
return _this;
|
||||
}
|
||||
VirtualAction.prototype.schedule = function (state, delay) {
|
||||
if (delay === void 0) {
|
||||
delay = 0;
|
||||
}
|
||||
if (!this.id) {
|
||||
return _super.prototype.schedule.call(this, state, delay);
|
||||
}
|
||||
this.active = false;
|
||||
var action = new VirtualAction(this.scheduler, this.work);
|
||||
this.add(action);
|
||||
return action.schedule(state, delay);
|
||||
};
|
||||
VirtualAction.prototype.requestAsyncId = function (scheduler, id, delay) {
|
||||
if (delay === void 0) {
|
||||
delay = 0;
|
||||
}
|
||||
this.delay = scheduler.frame + delay;
|
||||
var actions = scheduler.actions;
|
||||
actions.push(this);
|
||||
actions.sort(VirtualAction.sortActions);
|
||||
return true;
|
||||
};
|
||||
VirtualAction.prototype.recycleAsyncId = function (scheduler, id, delay) {
|
||||
if (delay === void 0) {
|
||||
delay = 0;
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
VirtualAction.prototype._execute = function (state, delay) {
|
||||
if (this.active === true) {
|
||||
return _super.prototype._execute.call(this, state, delay);
|
||||
}
|
||||
};
|
||||
VirtualAction.sortActions = function (a, b) {
|
||||
if (a.delay === b.delay) {
|
||||
if (a.index === b.index) {
|
||||
return 0;
|
||||
}
|
||||
else if (a.index > b.index) {
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else if (a.delay > b.delay) {
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
return -1;
|
||||
}
|
||||
};
|
||||
return VirtualAction;
|
||||
}(AsyncAction));
|
||||
export { VirtualAction };
|
||||
//# sourceMappingURL=VirtualTimeScheduler.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"forkJoin.js","sources":["../src/observable/forkJoin.ts"],"names":[],"mappings":";;;;;AAAA,qDAAgD"}
|
||||
@@ -0,0 +1 @@
|
||||
import 'rxjs-compat/add/operator/throttleTime';
|
||||
@@ -0,0 +1,57 @@
|
||||
import { async } from '../scheduler/async';
|
||||
import { isDate } from '../util/isDate';
|
||||
import { SimpleOuterSubscriber, innerSubscribe, SimpleInnerSubscriber } from '../innerSubscribe';
|
||||
export function timeoutWith(due, withObservable, scheduler = async) {
|
||||
return (source) => {
|
||||
let absoluteTimeout = isDate(due);
|
||||
let waitFor = absoluteTimeout ? (+due - scheduler.now()) : Math.abs(due);
|
||||
return source.lift(new TimeoutWithOperator(waitFor, absoluteTimeout, withObservable, scheduler));
|
||||
};
|
||||
}
|
||||
class TimeoutWithOperator {
|
||||
constructor(waitFor, absoluteTimeout, withObservable, scheduler) {
|
||||
this.waitFor = waitFor;
|
||||
this.absoluteTimeout = absoluteTimeout;
|
||||
this.withObservable = withObservable;
|
||||
this.scheduler = scheduler;
|
||||
}
|
||||
call(subscriber, source) {
|
||||
return source.subscribe(new TimeoutWithSubscriber(subscriber, this.absoluteTimeout, this.waitFor, this.withObservable, this.scheduler));
|
||||
}
|
||||
}
|
||||
class TimeoutWithSubscriber extends SimpleOuterSubscriber {
|
||||
constructor(destination, absoluteTimeout, waitFor, withObservable, scheduler) {
|
||||
super(destination);
|
||||
this.absoluteTimeout = absoluteTimeout;
|
||||
this.waitFor = waitFor;
|
||||
this.withObservable = withObservable;
|
||||
this.scheduler = scheduler;
|
||||
this.scheduleTimeout();
|
||||
}
|
||||
static dispatchTimeout(subscriber) {
|
||||
const { withObservable } = subscriber;
|
||||
subscriber._unsubscribeAndRecycle();
|
||||
subscriber.add(innerSubscribe(withObservable, new SimpleInnerSubscriber(subscriber)));
|
||||
}
|
||||
scheduleTimeout() {
|
||||
const { action } = this;
|
||||
if (action) {
|
||||
this.action = action.schedule(this, this.waitFor);
|
||||
}
|
||||
else {
|
||||
this.add(this.action = this.scheduler.schedule(TimeoutWithSubscriber.dispatchTimeout, this.waitFor, this));
|
||||
}
|
||||
}
|
||||
_next(value) {
|
||||
if (!this.absoluteTimeout) {
|
||||
this.scheduleTimeout();
|
||||
}
|
||||
super._next(value);
|
||||
}
|
||||
_unsubscribe() {
|
||||
this.action = undefined;
|
||||
this.scheduler = null;
|
||||
this.withObservable = null;
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=timeoutWith.js.map
|
||||
@@ -0,0 +1 @@
|
||||
module.exports={C:{"47":0.01136,"60":0.02271,"68":0.01136,"78":0.00379,"91":0.01136,"96":0.02271,"102":0.12112,"106":0.00379,"107":0.0265,"108":2.08554,"109":1.4648,_:"2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 48 49 50 51 52 53 54 55 56 57 58 59 61 62 63 64 65 66 67 69 70 71 72 73 74 75 76 77 79 80 81 82 83 84 85 86 87 88 89 90 92 93 94 95 97 98 99 100 101 103 104 105 110 111 3.5 3.6"},D:{"11":0.01514,"34":0.00379,"38":0.00379,"42":0.00757,"47":0.00757,"49":0.06056,"55":0.00379,"56":0.00757,"63":0.10598,"65":0.01136,"68":0.00379,"69":0.04921,"75":0.04542,"77":0.01514,"78":0.03028,"79":0.05299,"81":0.04164,"83":0.01136,"84":0.02271,"85":0.00757,"86":0.28009,"87":0.00379,"89":0.03407,"90":0.00757,"92":0.00757,"95":0.00757,"97":0.13248,"98":0.01136,"99":0.05299,"100":0.00379,"101":0.00379,"102":0.04542,"103":0.03407,"104":0.02271,"105":0.01514,"106":0.11355,"107":0.05299,"108":6.56319,"109":9.20512,"110":0.01514,_:"4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 35 36 37 39 40 41 43 44 45 46 48 50 51 52 53 54 57 58 59 60 61 62 64 66 67 70 71 72 73 74 76 80 88 91 93 94 96 111 112"},F:{"79":0.02271,"85":0.00757,"92":0.01136,"93":0.02271,"94":1.88115,_:"9 11 12 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 60 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 80 81 82 83 84 86 87 88 89 90 91 9.5-9.6 10.5 10.6 11.1 11.5 11.6 12.1","10.0-10.1":0},B:{"12":0.01136,"13":0.02271,"14":0.00379,"15":0.16654,"16":0.08706,"17":0.00757,"18":0.08706,"84":0.01136,"90":0.00379,"92":0.02271,"98":0.00379,"99":0.00379,"105":0.04164,"106":0.00757,"107":0.03028,"108":1.97577,"109":1.79788,_:"79 80 81 83 85 86 87 88 89 91 93 94 95 96 97 100 101 102 103 104"},E:{"4":0,"11":0.00379,_:"0 5 6 7 8 9 10 12 13 14 15 3.1 3.2 5.1 6.1 7.1 9.1 10.1 11.1 15.1 15.2-15.3 15.4 15.5 16.3","12.1":0.01514,"13.1":0.10977,"14.1":0.01893,"15.6":0.03785,"16.0":0.00757,"16.1":0.02271,"16.2":0.02271},G:{"8":0,"3.2":0,"4.0-4.1":0,"4.2-4.3":0,"5.0-5.1":0.01123,"6.0-6.1":0,"7.0-7.1":0.16712,"8.1-8.4":0,"9.0-9.2":0.0014,"9.3":0.2879,"10.0-10.2":0.0014,"10.3":0.42974,"11.0-11.2":0.04354,"11.3-11.4":0.08567,"12.0-12.1":0.02949,"12.2-12.5":5.27482,"13.0-13.1":0.0014,"13.2":0,"13.3":0.00562,"13.4-13.7":0.2879,"14.0-14.4":0.14044,"14.5-14.8":0.2893,"15.0-15.1":0.5154,"15.2-15.3":0.27385,"15.4":0.11656,"15.5":0.27526,"15.6":0.72747,"16.0":0.56596,"16.1":0.59124,"16.2":1.12069,"16.3":0.17976},P:{"4":0.14812,"5.0-5.4":0.12832,"6.2-6.4":0.03948,"7.2-7.4":0.18231,"8.2":0,"9.2":0.03418,"10.1":0,"11.1-11.2":0.02961,"12.0":0,"13.0":0.00987,"14.0":0.02279,"15.0":0.01139,"16.0":0.01139,"17.0":0.13673,"18.0":0.04558,"19.0":0.36461},I:{"0":0,"3":0,"4":0.00016,"2.1":0,"2.2":0,"2.3":0,"4.1":0.00126,"4.2-4.3":0.00138,"4.4":0,"4.4.3-4.4.4":0.05313},K:{_:"0 10 11 12 11.1 11.5 12.1"},A:{"11":0.0265,_:"6 7 8 9 10 5.5"},J:{"7":0,"10":0},N:{"10":0,"11":0},R:{_:"0"},M:{"0":0.04351},Q:{"13.1":0.03729},O:{"0":0.42262},H:{"0":0.84729},L:{"0":57.73038},S:{"2.5":0.48477}};
|
||||
@@ -0,0 +1,14 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var zip_1 = require("../observable/zip");
|
||||
function zip() {
|
||||
var observables = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
observables[_i] = arguments[_i];
|
||||
}
|
||||
return function zipOperatorFunction(source) {
|
||||
return source.lift.call(zip_1.zip.apply(void 0, [source].concat(observables)));
|
||||
};
|
||||
}
|
||||
exports.zip = zip;
|
||||
//# sourceMappingURL=zip.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"startWith.js","sources":["../../src/internal/operators/startWith.ts"],"names":[],"mappings":";;AACA,+CAA8C;AAC9C,mDAAkD;AAiElD,SAAgB,SAAS;IAAO,eAAkC;SAAlC,UAAkC,EAAlC,qBAAkC,EAAlC,IAAkC;QAAlC,0BAAkC;;IAChE,IAAM,SAAS,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAkB,CAAC;IAC3D,IAAI,yBAAW,CAAC,SAAS,CAAC,EAAE;QAE1B,KAAK,CAAC,GAAG,EAAE,CAAC;QACZ,OAAO,UAAC,MAAqB,IAAK,OAAA,eAAM,CAAC,KAAY,EAAE,MAAM,EAAE,SAAS,CAAC,EAAvC,CAAuC,CAAC;KAC3E;SAAM;QACL,OAAO,UAAC,MAAqB,IAAK,OAAA,eAAM,CAAC,KAAY,EAAE,MAAM,CAAC,EAA5B,CAA4B,CAAC;KAChE;AACH,CAAC;AATD,8BASC"}
|
||||
@@ -0,0 +1,6 @@
|
||||
/**
|
||||
* Abort signal
|
||||
*
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal
|
||||
*/
|
||||
export declare type Signal = any;
|
||||
@@ -0,0 +1,8 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var Observable_1 = require("../Observable");
|
||||
function isObservable(obj) {
|
||||
return !!obj && (obj instanceof Observable_1.Observable || (typeof obj.lift === 'function' && typeof obj.subscribe === 'function'));
|
||||
}
|
||||
exports.isObservable = isObservable;
|
||||
//# sourceMappingURL=isObservable.js.map
|
||||
@@ -0,0 +1,4 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
require("rxjs-compat/add/operator/race");
|
||||
//# sourceMappingURL=race.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"pipe.js","sources":["../src/util/pipe.ts"],"names":[],"mappings":";;;;;AAAA,2CAAsC"}
|
||||
@@ -0,0 +1,4 @@
|
||||
import Block from '../../Block';
|
||||
import Action from '../../../nodes/Action';
|
||||
export default function add_actions(block: Block, target: string, actions: Action[]): void;
|
||||
export declare function add_action(block: Block, target: string, action: Action): void;
|
||||
@@ -0,0 +1,60 @@
|
||||
"use strict";
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
}
|
||||
return function (d, b) {
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var Subscriber_1 = require("../Subscriber");
|
||||
var async_1 = require("../scheduler/async");
|
||||
function sampleTime(period, scheduler) {
|
||||
if (scheduler === void 0) { scheduler = async_1.async; }
|
||||
return function (source) { return source.lift(new SampleTimeOperator(period, scheduler)); };
|
||||
}
|
||||
exports.sampleTime = sampleTime;
|
||||
var SampleTimeOperator = (function () {
|
||||
function SampleTimeOperator(period, scheduler) {
|
||||
this.period = period;
|
||||
this.scheduler = scheduler;
|
||||
}
|
||||
SampleTimeOperator.prototype.call = function (subscriber, source) {
|
||||
return source.subscribe(new SampleTimeSubscriber(subscriber, this.period, this.scheduler));
|
||||
};
|
||||
return SampleTimeOperator;
|
||||
}());
|
||||
var SampleTimeSubscriber = (function (_super) {
|
||||
__extends(SampleTimeSubscriber, _super);
|
||||
function SampleTimeSubscriber(destination, period, scheduler) {
|
||||
var _this = _super.call(this, destination) || this;
|
||||
_this.period = period;
|
||||
_this.scheduler = scheduler;
|
||||
_this.hasValue = false;
|
||||
_this.add(scheduler.schedule(dispatchNotification, period, { subscriber: _this, period: period }));
|
||||
return _this;
|
||||
}
|
||||
SampleTimeSubscriber.prototype._next = function (value) {
|
||||
this.lastValue = value;
|
||||
this.hasValue = true;
|
||||
};
|
||||
SampleTimeSubscriber.prototype.notifyNext = function () {
|
||||
if (this.hasValue) {
|
||||
this.hasValue = false;
|
||||
this.destination.next(this.lastValue);
|
||||
}
|
||||
};
|
||||
return SampleTimeSubscriber;
|
||||
}(Subscriber_1.Subscriber));
|
||||
function dispatchNotification(state) {
|
||||
var subscriber = state.subscriber, period = state.period;
|
||||
subscriber.notifyNext();
|
||||
this.schedule(state, period);
|
||||
}
|
||||
//# sourceMappingURL=sampleTime.js.map
|
||||
@@ -0,0 +1,113 @@
|
||||
/** PURE_IMPORTS_START _Observable,_AsyncSubject,_operators_map,_util_canReportError,_util_isScheduler,_util_isArray PURE_IMPORTS_END */
|
||||
import { Observable } from '../Observable';
|
||||
import { AsyncSubject } from '../AsyncSubject';
|
||||
import { map } from '../operators/map';
|
||||
import { canReportError } from '../util/canReportError';
|
||||
import { isScheduler } from '../util/isScheduler';
|
||||
import { isArray } from '../util/isArray';
|
||||
export function bindNodeCallback(callbackFunc, resultSelector, scheduler) {
|
||||
if (resultSelector) {
|
||||
if (isScheduler(resultSelector)) {
|
||||
scheduler = resultSelector;
|
||||
}
|
||||
else {
|
||||
return function () {
|
||||
var args = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
args[_i] = arguments[_i];
|
||||
}
|
||||
return bindNodeCallback(callbackFunc, scheduler).apply(void 0, args).pipe(map(function (args) { return isArray(args) ? resultSelector.apply(void 0, args) : resultSelector(args); }));
|
||||
};
|
||||
}
|
||||
}
|
||||
return function () {
|
||||
var args = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
args[_i] = arguments[_i];
|
||||
}
|
||||
var params = {
|
||||
subject: undefined,
|
||||
args: args,
|
||||
callbackFunc: callbackFunc,
|
||||
scheduler: scheduler,
|
||||
context: this,
|
||||
};
|
||||
return new Observable(function (subscriber) {
|
||||
var context = params.context;
|
||||
var subject = params.subject;
|
||||
if (!scheduler) {
|
||||
if (!subject) {
|
||||
subject = params.subject = new AsyncSubject();
|
||||
var handler = function () {
|
||||
var innerArgs = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
innerArgs[_i] = arguments[_i];
|
||||
}
|
||||
var err = innerArgs.shift();
|
||||
if (err) {
|
||||
subject.error(err);
|
||||
return;
|
||||
}
|
||||
subject.next(innerArgs.length <= 1 ? innerArgs[0] : innerArgs);
|
||||
subject.complete();
|
||||
};
|
||||
try {
|
||||
callbackFunc.apply(context, args.concat([handler]));
|
||||
}
|
||||
catch (err) {
|
||||
if (canReportError(subject)) {
|
||||
subject.error(err);
|
||||
}
|
||||
else {
|
||||
console.warn(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
return subject.subscribe(subscriber);
|
||||
}
|
||||
else {
|
||||
return scheduler.schedule(dispatch, 0, { params: params, subscriber: subscriber, context: context });
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
function dispatch(state) {
|
||||
var _this = this;
|
||||
var params = state.params, subscriber = state.subscriber, context = state.context;
|
||||
var callbackFunc = params.callbackFunc, args = params.args, scheduler = params.scheduler;
|
||||
var subject = params.subject;
|
||||
if (!subject) {
|
||||
subject = params.subject = new AsyncSubject();
|
||||
var handler = function () {
|
||||
var innerArgs = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
innerArgs[_i] = arguments[_i];
|
||||
}
|
||||
var err = innerArgs.shift();
|
||||
if (err) {
|
||||
_this.add(scheduler.schedule(dispatchError, 0, { err: err, subject: subject }));
|
||||
}
|
||||
else {
|
||||
var value = innerArgs.length <= 1 ? innerArgs[0] : innerArgs;
|
||||
_this.add(scheduler.schedule(dispatchNext, 0, { value: value, subject: subject }));
|
||||
}
|
||||
};
|
||||
try {
|
||||
callbackFunc.apply(context, args.concat([handler]));
|
||||
}
|
||||
catch (err) {
|
||||
this.add(scheduler.schedule(dispatchError, 0, { err: err, subject: subject }));
|
||||
}
|
||||
}
|
||||
this.add(subject.subscribe(subscriber));
|
||||
}
|
||||
function dispatchNext(arg) {
|
||||
var value = arg.value, subject = arg.subject;
|
||||
subject.next(value);
|
||||
subject.complete();
|
||||
}
|
||||
function dispatchError(arg) {
|
||||
var err = arg.err, subject = arg.subject;
|
||||
subject.error(err);
|
||||
}
|
||||
//# sourceMappingURL=bindNodeCallback.js.map
|
||||
@@ -0,0 +1 @@
|
||||
module.exports={A:{A:{"2":"J E F G A B BC"},B:{"1":"P Q R S T U V W X Y Z a b c d f g h i j k l m n o p q r s D t","2":"C K L H M N O"},C:{"1":"HB IB JB KB LB MB NB OB PB QB RB SB TB UB VB WB XB YB uB ZB vB aB bB cB dB eB fB gB hB iB jB kB e lB mB nB oB pB P Q R wB S T U V W X Y Z a b c d f g h i j k l m n o p q r s D t xB yB","2":"0 1 2 3 4 5 6 7 8 9 CC tB I u J E F G A B C K L H M N O v w x y z AB DC EC","194":"BB CB DB EB FB GB"},D:{"1":"BB CB DB EB FB GB HB IB JB KB LB MB NB OB PB QB RB SB TB UB VB WB XB YB uB ZB vB aB bB cB dB eB fB gB hB iB jB kB e lB mB nB oB pB P Q R S T U V W X Y Z a b c d f g h i j k l m n o p q r s D t xB yB FC","2":"0 1 2 3 4 5 6 7 8 9 I u J E F G A B C K L H M N O v w x y z AB"},E:{"1":"A B C K L H 0B qB rB 1B LC MC 2B 3B 4B 5B sB 6B 7B 8B NC","2":"I u J E F G GC zB HC IC JC KC"},F:{"1":"0 1 2 3 4 5 6 7 8 9 y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB PB QB RB SB TB UB VB WB XB YB ZB aB bB cB dB eB fB gB hB iB jB kB e lB mB nB oB pB P Q R wB S T U V W X Y Z a b c d","2":"G B C H M N O v w x OC PC QC RC qB 9B SC rB"},G:{"1":"aC bC cC dC eC fC gC hC iC jC kC lC mC 2B 3B 4B 5B sB 6B 7B 8B","2":"F zB TC AC UC VC WC XC YC ZC"},H:{"2":"nC"},I:{"1":"D","2":"tB I oC pC qC rC AC sC tC"},J:{"2":"E A"},K:{"1":"e","2":"A B C qB 9B rB"},L:{"1":"D"},M:{"1":"D"},N:{"2":"A B"},O:{"1":"uC"},P:{"1":"I vC wC xC yC zC 0B 0C 1C 2C 3C 4C sB 5C 6C 7C"},Q:{"1":"1B"},R:{"1":"8C"},S:{"1":"9C"}},B:5,C:"CSS Font Loading"};
|
||||
@@ -0,0 +1,54 @@
|
||||
import { ObservableInput } from '../types';
|
||||
import { Observable } from '../Observable';
|
||||
/**
|
||||
* Splits the source Observable into two, one with values that satisfy a
|
||||
* predicate, and another with values that don't satisfy the predicate.
|
||||
*
|
||||
* <span class="informal">It's like {@link filter}, but returns two Observables:
|
||||
* one like the output of {@link filter}, and the other with values that did not
|
||||
* pass the condition.</span>
|
||||
*
|
||||
* 
|
||||
*
|
||||
* `partition` outputs an array with two Observables that partition the values
|
||||
* from the source Observable through the given `predicate` function. The first
|
||||
* Observable in that array emits source values for which the predicate argument
|
||||
* returns true. The second Observable emits source values for which the
|
||||
* predicate returns false. The first behaves like {@link filter} and the second
|
||||
* behaves like {@link filter} with the predicate negated.
|
||||
*
|
||||
* ## Example
|
||||
* Partition a set of numbers into odds and evens observables
|
||||
* ```ts
|
||||
* import { of, partition } from 'rxjs';
|
||||
*
|
||||
* const observableValues = of(1, 2, 3, 4, 5, 6);
|
||||
* const [evens$, odds$] = partition(observableValues, (value, index) => value % 2 === 0);
|
||||
*
|
||||
* odds$.subscribe(x => console.log('odds', x));
|
||||
* evens$.subscribe(x => console.log('evens', x));
|
||||
*
|
||||
* // Logs:
|
||||
* // odds 1
|
||||
* // odds 3
|
||||
* // odds 5
|
||||
* // evens 2
|
||||
* // evens 4
|
||||
* // evens 6
|
||||
* ```
|
||||
*
|
||||
* @see {@link filter}
|
||||
*
|
||||
* @param {function(value: T, index: number): boolean} predicate A function that
|
||||
* evaluates each value emitted by the source Observable. If it returns `true`,
|
||||
* the value is emitted on the first Observable in the returned array, if
|
||||
* `false` the value is emitted on the second Observable in the array. The
|
||||
* `index` parameter is the number `i` for the i-th source emission that has
|
||||
* happened since the subscription, starting from the number `0`.
|
||||
* @param {any} [thisArg] An optional argument to determine the value of `this`
|
||||
* in the `predicate` function.
|
||||
* @return {[Observable<T>, Observable<T>]} An array with two Observables: one
|
||||
* with values that passed the predicate, and another with values that did not
|
||||
* pass the predicate.
|
||||
*/
|
||||
export declare function partition<T>(source: ObservableInput<T>, predicate: (value: T, index: number) => boolean, thisArg?: any): [Observable<T>, Observable<T>];
|
||||
@@ -0,0 +1 @@
|
||||
module.exports={A:{A:{"2":"J E BC","260":"F","388":"G A B"},B:{"1":"H M N O P Q R S T U V W X Y Z a b c d f g h i j k l m n o p q r s D t","388":"C K L"},C:{"1":"0 1 2 3 4 5 6 7 8 9 CC tB I u J E F G A B C K L H M N O v w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB PB QB RB SB TB UB VB WB XB YB uB ZB vB aB bB cB dB eB fB gB hB iB jB kB e lB mB nB oB pB P Q R wB S T U V W X Y Z a b c d f g h i j k l m n o p q r s D t xB yB DC EC"},D:{"1":"0 1 2 3 4 5 6 7 8 9 I u J E F G A B C K L H M N O v w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB PB QB RB SB TB UB VB WB XB YB uB ZB vB aB bB cB dB eB fB gB hB iB jB kB e lB mB nB oB pB P Q R S T U V W X Y Z a b c d f g h i j k l m n o p q r s D t xB yB FC"},E:{"1":"I u J E F G A B C K L H GC zB HC IC JC KC 0B qB rB 1B LC MC 2B 3B 4B 5B sB 6B 7B 8B NC"},F:{"1":"0 1 2 3 4 5 6 7 8 9 C H M N O v w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB PB QB RB SB TB UB VB WB XB YB ZB aB bB cB dB eB fB gB hB iB jB kB e lB mB nB oB pB P Q R wB S T U V W X Y Z a b c d SC","129":"rB","260":"G B OC PC QC RC qB 9B"},G:{"1":"F zB TC AC UC VC WC XC YC ZC aC bC cC dC eC fC gC hC iC jC kC lC mC 2B 3B 4B 5B sB 6B 7B 8B"},H:{"2":"nC"},I:{"1":"tB I D oC pC qC rC AC sC tC"},J:{"1":"E A"},K:{"1":"C e rB","260":"A B qB 9B"},L:{"1":"D"},M:{"1":"D"},N:{"388":"A B"},O:{"1":"uC"},P:{"1":"I vC wC xC yC zC 0B 0C 1C 2C 3C 4C sB 5C 6C 7C"},Q:{"1":"1B"},R:{"1":"8C"},S:{"1":"9C"}},B:4,C:"CSS outline properties"};
|
||||
@@ -0,0 +1,4 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
require("rxjs-compat/add/operator/window");
|
||||
//# sourceMappingURL=window.js.map
|
||||
@@ -0,0 +1 @@
|
||||
module.exports={A:{A:{"8":"J E F G A B BC"},B:{"1":"C K L H M N O P Q R S T U V W X Y Z a b c d f g h i j k l m n o p q r s D t"},C:{"1":"5 6 7 8 9 AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB PB QB RB SB TB UB VB WB XB YB uB ZB vB aB bB cB dB eB fB gB hB iB jB kB e lB mB nB oB pB P Q R wB S T U V W X Y Z a b c d f g h i j k l m n o p q r s D t xB yB","4":"3 4","8":"0 1 2 CC tB I u J E F G A B C K L H M N O v w x y z DC EC"},D:{"1":"9 AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB PB QB RB SB TB UB VB WB XB YB uB ZB vB aB bB cB dB eB fB gB hB iB jB kB e lB mB nB oB pB P Q R S T U V W X Y Z a b c d f g h i j k l m n o p q r s D t xB yB FC","4":"8","8":"0 1 2 3 4 5 6 7 I u J E F G A B C K L H M N O v w x y z"},E:{"1":"F G A B C K L H JC KC 0B qB rB 1B LC MC 2B 3B 4B 5B sB 6B 7B 8B NC","8":"I u J E GC zB HC IC"},F:{"1":"0 1 2 3 4 5 6 7 8 9 w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB PB QB RB SB TB UB VB WB XB YB ZB aB bB cB dB eB fB gB hB iB jB kB e lB mB nB oB pB P Q R wB S T U V W X Y Z a b c d","4":"v","8":"G B C H M N O OC PC QC RC qB 9B SC rB"},G:{"1":"F XC YC ZC aC bC cC dC eC fC gC hC iC jC kC lC mC 2B 3B 4B 5B sB 6B 7B 8B","8":"zB TC AC UC VC WC"},H:{"8":"nC"},I:{"1":"D tC","8":"tB I oC pC qC rC AC sC"},J:{"8":"E A"},K:{"1":"e","8":"A B C qB 9B rB"},L:{"1":"D"},M:{"1":"D"},N:{"8":"A B"},O:{"1":"uC"},P:{"1":"I vC wC xC yC zC 0B 0C 1C 2C 3C 4C sB 5C 6C 7C"},Q:{"1":"1B"},R:{"1":"8C"},S:{"1":"9C"}},B:6,C:"Promises"};
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,7 @@
|
||||
"use strict";
|
||||
function __export(m) {
|
||||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
||||
}
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
__export(require("rxjs-compat/operator/audit"));
|
||||
//# sourceMappingURL=audit.js.map
|
||||
@@ -0,0 +1 @@
|
||||
import 'rxjs-compat/add/operator/dematerialize';
|
||||
@@ -0,0 +1,130 @@
|
||||
import { getUserAgent } from 'universal-user-agent';
|
||||
import { Collection } from 'before-after-hook';
|
||||
import { request } from '@octokit/request';
|
||||
import { withCustomRequest } from '@octokit/graphql';
|
||||
import { createTokenAuth } from '@octokit/auth-token';
|
||||
|
||||
const VERSION = "3.6.0";
|
||||
|
||||
class Octokit {
|
||||
constructor(options = {}) {
|
||||
const hook = new Collection();
|
||||
const requestDefaults = {
|
||||
baseUrl: request.endpoint.DEFAULTS.baseUrl,
|
||||
headers: {},
|
||||
request: Object.assign({}, options.request, {
|
||||
// @ts-ignore internal usage only, no need to type
|
||||
hook: hook.bind(null, "request"),
|
||||
}),
|
||||
mediaType: {
|
||||
previews: [],
|
||||
format: "",
|
||||
},
|
||||
};
|
||||
// prepend default user agent with `options.userAgent` if set
|
||||
requestDefaults.headers["user-agent"] = [
|
||||
options.userAgent,
|
||||
`octokit-core.js/${VERSION} ${getUserAgent()}`,
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(" ");
|
||||
if (options.baseUrl) {
|
||||
requestDefaults.baseUrl = options.baseUrl;
|
||||
}
|
||||
if (options.previews) {
|
||||
requestDefaults.mediaType.previews = options.previews;
|
||||
}
|
||||
if (options.timeZone) {
|
||||
requestDefaults.headers["time-zone"] = options.timeZone;
|
||||
}
|
||||
this.request = request.defaults(requestDefaults);
|
||||
this.graphql = withCustomRequest(this.request).defaults(requestDefaults);
|
||||
this.log = Object.assign({
|
||||
debug: () => { },
|
||||
info: () => { },
|
||||
warn: console.warn.bind(console),
|
||||
error: console.error.bind(console),
|
||||
}, options.log);
|
||||
this.hook = hook;
|
||||
// (1) If neither `options.authStrategy` nor `options.auth` are set, the `octokit` instance
|
||||
// is unauthenticated. The `this.auth()` method is a no-op and no request hook is registered.
|
||||
// (2) If only `options.auth` is set, use the default token authentication strategy.
|
||||
// (3) If `options.authStrategy` is set then use it and pass in `options.auth`. Always pass own request as many strategies accept a custom request instance.
|
||||
// TODO: type `options.auth` based on `options.authStrategy`.
|
||||
if (!options.authStrategy) {
|
||||
if (!options.auth) {
|
||||
// (1)
|
||||
this.auth = async () => ({
|
||||
type: "unauthenticated",
|
||||
});
|
||||
}
|
||||
else {
|
||||
// (2)
|
||||
const auth = createTokenAuth(options.auth);
|
||||
// @ts-ignore ¯\_(ツ)_/¯
|
||||
hook.wrap("request", auth.hook);
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
else {
|
||||
const { authStrategy, ...otherOptions } = options;
|
||||
const auth = authStrategy(Object.assign({
|
||||
request: this.request,
|
||||
log: this.log,
|
||||
// we pass the current octokit instance as well as its constructor options
|
||||
// to allow for authentication strategies that return a new octokit instance
|
||||
// that shares the same internal state as the current one. The original
|
||||
// requirement for this was the "event-octokit" authentication strategy
|
||||
// of https://github.com/probot/octokit-auth-probot.
|
||||
octokit: this,
|
||||
octokitOptions: otherOptions,
|
||||
}, options.auth));
|
||||
// @ts-ignore ¯\_(ツ)_/¯
|
||||
hook.wrap("request", auth.hook);
|
||||
this.auth = auth;
|
||||
}
|
||||
// apply plugins
|
||||
// https://stackoverflow.com/a/16345172
|
||||
const classConstructor = this.constructor;
|
||||
classConstructor.plugins.forEach((plugin) => {
|
||||
Object.assign(this, plugin(this, options));
|
||||
});
|
||||
}
|
||||
static defaults(defaults) {
|
||||
const OctokitWithDefaults = class extends this {
|
||||
constructor(...args) {
|
||||
const options = args[0] || {};
|
||||
if (typeof defaults === "function") {
|
||||
super(defaults(options));
|
||||
return;
|
||||
}
|
||||
super(Object.assign({}, defaults, options, options.userAgent && defaults.userAgent
|
||||
? {
|
||||
userAgent: `${options.userAgent} ${defaults.userAgent}`,
|
||||
}
|
||||
: null));
|
||||
}
|
||||
};
|
||||
return OctokitWithDefaults;
|
||||
}
|
||||
/**
|
||||
* Attach a plugin (or many) to your Octokit instance.
|
||||
*
|
||||
* @example
|
||||
* const API = Octokit.plugin(plugin1, plugin2, plugin3, ...)
|
||||
*/
|
||||
static plugin(...newPlugins) {
|
||||
var _a;
|
||||
const currentPlugins = this.plugins;
|
||||
const NewOctokit = (_a = class extends this {
|
||||
},
|
||||
_a.plugins = currentPlugins.concat(newPlugins.filter((plugin) => !currentPlugins.includes(plugin))),
|
||||
_a);
|
||||
return NewOctokit;
|
||||
}
|
||||
}
|
||||
Octokit.VERSION = VERSION;
|
||||
Octokit.plugins = [];
|
||||
|
||||
export { Octokit };
|
||||
//# sourceMappingURL=index.js.map
|
||||
@@ -0,0 +1 @@
|
||||
export * from 'rxjs-compat/operator/distinct';
|
||||
@@ -0,0 +1,548 @@
|
||||
import { assertNotStrictEqual, } from './typings/common-types.js';
|
||||
import { objFilter } from './utils/obj-filter.js';
|
||||
import { YError } from './yerror.js';
|
||||
import setBlocking from './utils/set-blocking.js';
|
||||
export function usage(yargs, y18n, shim) {
|
||||
const __ = y18n.__;
|
||||
const self = {};
|
||||
const fails = [];
|
||||
self.failFn = function failFn(f) {
|
||||
fails.push(f);
|
||||
};
|
||||
let failMessage = null;
|
||||
let showHelpOnFail = true;
|
||||
self.showHelpOnFail = function showHelpOnFailFn(arg1 = true, arg2) {
|
||||
function parseFunctionArgs() {
|
||||
return typeof arg1 === 'string' ? [true, arg1] : [arg1, arg2];
|
||||
}
|
||||
const [enabled, message] = parseFunctionArgs();
|
||||
failMessage = message;
|
||||
showHelpOnFail = enabled;
|
||||
return self;
|
||||
};
|
||||
let failureOutput = false;
|
||||
self.fail = function fail(msg, err) {
|
||||
const logger = yargs._getLoggerInstance();
|
||||
if (fails.length) {
|
||||
for (let i = fails.length - 1; i >= 0; --i) {
|
||||
fails[i](msg, err, self);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (yargs.getExitProcess())
|
||||
setBlocking(true);
|
||||
if (!failureOutput) {
|
||||
failureOutput = true;
|
||||
if (showHelpOnFail) {
|
||||
yargs.showHelp('error');
|
||||
logger.error();
|
||||
}
|
||||
if (msg || err)
|
||||
logger.error(msg || err);
|
||||
if (failMessage) {
|
||||
if (msg || err)
|
||||
logger.error('');
|
||||
logger.error(failMessage);
|
||||
}
|
||||
}
|
||||
err = err || new YError(msg);
|
||||
if (yargs.getExitProcess()) {
|
||||
return yargs.exit(1);
|
||||
}
|
||||
else if (yargs._hasParseCallback()) {
|
||||
return yargs.exit(1, err);
|
||||
}
|
||||
else {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
};
|
||||
let usages = [];
|
||||
let usageDisabled = false;
|
||||
self.usage = (msg, description) => {
|
||||
if (msg === null) {
|
||||
usageDisabled = true;
|
||||
usages = [];
|
||||
return self;
|
||||
}
|
||||
usageDisabled = false;
|
||||
usages.push([msg, description || '']);
|
||||
return self;
|
||||
};
|
||||
self.getUsage = () => {
|
||||
return usages;
|
||||
};
|
||||
self.getUsageDisabled = () => {
|
||||
return usageDisabled;
|
||||
};
|
||||
self.getPositionalGroupName = () => {
|
||||
return __('Positionals:');
|
||||
};
|
||||
let examples = [];
|
||||
self.example = (cmd, description) => {
|
||||
examples.push([cmd, description || '']);
|
||||
};
|
||||
let commands = [];
|
||||
self.command = function command(cmd, description, isDefault, aliases, deprecated = false) {
|
||||
if (isDefault) {
|
||||
commands = commands.map(cmdArray => {
|
||||
cmdArray[2] = false;
|
||||
return cmdArray;
|
||||
});
|
||||
}
|
||||
commands.push([cmd, description || '', isDefault, aliases, deprecated]);
|
||||
};
|
||||
self.getCommands = () => commands;
|
||||
let descriptions = {};
|
||||
self.describe = function describe(keyOrKeys, desc) {
|
||||
if (Array.isArray(keyOrKeys)) {
|
||||
keyOrKeys.forEach(k => {
|
||||
self.describe(k, desc);
|
||||
});
|
||||
}
|
||||
else if (typeof keyOrKeys === 'object') {
|
||||
Object.keys(keyOrKeys).forEach(k => {
|
||||
self.describe(k, keyOrKeys[k]);
|
||||
});
|
||||
}
|
||||
else {
|
||||
descriptions[keyOrKeys] = desc;
|
||||
}
|
||||
};
|
||||
self.getDescriptions = () => descriptions;
|
||||
let epilogs = [];
|
||||
self.epilog = msg => {
|
||||
epilogs.push(msg);
|
||||
};
|
||||
let wrapSet = false;
|
||||
let wrap;
|
||||
self.wrap = cols => {
|
||||
wrapSet = true;
|
||||
wrap = cols;
|
||||
};
|
||||
function getWrap() {
|
||||
if (!wrapSet) {
|
||||
wrap = windowWidth();
|
||||
wrapSet = true;
|
||||
}
|
||||
return wrap;
|
||||
}
|
||||
const deferY18nLookupPrefix = '__yargsString__:';
|
||||
self.deferY18nLookup = str => deferY18nLookupPrefix + str;
|
||||
self.help = function help() {
|
||||
if (cachedHelpMessage)
|
||||
return cachedHelpMessage;
|
||||
normalizeAliases();
|
||||
const base$0 = yargs.customScriptName
|
||||
? yargs.$0
|
||||
: shim.path.basename(yargs.$0);
|
||||
const demandedOptions = yargs.getDemandedOptions();
|
||||
const demandedCommands = yargs.getDemandedCommands();
|
||||
const deprecatedOptions = yargs.getDeprecatedOptions();
|
||||
const groups = yargs.getGroups();
|
||||
const options = yargs.getOptions();
|
||||
let keys = [];
|
||||
keys = keys.concat(Object.keys(descriptions));
|
||||
keys = keys.concat(Object.keys(demandedOptions));
|
||||
keys = keys.concat(Object.keys(demandedCommands));
|
||||
keys = keys.concat(Object.keys(options.default));
|
||||
keys = keys.filter(filterHiddenOptions);
|
||||
keys = Object.keys(keys.reduce((acc, key) => {
|
||||
if (key !== '_')
|
||||
acc[key] = true;
|
||||
return acc;
|
||||
}, {}));
|
||||
const theWrap = getWrap();
|
||||
const ui = shim.cliui({
|
||||
width: theWrap,
|
||||
wrap: !!theWrap,
|
||||
});
|
||||
if (!usageDisabled) {
|
||||
if (usages.length) {
|
||||
usages.forEach(usage => {
|
||||
ui.div(`${usage[0].replace(/\$0/g, base$0)}`);
|
||||
if (usage[1]) {
|
||||
ui.div({ text: `${usage[1]}`, padding: [1, 0, 0, 0] });
|
||||
}
|
||||
});
|
||||
ui.div();
|
||||
}
|
||||
else if (commands.length) {
|
||||
let u = null;
|
||||
if (demandedCommands._) {
|
||||
u = `${base$0} <${__('command')}>\n`;
|
||||
}
|
||||
else {
|
||||
u = `${base$0} [${__('command')}]\n`;
|
||||
}
|
||||
ui.div(`${u}`);
|
||||
}
|
||||
}
|
||||
if (commands.length) {
|
||||
ui.div(__('Commands:'));
|
||||
const context = yargs.getContext();
|
||||
const parentCommands = context.commands.length
|
||||
? `${context.commands.join(' ')} `
|
||||
: '';
|
||||
if (yargs.getParserConfiguration()['sort-commands'] === true) {
|
||||
commands = commands.sort((a, b) => a[0].localeCompare(b[0]));
|
||||
}
|
||||
commands.forEach(command => {
|
||||
const commandString = `${base$0} ${parentCommands}${command[0].replace(/^\$0 ?/, '')}`;
|
||||
ui.span({
|
||||
text: commandString,
|
||||
padding: [0, 2, 0, 2],
|
||||
width: maxWidth(commands, theWrap, `${base$0}${parentCommands}`) + 4,
|
||||
}, { text: command[1] });
|
||||
const hints = [];
|
||||
if (command[2])
|
||||
hints.push(`[${__('default')}]`);
|
||||
if (command[3] && command[3].length) {
|
||||
hints.push(`[${__('aliases:')} ${command[3].join(', ')}]`);
|
||||
}
|
||||
if (command[4]) {
|
||||
if (typeof command[4] === 'string') {
|
||||
hints.push(`[${__('deprecated: %s', command[4])}]`);
|
||||
}
|
||||
else {
|
||||
hints.push(`[${__('deprecated')}]`);
|
||||
}
|
||||
}
|
||||
if (hints.length) {
|
||||
ui.div({
|
||||
text: hints.join(' '),
|
||||
padding: [0, 0, 0, 2],
|
||||
align: 'right',
|
||||
});
|
||||
}
|
||||
else {
|
||||
ui.div();
|
||||
}
|
||||
});
|
||||
ui.div();
|
||||
}
|
||||
const aliasKeys = (Object.keys(options.alias) || []).concat(Object.keys(yargs.parsed.newAliases) || []);
|
||||
keys = keys.filter(key => !yargs.parsed.newAliases[key] &&
|
||||
aliasKeys.every(alias => (options.alias[alias] || []).indexOf(key) === -1));
|
||||
const defaultGroup = __('Options:');
|
||||
if (!groups[defaultGroup])
|
||||
groups[defaultGroup] = [];
|
||||
addUngroupedKeys(keys, options.alias, groups, defaultGroup);
|
||||
const isLongSwitch = (sw) => /^--/.test(getText(sw));
|
||||
const displayedGroups = Object.keys(groups)
|
||||
.filter(groupName => groups[groupName].length > 0)
|
||||
.map(groupName => {
|
||||
const normalizedKeys = groups[groupName]
|
||||
.filter(filterHiddenOptions)
|
||||
.map(key => {
|
||||
if (~aliasKeys.indexOf(key))
|
||||
return key;
|
||||
for (let i = 0, aliasKey; (aliasKey = aliasKeys[i]) !== undefined; i++) {
|
||||
if (~(options.alias[aliasKey] || []).indexOf(key))
|
||||
return aliasKey;
|
||||
}
|
||||
return key;
|
||||
});
|
||||
return { groupName, normalizedKeys };
|
||||
})
|
||||
.filter(({ normalizedKeys }) => normalizedKeys.length > 0)
|
||||
.map(({ groupName, normalizedKeys }) => {
|
||||
const switches = normalizedKeys.reduce((acc, key) => {
|
||||
acc[key] = [key]
|
||||
.concat(options.alias[key] || [])
|
||||
.map(sw => {
|
||||
if (groupName === self.getPositionalGroupName())
|
||||
return sw;
|
||||
else {
|
||||
return ((/^[0-9]$/.test(sw)
|
||||
? ~options.boolean.indexOf(key)
|
||||
? '-'
|
||||
: '--'
|
||||
: sw.length > 1
|
||||
? '--'
|
||||
: '-') + sw);
|
||||
}
|
||||
})
|
||||
.sort((sw1, sw2) => isLongSwitch(sw1) === isLongSwitch(sw2)
|
||||
? 0
|
||||
: isLongSwitch(sw1)
|
||||
? 1
|
||||
: -1)
|
||||
.join(', ');
|
||||
return acc;
|
||||
}, {});
|
||||
return { groupName, normalizedKeys, switches };
|
||||
});
|
||||
const shortSwitchesUsed = displayedGroups
|
||||
.filter(({ groupName }) => groupName !== self.getPositionalGroupName())
|
||||
.some(({ normalizedKeys, switches }) => !normalizedKeys.every(key => isLongSwitch(switches[key])));
|
||||
if (shortSwitchesUsed) {
|
||||
displayedGroups
|
||||
.filter(({ groupName }) => groupName !== self.getPositionalGroupName())
|
||||
.forEach(({ normalizedKeys, switches }) => {
|
||||
normalizedKeys.forEach(key => {
|
||||
if (isLongSwitch(switches[key])) {
|
||||
switches[key] = addIndentation(switches[key], '-x, '.length);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
displayedGroups.forEach(({ groupName, normalizedKeys, switches }) => {
|
||||
ui.div(groupName);
|
||||
normalizedKeys.forEach(key => {
|
||||
const kswitch = switches[key];
|
||||
let desc = descriptions[key] || '';
|
||||
let type = null;
|
||||
if (~desc.lastIndexOf(deferY18nLookupPrefix))
|
||||
desc = __(desc.substring(deferY18nLookupPrefix.length));
|
||||
if (~options.boolean.indexOf(key))
|
||||
type = `[${__('boolean')}]`;
|
||||
if (~options.count.indexOf(key))
|
||||
type = `[${__('count')}]`;
|
||||
if (~options.string.indexOf(key))
|
||||
type = `[${__('string')}]`;
|
||||
if (~options.normalize.indexOf(key))
|
||||
type = `[${__('string')}]`;
|
||||
if (~options.array.indexOf(key))
|
||||
type = `[${__('array')}]`;
|
||||
if (~options.number.indexOf(key))
|
||||
type = `[${__('number')}]`;
|
||||
const deprecatedExtra = (deprecated) => typeof deprecated === 'string'
|
||||
? `[${__('deprecated: %s', deprecated)}]`
|
||||
: `[${__('deprecated')}]`;
|
||||
const extra = [
|
||||
key in deprecatedOptions
|
||||
? deprecatedExtra(deprecatedOptions[key])
|
||||
: null,
|
||||
type,
|
||||
key in demandedOptions ? `[${__('required')}]` : null,
|
||||
options.choices && options.choices[key]
|
||||
? `[${__('choices:')} ${self.stringifiedValues(options.choices[key])}]`
|
||||
: null,
|
||||
defaultString(options.default[key], options.defaultDescription[key]),
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(' ');
|
||||
ui.span({
|
||||
text: getText(kswitch),
|
||||
padding: [0, 2, 0, 2 + getIndentation(kswitch)],
|
||||
width: maxWidth(switches, theWrap) + 4,
|
||||
}, desc);
|
||||
if (extra)
|
||||
ui.div({ text: extra, padding: [0, 0, 0, 2], align: 'right' });
|
||||
else
|
||||
ui.div();
|
||||
});
|
||||
ui.div();
|
||||
});
|
||||
if (examples.length) {
|
||||
ui.div(__('Examples:'));
|
||||
examples.forEach(example => {
|
||||
example[0] = example[0].replace(/\$0/g, base$0);
|
||||
});
|
||||
examples.forEach(example => {
|
||||
if (example[1] === '') {
|
||||
ui.div({
|
||||
text: example[0],
|
||||
padding: [0, 2, 0, 2],
|
||||
});
|
||||
}
|
||||
else {
|
||||
ui.div({
|
||||
text: example[0],
|
||||
padding: [0, 2, 0, 2],
|
||||
width: maxWidth(examples, theWrap) + 4,
|
||||
}, {
|
||||
text: example[1],
|
||||
});
|
||||
}
|
||||
});
|
||||
ui.div();
|
||||
}
|
||||
if (epilogs.length > 0) {
|
||||
const e = epilogs
|
||||
.map(epilog => epilog.replace(/\$0/g, base$0))
|
||||
.join('\n');
|
||||
ui.div(`${e}\n`);
|
||||
}
|
||||
return ui.toString().replace(/\s*$/, '');
|
||||
};
|
||||
function maxWidth(table, theWrap, modifier) {
|
||||
let width = 0;
|
||||
if (!Array.isArray(table)) {
|
||||
table = Object.values(table).map(v => [v]);
|
||||
}
|
||||
table.forEach(v => {
|
||||
width = Math.max(shim.stringWidth(modifier ? `${modifier} ${getText(v[0])}` : getText(v[0])) + getIndentation(v[0]), width);
|
||||
});
|
||||
if (theWrap)
|
||||
width = Math.min(width, parseInt((theWrap * 0.5).toString(), 10));
|
||||
return width;
|
||||
}
|
||||
function normalizeAliases() {
|
||||
const demandedOptions = yargs.getDemandedOptions();
|
||||
const options = yargs.getOptions();
|
||||
(Object.keys(options.alias) || []).forEach(key => {
|
||||
options.alias[key].forEach(alias => {
|
||||
if (descriptions[alias])
|
||||
self.describe(key, descriptions[alias]);
|
||||
if (alias in demandedOptions)
|
||||
yargs.demandOption(key, demandedOptions[alias]);
|
||||
if (~options.boolean.indexOf(alias))
|
||||
yargs.boolean(key);
|
||||
if (~options.count.indexOf(alias))
|
||||
yargs.count(key);
|
||||
if (~options.string.indexOf(alias))
|
||||
yargs.string(key);
|
||||
if (~options.normalize.indexOf(alias))
|
||||
yargs.normalize(key);
|
||||
if (~options.array.indexOf(alias))
|
||||
yargs.array(key);
|
||||
if (~options.number.indexOf(alias))
|
||||
yargs.number(key);
|
||||
});
|
||||
});
|
||||
}
|
||||
let cachedHelpMessage;
|
||||
self.cacheHelpMessage = function () {
|
||||
cachedHelpMessage = this.help();
|
||||
};
|
||||
self.clearCachedHelpMessage = function () {
|
||||
cachedHelpMessage = undefined;
|
||||
};
|
||||
function addUngroupedKeys(keys, aliases, groups, defaultGroup) {
|
||||
let groupedKeys = [];
|
||||
let toCheck = null;
|
||||
Object.keys(groups).forEach(group => {
|
||||
groupedKeys = groupedKeys.concat(groups[group]);
|
||||
});
|
||||
keys.forEach(key => {
|
||||
toCheck = [key].concat(aliases[key]);
|
||||
if (!toCheck.some(k => groupedKeys.indexOf(k) !== -1)) {
|
||||
groups[defaultGroup].push(key);
|
||||
}
|
||||
});
|
||||
return groupedKeys;
|
||||
}
|
||||
function filterHiddenOptions(key) {
|
||||
return (yargs.getOptions().hiddenOptions.indexOf(key) < 0 ||
|
||||
yargs.parsed.argv[yargs.getOptions().showHiddenOpt]);
|
||||
}
|
||||
self.showHelp = (level) => {
|
||||
const logger = yargs._getLoggerInstance();
|
||||
if (!level)
|
||||
level = 'error';
|
||||
const emit = typeof level === 'function' ? level : logger[level];
|
||||
emit(self.help());
|
||||
};
|
||||
self.functionDescription = fn => {
|
||||
const description = fn.name
|
||||
? shim.Parser.decamelize(fn.name, '-')
|
||||
: __('generated-value');
|
||||
return ['(', description, ')'].join('');
|
||||
};
|
||||
self.stringifiedValues = function stringifiedValues(values, separator) {
|
||||
let string = '';
|
||||
const sep = separator || ', ';
|
||||
const array = [].concat(values);
|
||||
if (!values || !array.length)
|
||||
return string;
|
||||
array.forEach(value => {
|
||||
if (string.length)
|
||||
string += sep;
|
||||
string += JSON.stringify(value);
|
||||
});
|
||||
return string;
|
||||
};
|
||||
function defaultString(value, defaultDescription) {
|
||||
let string = `[${__('default:')} `;
|
||||
if (value === undefined && !defaultDescription)
|
||||
return null;
|
||||
if (defaultDescription) {
|
||||
string += defaultDescription;
|
||||
}
|
||||
else {
|
||||
switch (typeof value) {
|
||||
case 'string':
|
||||
string += `"${value}"`;
|
||||
break;
|
||||
case 'object':
|
||||
string += JSON.stringify(value);
|
||||
break;
|
||||
default:
|
||||
string += value;
|
||||
}
|
||||
}
|
||||
return `${string}]`;
|
||||
}
|
||||
function windowWidth() {
|
||||
const maxWidth = 80;
|
||||
if (shim.process.stdColumns) {
|
||||
return Math.min(maxWidth, shim.process.stdColumns);
|
||||
}
|
||||
else {
|
||||
return maxWidth;
|
||||
}
|
||||
}
|
||||
let version = null;
|
||||
self.version = ver => {
|
||||
version = ver;
|
||||
};
|
||||
self.showVersion = () => {
|
||||
const logger = yargs._getLoggerInstance();
|
||||
logger.log(version);
|
||||
};
|
||||
self.reset = function reset(localLookup) {
|
||||
failMessage = null;
|
||||
failureOutput = false;
|
||||
usages = [];
|
||||
usageDisabled = false;
|
||||
epilogs = [];
|
||||
examples = [];
|
||||
commands = [];
|
||||
descriptions = objFilter(descriptions, k => !localLookup[k]);
|
||||
return self;
|
||||
};
|
||||
const frozens = [];
|
||||
self.freeze = function freeze() {
|
||||
frozens.push({
|
||||
failMessage,
|
||||
failureOutput,
|
||||
usages,
|
||||
usageDisabled,
|
||||
epilogs,
|
||||
examples,
|
||||
commands,
|
||||
descriptions,
|
||||
});
|
||||
};
|
||||
self.unfreeze = function unfreeze() {
|
||||
const frozen = frozens.pop();
|
||||
assertNotStrictEqual(frozen, undefined, shim);
|
||||
({
|
||||
failMessage,
|
||||
failureOutput,
|
||||
usages,
|
||||
usageDisabled,
|
||||
epilogs,
|
||||
examples,
|
||||
commands,
|
||||
descriptions,
|
||||
} = frozen);
|
||||
};
|
||||
return self;
|
||||
}
|
||||
function isIndentedText(text) {
|
||||
return typeof text === 'object';
|
||||
}
|
||||
function addIndentation(text, indent) {
|
||||
return isIndentedText(text)
|
||||
? { text: text.text, indentation: text.indentation + indent }
|
||||
: { text, indentation: indent };
|
||||
}
|
||||
function getIndentation(text) {
|
||||
return isIndentedText(text) ? text.indentation : 0;
|
||||
}
|
||||
function getText(text) {
|
||||
return isIndentedText(text) ? text.text : text;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
"use strict";
|
||||
function __export(m) {
|
||||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
||||
}
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
__export(require("rxjs-compat/util/isScheduler"));
|
||||
//# sourceMappingURL=isScheduler.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"errorObject.js","sources":["../src/util/errorObject.ts"],"names":[],"mappings":";;;;;AAAA,kDAA6C"}
|
||||
@@ -0,0 +1,10 @@
|
||||
# editorconfig.org
|
||||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
@@ -0,0 +1,7 @@
|
||||
"use strict";
|
||||
function __export(m) {
|
||||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
||||
}
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
__export(require("rxjs-compat/operator/first"));
|
||||
//# sourceMappingURL=first.js.map
|
||||
@@ -0,0 +1,208 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const got = require('got');
|
||||
const globby = require('globby');
|
||||
const FormData = require('form-data');
|
||||
const Release = require('../GitRelease');
|
||||
const { format, e } = require('../../util');
|
||||
const prompts = require('./prompts');
|
||||
|
||||
const docs = 'https://git.io/release-it-gitlab';
|
||||
|
||||
const noop = Promise.resolve();
|
||||
|
||||
class GitLab extends Release {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
this.registerPrompts(prompts);
|
||||
this.assets = [];
|
||||
}
|
||||
|
||||
get client() {
|
||||
if (this._client) return this._client;
|
||||
const { tokenHeader } = this.options;
|
||||
const { baseUrl } = this.getContext();
|
||||
this._client = got.extend({
|
||||
prefixUrl: baseUrl,
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'user-agent': 'webpro/release-it',
|
||||
[tokenHeader]: this.token
|
||||
}
|
||||
});
|
||||
return this._client;
|
||||
}
|
||||
|
||||
async init() {
|
||||
await super.init();
|
||||
const { skipChecks, tokenRef, tokenHeader } = this.options;
|
||||
const { repo } = this.getContext();
|
||||
const hasJobToken = (tokenHeader || '').toLowerCase() === 'job-token';
|
||||
const origin = this.options.origin || `https://${repo.host}`;
|
||||
this.setContext({
|
||||
id: encodeURIComponent(repo.repository),
|
||||
origin,
|
||||
baseUrl: `${origin}/api/v4`
|
||||
});
|
||||
|
||||
if (skipChecks) return;
|
||||
|
||||
if (!this.token) {
|
||||
throw e(`Environment variable "${tokenRef}" is required for GitLab releases.`, docs);
|
||||
}
|
||||
|
||||
if (!hasJobToken) {
|
||||
if (!(await this.isAuthenticated())) {
|
||||
throw e(`Could not authenticate with GitLab using environment variable "${tokenRef}".`, docs);
|
||||
}
|
||||
if (!(await this.isCollaborator())) {
|
||||
const { user, repo } = this.getContext();
|
||||
throw e(`User ${user.username} is not a collaborator for ${repo.repository}.`, docs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async isAuthenticated() {
|
||||
if (this.config.isDryRun) return true;
|
||||
const endpoint = `user`;
|
||||
try {
|
||||
const { id, username } = await this.request(endpoint, { method: 'GET' });
|
||||
this.setContext({ user: { id, username } });
|
||||
return true;
|
||||
} catch (err) {
|
||||
this.debug(err);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async isCollaborator() {
|
||||
if (this.config.isDryRun) return true;
|
||||
const { id, user } = this.getContext();
|
||||
const endpoint = `projects/${id}/members/all/${user.id}`;
|
||||
try {
|
||||
const { access_level } = await this.request(endpoint, { method: 'GET' });
|
||||
return access_level && access_level >= 30;
|
||||
} catch (err) {
|
||||
this.debug(err);
|
||||
if (err.name === 'HTTPError' && err.response.statusCode === 404) {
|
||||
// Using another endpoint, since "/projects/:id/members/all/:user_id" was introduced in v12.4
|
||||
const endpoint = `projects/${id}/members/${user.id}`;
|
||||
try {
|
||||
const { access_level } = await this.request(endpoint, { method: 'GET' });
|
||||
return access_level && access_level >= 30;
|
||||
} catch (err) {
|
||||
this.debug(err);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async release() {
|
||||
const glRelease = () => this.createRelease();
|
||||
const glUploadAssets = () => this.uploadAssets();
|
||||
|
||||
if (this.config.isCI) {
|
||||
await this.step({ enabled: this.options.assets, task: glUploadAssets, label: 'GitLab upload assets' });
|
||||
return await this.step({ task: glRelease, label: 'GitLab release' });
|
||||
} else {
|
||||
const release = () => glUploadAssets().then(() => glRelease());
|
||||
return await this.step({ task: release, label: 'GitLab release', prompt: 'release' });
|
||||
}
|
||||
}
|
||||
|
||||
async request(endpoint, options) {
|
||||
const { baseUrl } = this.getContext();
|
||||
this.debug(Object.assign({ url: `${baseUrl}/${endpoint}` }, options));
|
||||
const method = (options.method || 'POST').toLowerCase();
|
||||
const response = await this.client[method](endpoint, options);
|
||||
const body = typeof response.body === 'string' ? JSON.parse(response.body) : response.body || {};
|
||||
this.debug(body);
|
||||
return body;
|
||||
}
|
||||
|
||||
async createRelease() {
|
||||
const { releaseName } = this.options;
|
||||
const { id, tagName, releaseNotes, repo, origin } = this.getContext();
|
||||
const { isDryRun } = this.config;
|
||||
const name = format(releaseName, this.config.getContext());
|
||||
const description = releaseNotes || '-';
|
||||
const releaseUrl = `${origin}/${repo.repository}/-/releases`;
|
||||
|
||||
this.log.exec(`gitlab releases#createRelease "${name}" (${tagName})`, { isDryRun });
|
||||
|
||||
if (isDryRun) {
|
||||
this.setContext({ isReleased: true, releaseUrl });
|
||||
return true;
|
||||
}
|
||||
|
||||
const endpoint = `projects/${id}/releases`;
|
||||
const options = {
|
||||
json: {
|
||||
name,
|
||||
tag_name: tagName,
|
||||
description
|
||||
}
|
||||
};
|
||||
|
||||
if (this.assets.length) {
|
||||
options.json.assets = {
|
||||
links: this.assets
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
await this.request(endpoint, options);
|
||||
this.log.verbose('gitlab releases#createRelease: done');
|
||||
this.setContext({ isReleased: true, releaseUrl });
|
||||
return true;
|
||||
} catch (err) {
|
||||
this.debug(err);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
async uploadAsset(filePath) {
|
||||
const name = path.basename(filePath);
|
||||
const { id, origin, repo } = this.getContext();
|
||||
const endpoint = `projects/${id}/uploads`;
|
||||
|
||||
const body = new FormData();
|
||||
body.append('file', fs.createReadStream(filePath));
|
||||
const options = { body };
|
||||
|
||||
try {
|
||||
const body = await this.request(endpoint, options);
|
||||
this.log.verbose(`gitlab releases#uploadAsset: done (${body.url})`);
|
||||
this.assets.push({
|
||||
name,
|
||||
url: `${origin}/${repo.repository}${body.url}`
|
||||
});
|
||||
} catch (err) {
|
||||
this.debug(err);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
uploadAssets() {
|
||||
const { assets } = this.options;
|
||||
const { isDryRun } = this.config;
|
||||
|
||||
this.log.exec('gitlab releases#uploadAssets', assets, { isDryRun });
|
||||
|
||||
if (!assets || isDryRun) {
|
||||
return noop;
|
||||
}
|
||||
|
||||
return globby(assets).then(files => {
|
||||
if (!files.length) {
|
||||
this.log.warn(`gitlab releases#uploadAssets: could not find "${assets}" relative to ${process.cwd()}`);
|
||||
}
|
||||
return Promise.all(files.map(filePath => this.uploadAsset(filePath)));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GitLab;
|
||||
Reference in New Issue
Block a user