zarro 1.165.2 → 1.165.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/gulp-tasks/modules/fetch-github-release/dist-copy/constants.js +10 -0
  2. package/gulp-tasks/modules/fetch-github-release/dist-copy/fetchRelease.js +123 -0
  3. package/gulp-tasks/modules/fetch-github-release/dist-copy/getAssetDefault.js +34 -0
  4. package/gulp-tasks/modules/fetch-github-release/dist-copy/index.js +18 -0
  5. package/gulp-tasks/modules/fetch-github-release/dist-copy/isUpdateAvailable.js +50 -0
  6. package/gulp-tasks/modules/fetch-github-release/dist-copy/types.d.ts +14 -0
  7. package/gulp-tasks/modules/fetch-github-release/dist-copy/types.js +2 -0
  8. package/gulp-tasks/modules/fetch-github-release/dist-copy/util.js +39 -0
  9. package/gulp-tasks/modules/fetch-github-release.js +15 -5
  10. package/package.json +7 -2
  11. package/gulp-tasks/modules/fetch-github-release/.editorconfig +0 -10
  12. package/gulp-tasks/modules/fetch-github-release/.gitattributes +0 -1
  13. package/gulp-tasks/modules/fetch-github-release/.github/.kodiak.toml +0 -1
  14. package/gulp-tasks/modules/fetch-github-release/.github/workflows/release-please.yml +0 -26
  15. package/gulp-tasks/modules/fetch-github-release/.github/workflows/test.yml +0 -26
  16. package/gulp-tasks/modules/fetch-github-release/.prettierrc.json +0 -7
  17. package/gulp-tasks/modules/fetch-github-release/CHANGELOG.md +0 -8
  18. package/gulp-tasks/modules/fetch-github-release/package-lock.json +0 -12412
  19. package/gulp-tasks/modules/fetch-github-release/package.json +0 -78
  20. package/gulp-tasks/modules/fetch-github-release/renovate.json5 +0 -19
  21. package/gulp-tasks/modules/fetch-github-release/src/__tests__/index.ts +0 -51
  22. package/gulp-tasks/modules/fetch-github-release/src/constants.ts +0 -5
  23. package/gulp-tasks/modules/fetch-github-release/src/fetchRelease.ts +0 -159
  24. package/gulp-tasks/modules/fetch-github-release/src/getAssetDefault.ts +0 -48
  25. package/gulp-tasks/modules/fetch-github-release/src/index.ts +0 -2
  26. package/gulp-tasks/modules/fetch-github-release/src/isUpdateAvailable.ts +0 -143
  27. package/gulp-tasks/modules/fetch-github-release/src/types.ts +0 -17
  28. package/gulp-tasks/modules/fetch-github-release/src/util.ts +0 -24
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.PACKAGE_DATA_DIR = exports.PACKAGE_NAME = void 0;
7
+ const os_1 = __importDefault(require("os"));
8
+ const path_1 = __importDefault(require("path"));
9
+ exports.PACKAGE_NAME = 'fetch-github-release';
10
+ exports.PACKAGE_DATA_DIR = path_1.default.join(os_1.default.homedir(), `.${exports.PACKAGE_NAME}`);
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.fetchLatestRelease = exports.fetchReleaseByTag = void 0;
16
+ const yafs_1 = require("yafs");
17
+ const path_1 = __importDefault(require("path"));
18
+ const rest_1 = require("@octokit/rest");
19
+ const decompress_1 = __importDefault(require("decompress"));
20
+ const bent = require("bent");
21
+ const constants_1 = require("./constants");
22
+ const util_1 = require("./util");
23
+ const getAssetDefault_1 = require("./getAssetDefault");
24
+ function determineFilenameFrom(response) {
25
+ const contentDisposition = response.headers["content-disposition"];
26
+ if (!contentDisposition) {
27
+ // guess? shouldn't get here from GH queries...
28
+ return fallback();
29
+ }
30
+ const parts = contentDisposition.split(";").map(s => s.trim());
31
+ for (const part of parts) {
32
+ let match = part.match(/^filename=(?<filename>.+)/i);
33
+ if (match && match.groups) {
34
+ const filename = match.groups["filename"];
35
+ if (filename) {
36
+ return filename;
37
+ }
38
+ }
39
+ }
40
+ return fallback();
41
+ function fallback() {
42
+ console.warn(`Unable to determine filename from request, falling back on release.zip`);
43
+ return "release.zip";
44
+ }
45
+ }
46
+ function download(url, destination) {
47
+ return __awaiter(this, void 0, void 0, function* () {
48
+ const fetch = bent(url);
49
+ try {
50
+ const response = yield fetch();
51
+ const data = yield response.arrayBuffer();
52
+ const filename = determineFilenameFrom(response);
53
+ yield (0, yafs_1.writeFile)(path_1.default.join(destination, filename), data);
54
+ return determineFilenameFrom(response);
55
+ }
56
+ catch (e) {
57
+ const err = e;
58
+ if (err.statusCode === undefined) {
59
+ throw err;
60
+ }
61
+ if (err.statusCode === 301 || err.statusCode === 302) {
62
+ const next = err.headers["location"];
63
+ if (!next) {
64
+ throw new Error(`No location provided for http response ${err.statusCode}`);
65
+ }
66
+ return download(next, destination);
67
+ }
68
+ throw err;
69
+ }
70
+ });
71
+ }
72
+ function fetchRelease(options) {
73
+ var _a;
74
+ return __awaiter(this, void 0, void 0, function* () {
75
+ const { owner, repo, getRelease, getAsset = getAssetDefault_1.getAssetDefault, destination = constants_1.PACKAGE_DATA_DIR, shouldExtract = true, } = options;
76
+ if (!owner) {
77
+ throw new Error('Required "owner" option is missing');
78
+ }
79
+ if (!repo) {
80
+ throw new Error('Required "repo" option is missing');
81
+ }
82
+ const { data: { assets, tag_name: version }, } = yield getRelease(owner, repo);
83
+ const downloadUrl = (_a = getAsset(version, assets)) === null || _a === void 0 ? void 0 : _a.browser_download_url;
84
+ if (!downloadUrl) {
85
+ throw new Error('Unable to find download URL');
86
+ }
87
+ yield (0, util_1.ensureDirExist)(destination);
88
+ const filename = yield download(downloadUrl, destination);
89
+ const downloadPath = path_1.default.join(destination, filename);
90
+ if (shouldExtract) {
91
+ const files = yield (0, decompress_1.default)(downloadPath, destination);
92
+ yield (0, yafs_1.rm)(downloadPath);
93
+ return files.map((file) => path_1.default.join(destination, file.path));
94
+ }
95
+ return [downloadPath];
96
+ });
97
+ }
98
+ /**
99
+ * Downloads and extract release for the specified tag from Github to the destination.
100
+ *
101
+ * await fetchLatestRelease({ owner: 'smallstep', repo: 'cli', tag: '1.0.0' })
102
+ */
103
+ function fetchReleaseByTag(options) {
104
+ return __awaiter(this, void 0, void 0, function* () {
105
+ return fetchRelease(Object.assign(Object.assign({}, options), { getRelease: (owner, repo) => new rest_1.Octokit({ auth: options.accessToken }).repos.getReleaseByTag({
106
+ owner,
107
+ repo,
108
+ tag: options.tag,
109
+ }) }));
110
+ });
111
+ }
112
+ exports.fetchReleaseByTag = fetchReleaseByTag;
113
+ /**
114
+ * Downloads and extract latest release from Github to the destination.
115
+ *
116
+ * await fetchLatestRelease({ owner: 'smallstep', repo: 'cli' })
117
+ */
118
+ function fetchLatestRelease(options) {
119
+ return __awaiter(this, void 0, void 0, function* () {
120
+ return fetchRelease(Object.assign(Object.assign({}, options), { getRelease: (owner, repo) => new rest_1.Octokit({ auth: options.accessToken }).repos.getLatestRelease({ owner, repo }) }));
121
+ });
122
+ }
123
+ exports.fetchLatestRelease = fetchLatestRelease;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAssetDefault = void 0;
4
+ function getPlatformIdentifier() {
5
+ switch (process.platform) {
6
+ case 'win32':
7
+ return { platform: 'windows', arch: 'amd64' };
8
+ case 'linux':
9
+ if (process.arch === 'arm64') {
10
+ return { platform: 'linux', arch: 'arm64' };
11
+ }
12
+ if (process.arch === 'arm') {
13
+ return { platform: 'linux', arch: 'arm' };
14
+ }
15
+ return { platform: 'linux', arch: 'amd64' };
16
+ case 'darwin':
17
+ return { platform: 'darwin', arch: 'amd64' };
18
+ default:
19
+ throw new Error('Unsupported platform');
20
+ }
21
+ }
22
+ function getAssetDefault(version, assets) {
23
+ const { platform, arch } = getPlatformIdentifier();
24
+ const platformAssets = assets.filter((asset) => asset.name.includes(platform));
25
+ if (platformAssets.length === 1) {
26
+ return platformAssets[0];
27
+ }
28
+ const archAsset = platformAssets.find((asset) => asset.name.includes(arch));
29
+ if (!archAsset) {
30
+ throw new Error(`Unable to find release for platform: ${platform} and arch: ${arch}`);
31
+ }
32
+ return archAsset;
33
+ }
34
+ exports.getAssetDefault = getAssetDefault;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./fetchRelease"), exports);
18
+ __exportStar(require("./isUpdateAvailable"), exports);
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.newerVersion = exports.listReleases = exports.fetchLatestReleaseInfo = exports.isUpdateAvailable = void 0;
13
+ const rest_1 = require("@octokit/rest");
14
+ const semver_1 = require("semver");
15
+ function isUpdateAvailable(options) {
16
+ return __awaiter(this, void 0, void 0, function* () {
17
+ const { repo, owner, currentVersion, accessToken } = options;
18
+ const { data: { tag_name: latestVersion }, } = yield new rest_1.Octokit({ auth: accessToken }).repos.getLatestRelease({ owner, repo });
19
+ return newerVersion(latestVersion, currentVersion);
20
+ });
21
+ }
22
+ exports.isUpdateAvailable = isUpdateAvailable;
23
+ function fetchLatestReleaseInfo(opts) {
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ const { repo, owner, accessToken } = opts;
26
+ const result = yield new rest_1.Octokit({ auth: accessToken }).repos.getLatestRelease({ owner, repo });
27
+ return result.data;
28
+ });
29
+ }
30
+ exports.fetchLatestReleaseInfo = fetchLatestReleaseInfo;
31
+ function listReleases(opts) {
32
+ return __awaiter(this, void 0, void 0, function* () {
33
+ const { repo, owner, accessToken } = opts;
34
+ const result = yield new rest_1.Octokit({ auth: accessToken }).repos.listReleases({ owner, repo });
35
+ return result.data;
36
+ });
37
+ }
38
+ exports.listReleases = listReleases;
39
+ function newerVersion(latestVersion, currentVersion) {
40
+ if (!latestVersion) {
41
+ return false;
42
+ }
43
+ if (!currentVersion) {
44
+ return true;
45
+ }
46
+ const normalizedLatestVersion = latestVersion.replace(/^v/, "");
47
+ const normalizedCurrentVersion = currentVersion.replace(/^v/, "");
48
+ return (0, semver_1.gt)(normalizedLatestVersion, normalizedCurrentVersion);
49
+ }
50
+ exports.newerVersion = newerVersion;
@@ -0,0 +1,14 @@
1
+ import { RestEndpointMethodTypes } from '@octokit/rest';
2
+ export type OctokitRelease = RestEndpointMethodTypes['repos']['getLatestRelease']['response'];
3
+ export type OctokitReleaseAssets = OctokitRelease['data']['assets'];
4
+ export interface Release {
5
+ repository: string;
6
+ package: string;
7
+ destination: string;
8
+ version: string;
9
+ extract: boolean;
10
+ }
11
+ export interface RepoInfo {
12
+ owner: string;
13
+ repo: string;
14
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.ensureDirExist = exports.mkdir = exports.exists = void 0;
16
+ const fs_1 = __importDefault(require("fs"));
17
+ const path_1 = __importDefault(require("path"));
18
+ const exists = (filePath) => __awaiter(void 0, void 0, void 0, function* () {
19
+ try {
20
+ yield fs_1.default.promises.access(filePath);
21
+ return true;
22
+ }
23
+ catch (_a) {
24
+ return false;
25
+ }
26
+ });
27
+ exports.exists = exists;
28
+ const mkdir = (dirname) => __awaiter(void 0, void 0, void 0, function* () {
29
+ const isExist = yield (0, exports.exists)(dirname);
30
+ if (!isExist) {
31
+ yield fs_1.default.promises.mkdir(dirname, { recursive: true });
32
+ }
33
+ });
34
+ exports.mkdir = mkdir;
35
+ const ensureDirExist = (filePath) => __awaiter(void 0, void 0, void 0, function* () {
36
+ const dirname = path_1.default.dirname(filePath);
37
+ yield (0, exports.mkdir)(dirname);
38
+ });
39
+ exports.ensureDirExist = ensureDirExist;
@@ -1,9 +1,19 @@
1
1
  "use strict";
2
2
  (async function () {
3
3
  requireModule("fetch");
4
- const path = require("path"), { folderExistsSync } = require("yafs");
5
- const imported = folderExistsSync(path.join(__dirname, "fetch-github-release", "dist"))
6
- ? require("./fetch-github-release/dist")
7
- : require("./fetch-github-release/src");
8
- module.exports = imported;
4
+ const path = require("path"), { folderExistsSync } = require("yafs"),
5
+ // ideally, during dev, we want fresh src files
6
+ // but the build produces a dist folder with
7
+ // js artifacts, which also work - but npm
8
+ // refuses to pack them, and I haven't figured out
9
+ // why; so another process should create dist-copy
10
+ // specifically for packing purposes
11
+ search = ["src", "dist", "dist-copy"];
12
+ for (const item of search) {
13
+ const seek = path.join(__dirname, "fetch-github-release", item);
14
+ if (folderExistsSync(seek)) {
15
+ module.exports = require(seek);
16
+ return;
17
+ }
18
+ }
9
19
  })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zarro",
3
- "version": "1.165.2",
3
+ "version": "1.165.4",
4
4
  "description": "Some glue to make gulp easier, perhaps even zero- or close-to-zero-conf",
5
5
  "bin": {
6
6
  "zarro": "./index.js"
@@ -39,6 +39,9 @@
39
39
  "build-zarro": "tsc",
40
40
  "prebuild-fetch-github-release": "rimraf gulp-tasks/modules/fetch-github-release/dist",
41
41
  "build-fetch-github-release": "tsc -p gulp-tasks/modules/fetch-github-release/tsconfig.json",
42
+ "postbuild-fetch-github-release": "run-s delete-fetch-github-release-dist-shadow shadow-fetch-github-release-dist",
43
+ "delete-fetch-github-release-dist-shadow": "rimraf gulp-tasks/modules/fetch-github-release/dist-copy",
44
+ "shadow-fetch-github-release-dist": "cpy gulp-tasks/modules/fetch-github-release/dist/*.* gulp-tasks/modules/fetch-github-release/dist-copy/",
42
45
  "gulp": "gulp",
43
46
  "test-npm-gulp-task": "echo \"this is a test\"",
44
47
  "verify-up-to-date": "run-s \"zarro -- verify-up-to-date\"",
@@ -91,7 +94,8 @@
91
94
  },
92
95
  "files": [
93
96
  "gulp-tasks/**/*.js",
94
- "gulp-tasks/modules/fetch-github-release/**/*.*",
97
+ "gulp-tasks/modules/fetch-github-release/moo/*.js",
98
+ "gulp-tasks/modules/fetch-github-release/moo/*.d.ts",
95
99
  "index-modules/**/*.js",
96
100
  "types.d.ts",
97
101
  "tsconfig.json"
@@ -118,6 +122,7 @@
118
122
  "@types/xml2js": "^0.4.8",
119
123
  "@types/yargs": "^15.0.13",
120
124
  "console-cls": "^1.2.2",
125
+ "cpy-cli": "^5.0.0",
121
126
  "debugger-is-attached": "^1.2.0",
122
127
  "expect-even-more-jest": "^1.15.0",
123
128
  "filesystem-sandbox": "^1.20.0",
@@ -1,10 +0,0 @@
1
- root = true
2
-
3
- [*]
4
- indent_style = space
5
- indent_size = 2
6
- end_of_line = lf
7
- charset = utf-8
8
- max_line_length = 100
9
- trim_trailing_whitespace = true
10
- insert_final_newline = true
@@ -1 +0,0 @@
1
- * text=auto eol=lf
@@ -1,26 +0,0 @@
1
- name: release-please
2
- on:
3
- push:
4
- branches:
5
- - main
6
- jobs:
7
- release-please:
8
- runs-on: ubuntu-latest
9
- steps:
10
- - uses: GoogleCloudPlatform/release-please-action@v2
11
- id: release
12
- with:
13
- release-type: node
14
- package-name: 'fetch-github-release'
15
- - uses: actions/checkout@v2
16
- if: ${{ steps.release.outputs.release_created }}
17
- - uses: actions/setup-node@v2
18
- with:
19
- node-version: '*'
20
- check-latest: true
21
- registry-url: 'https://registry.npmjs.org'
22
- if: ${{ steps.release.outputs.release_created }}
23
- - run: npm publish
24
- if: ${{ steps.release.outputs.release_created }}
25
- env:
26
- NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
@@ -1,26 +0,0 @@
1
- name: Test
2
- on:
3
- push:
4
- branches: [main]
5
- pull_request:
6
- branches: [main]
7
- jobs:
8
- build:
9
- runs-on: ubuntu-latest
10
- timeout-minutes: 15
11
- steps:
12
- - name: Git checkout
13
- uses: actions/checkout@v2
14
- - name: Setup Node.js
15
- uses: actions/setup-node@v2
16
- with:
17
- node-version: 16
18
- check-latest: true
19
- - name: Install dependencies
20
- run: npm ci
21
- - name: Linting
22
- run: npm run format:ci
23
- - name: Building
24
- run: npm run build
25
- - name: Tests
26
- run: npm run test
@@ -1,7 +0,0 @@
1
- {
2
- "semi": false,
3
- "singleQuote": true,
4
- "printWidth": 100,
5
- "proseWrap": "always",
6
- "trailingComma": "all"
7
- }
@@ -1,8 +0,0 @@
1
- # Changelog
2
-
3
- ## 1.0.0 (2021-08-21)
4
-
5
-
6
- ### Features
7
-
8
- * init ([a0f486a](https://www.github.com/valerybugakov/fetch-github-release/commit/a0f486a9a9843e262027851a805c559fdbeaedfb))