@zityhub/check-updates 0.0.4 → 1.0.0

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.
package/README.md CHANGED
@@ -0,0 +1,72 @@
1
+ # check-updates
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@zityhub/check-updates)](https://www.npmjs.com/package/@zityhub/check-updates)
4
+ [![CI](https://github.com/zityhub/check-updates/actions/workflows/ci.yml/badge.svg)](https://github.com/zityhub/check-updates/actions/workflows/ci.yml)
5
+
6
+ ## Installation
7
+
8
+ Install it as a development dependency:
9
+
10
+ ```sh
11
+ npm install -D @zityhub/check-updates
12
+ ```
13
+
14
+ Or run it directly using [npx](https://docs.npmjs.com/cli/v7/commands/npx):
15
+
16
+ ```sh
17
+ npx @zityhub/check-updates
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ Check if any of your project's dependencies have a major version update:
23
+
24
+ ```sh
25
+ check-updates
26
+
27
+ 2024-10-08T18:32:05.485Z ERROR Job check-updates finished failed
28
+ {
29
+ "type": {
30
+ "name": "job",
31
+ "data": {
32
+ "jobName": "check-updates",
33
+ "message": "Major update available for: awilix,jsonpath-plus,stripe"
34
+ }
35
+ }
36
+ }
37
+ ```
38
+
39
+ The command will return an error if there are any packages that need a major version update.
40
+
41
+ ## Exclude Packages
42
+
43
+ You can ignore specific dependencies to ensure the check returns an exit code 0:
44
+
45
+ ```sh
46
+ check-updates --exclude=awilix --exclude=jsonpath-plus --exclude=stripe
47
+
48
+ 2024-10-08T18:34:51.341Z INFO Job check-updates finished success
49
+ {
50
+ "type": {
51
+ "name": "job",
52
+ "data": {
53
+ "jobName": "check-updates",
54
+ "message": "Major update available for: awilix,jsonpath-plus,stripe"
55
+ }
56
+ }
57
+ }
58
+ ```
59
+
60
+ ## Add it as a Script in your Package
61
+
62
+ It is recommended to add it as a script in your package.json for easier usage:
63
+
64
+ ```json
65
+ {
66
+ "scripts": {
67
+ "check-updates": "check-updates"
68
+ }
69
+ }
70
+ ```
71
+
72
+
@@ -0,0 +1 @@
1
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,94 @@
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ const npm_check_updates_1 = require("npm-check-updates");
36
+ const process = __importStar(require("node:process"));
37
+ const info = (title, message) => {
38
+ process.stdout.write(`${new Date().toISOString()} \x1b[102mINFO\x1b[0m \x1b[34m${title}\x1b[0m\n${JSON.stringify(message, null, 2)}\n`);
39
+ };
40
+ const error = (title, message) => {
41
+ process.stderr.write(`${new Date().toISOString()} \x1b[41mERROR\x1b[0m \x1b[34m${title}\x1b[0m\n${JSON.stringify(message, null, 2)}\n`);
42
+ };
43
+ const parseArguments = (args) => {
44
+ const exclude = [];
45
+ args.forEach((arg) => {
46
+ const [key, value] = arg.split('=');
47
+ if (key.startsWith('--exclude') && value)
48
+ exclude.push(value);
49
+ });
50
+ return exclude;
51
+ };
52
+ const hasVersion = (version) => {
53
+ return version !== undefined && version !== null;
54
+ };
55
+ const packagesToUpdate = () => __awaiter(void 0, void 0, void 0, function* () {
56
+ const upgraded = (yield (0, npm_check_updates_1.run)({
57
+ filterResults: (packageName, { currentVersionSemver, upgradedVersionSemver }) => {
58
+ var _a;
59
+ const currentMajor = parseInt((_a = currentVersionSemver[0]) === null || _a === void 0 ? void 0 : _a.major, 10);
60
+ const upgradedMajor = parseInt(upgradedVersionSemver === null || upgradedVersionSemver === void 0 ? void 0 : upgradedVersionSemver.major, 10);
61
+ if (hasVersion(currentMajor) && hasVersion(upgradedMajor))
62
+ return currentMajor !== upgradedMajor;
63
+ return true;
64
+ }
65
+ }));
66
+ return Object.keys(upgraded);
67
+ });
68
+ const main = (exclude) => __awaiter(void 0, void 0, void 0, function* () {
69
+ const packages = yield packagesToUpdate();
70
+ const toUpdate = packages.filter((packageName) => !exclude.includes(packageName));
71
+ const message = `Major update available for: ${packages.join(',')}`;
72
+ if (toUpdate.length)
73
+ return Promise.reject(message);
74
+ return Promise.resolve(packages.length ? message : undefined);
75
+ });
76
+ main(parseArguments(process.argv.slice(2)))
77
+ .then((message) => {
78
+ info('Job check-updates finished success', {
79
+ type: {
80
+ name: 'job',
81
+ data: Object.assign({ jobName: 'check-updates' }, (message && { message }))
82
+ }
83
+ });
84
+ process.exit(0);
85
+ })
86
+ .catch((err) => {
87
+ error('Job check-updates finished failed', {
88
+ type: {
89
+ name: 'job',
90
+ data: { jobName: 'check-updates', message: err }
91
+ }
92
+ });
93
+ process.exit(1);
94
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zityhub/check-updates",
3
- "version": "0.0.4",
3
+ "version": "1.0.0",
4
4
  "author": "Zityhub",
5
5
  "license": "MIT",
6
6
  "description": "Project that checks if your project has any dependencies that have been updated with a major version.",