keep-a-changelog 2.0.1 → 2.2.1
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/CHANGELOG.md +28 -2
- package/README.md +21 -6
- package/esm/_dnt.polyfills.js +15 -0
- package/esm/bin.js +9 -4
- package/esm/deps/deno.land/std@0.173.0/_util/asserts.js +21 -0
- package/esm/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/_util/os.js +4 -1
- package/esm/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/flags/mod.js +145 -36
- package/esm/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/_constants.js +1 -0
- package/esm/deps/deno.land/std@0.173.0/path/_interface.js +3 -0
- package/esm/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/_util.js +1 -0
- package/esm/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/common.js +1 -1
- package/esm/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/glob.js +1 -1
- package/esm/deps/deno.land/std@0.173.0/path/mod.js +32 -0
- package/esm/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/posix.js +23 -16
- package/esm/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/separator.js +1 -1
- package/esm/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/win32.js +20 -15
- package/esm/deps/{deno_land/x/semver_v1.4.0 → deno.land/std@0.173.0/semver}/mod.js +227 -334
- package/esm/deps/{deno_land/std_0.51.0 → deno.land/std@0.51.0}/fs/eol.js +0 -0
- package/esm/deps/{deno_land/x/ini_v2.1.0 → deno.land/x/ini@v2.1.0}/ini.js +1 -1
- package/esm/deps/{deno_land/x/ini_v2.1.0 → deno.land/x/ini@v2.1.0}/mod.js +0 -0
- package/esm/mod.js +1 -0
- package/esm/src/Change.js +15 -15
- package/esm/src/Changelog.js +9 -1
- package/esm/src/Release.js +21 -4
- package/esm/src/deps.js +1 -1
- package/esm/src/parser.js +24 -5
- package/esm/test/changelog.custom.type.md +0 -1
- package/esm/test/changelog.expected.linted.md +208 -0
- package/esm/test/changelog.expected.md +6 -4
- package/esm/test/changelog.md +7 -3
- package/esm/test/empty.expected.md +0 -1
- package/package.json +13 -8
- package/script/_dnt.polyfills.js +16 -0
- package/script/_dnt.shims.js +66 -0
- package/script/bin.js +144 -0
- package/script/deps/deno.land/std@0.173.0/_util/asserts.js +27 -0
- package/script/deps/deno.land/std@0.173.0/_util/os.js +44 -0
- package/script/deps/deno.land/std@0.173.0/flags/mod.js +368 -0
- package/script/deps/deno.land/std@0.173.0/path/_constants.js +49 -0
- package/script/deps/deno.land/std@0.173.0/path/_interface.js +4 -0
- package/script/deps/deno.land/std@0.173.0/path/_util.js +125 -0
- package/script/deps/deno.land/std@0.173.0/path/common.js +40 -0
- package/script/deps/deno.land/std@0.173.0/path/glob.js +391 -0
- package/script/deps/deno.land/std@0.173.0/path/mod.js +63 -0
- package/script/deps/deno.land/std@0.173.0/path/posix.js +539 -0
- package/script/deps/deno.land/std@0.173.0/path/separator.js +8 -0
- package/script/deps/deno.land/std@0.173.0/path/win32.js +1007 -0
- package/script/deps/deno.land/std@0.173.0/semver/mod.js +1458 -0
- package/script/deps/deno.land/std@0.51.0/fs/eol.js +34 -0
- package/script/deps/deno.land/x/ini@v2.1.0/ini.js +256 -0
- package/script/deps/deno.land/x/ini@v2.1.0/mod.js +17 -0
- package/script/mod.js +15 -0
- package/{umd → script}/package.json +0 -0
- package/script/src/Change.js +51 -0
- package/script/src/Changelog.js +148 -0
- package/script/src/Release.js +227 -0
- package/script/src/deps.js +9 -0
- package/script/src/parser.js +184 -0
- package/{umd → script}/test/changelog.custom.type.md +0 -1
- package/script/test/changelog.expected.linted.md +208 -0
- package/{umd → script}/test/changelog.expected.md +6 -4
- package/{umd → script}/test/changelog.md +7 -3
- package/{umd → script}/test/empty.expected.md +0 -1
- package/types/_dnt.polyfills.d.ts +11 -0
- package/types/_dnt.shims.d.ts +0 -4
- package/types/bin.d.ts +1 -1
- package/types/deps/deno.land/std@0.173.0/_util/asserts.d.ts +10 -0
- package/types/deps/deno.land/std@0.173.0/_util/os.d.ts +4 -0
- package/types/deps/deno.land/std@0.173.0/flags/mod.d.ts +166 -0
- package/types/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/_constants.d.ts +0 -0
- package/types/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/_interface.d.ts +1 -1
- package/types/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/_util.d.ts +0 -0
- package/types/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/common.d.ts +0 -0
- package/types/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/glob.d.ts +10 -5
- package/types/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/mod.d.ts +0 -0
- package/types/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/posix.d.ts +9 -5
- package/types/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/separator.d.ts +0 -0
- package/types/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/win32.d.ts +7 -5
- package/types/deps/deno.land/std@0.173.0/semver/mod.d.ts +398 -0
- package/types/deps/{deno_land/std_0.51.0 → deno.land/std@0.51.0}/fs/eol.d.ts +0 -0
- package/types/deps/{deno_land/x/ini_v2.1.0 → deno.land/x/ini@v2.1.0}/ini.d.ts +0 -0
- package/types/deps/{deno_land/x/ini_v2.1.0 → deno.land/x/ini@v2.1.0}/mod.d.ts +0 -0
- package/types/mod.d.ts +1 -0
- package/types/src/Changelog.d.ts +1 -0
- package/types/src/Release.d.ts +2 -0
- package/types/src/deps.d.ts +1 -1
- package/esm/deps/deno_land/std_0.120.0/_util/assert.js +0 -13
- package/esm/deps/deno_land/std_0.120.0/path/_interface.js +0 -3
- package/esm/deps/deno_land/std_0.120.0/path/mod.js +0 -14
- package/types/deps/deno_land/std_0.120.0/_util/assert.d.ts +0 -5
- package/types/deps/deno_land/std_0.120.0/_util/os.d.ts +0 -3
- package/types/deps/deno_land/std_0.120.0/flags/mod.d.ts +0 -50
- package/types/deps/deno_land/x/semver_v1.4.0/mod.d.ts +0 -116
- package/umd/_dnt.shims.js +0 -76
- package/umd/bin.js +0 -145
- package/umd/deps/deno_land/std_0.120.0/_util/assert.js +0 -28
- package/umd/deps/deno_land/std_0.120.0/_util/os.js +0 -47
- package/umd/deps/deno_land/std_0.120.0/flags/mod.js +0 -269
- package/umd/deps/deno_land/std_0.120.0/path/_constants.js +0 -58
- package/umd/deps/deno_land/std_0.120.0/path/_interface.js +0 -14
- package/umd/deps/deno_land/std_0.120.0/path/_util.js +0 -134
- package/umd/deps/deno_land/std_0.120.0/path/common.js +0 -50
- package/umd/deps/deno_land/std_0.120.0/path/glob.js +0 -397
- package/umd/deps/deno_land/std_0.120.0/path/mod.js +0 -51
- package/umd/deps/deno_land/std_0.120.0/path/posix.js +0 -538
- package/umd/deps/deno_land/std_0.120.0/path/separator.js +0 -18
- package/umd/deps/deno_land/std_0.120.0/path/win32.js +0 -1008
- package/umd/deps/deno_land/std_0.51.0/fs/eol.js +0 -44
- package/umd/deps/deno_land/x/ini_v2.1.0/ini.js +0 -262
- package/umd/deps/deno_land/x/ini_v2.1.0/mod.js +0 -23
- package/umd/deps/deno_land/x/semver_v1.4.0/mod.js +0 -1578
- package/umd/mod.js +0 -24
- package/umd/src/Change.js +0 -61
- package/umd/src/Changelog.js +0 -150
- package/umd/src/Release.js +0 -220
- package/umd/src/deps.js +0 -19
- package/umd/src/parser.js +0 -175
package/script/bin.js
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
20
|
+
if (mod && mod.__esModule) return mod;
|
|
21
|
+
var result = {};
|
|
22
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
23
|
+
__setModuleDefault(result, mod);
|
|
24
|
+
return result;
|
|
25
|
+
};
|
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
require("./_dnt.polyfills.js");
|
|
28
|
+
const dntShim = __importStar(require("./_dnt.shims.js"));
|
|
29
|
+
const mod_js_1 = require("./deps/deno.land/std@0.173.0/path/mod.js");
|
|
30
|
+
const mod_js_2 = require("./mod.js");
|
|
31
|
+
const mod_js_3 = require("./deps/deno.land/std@0.173.0/flags/mod.js");
|
|
32
|
+
const mod_js_4 = require("./deps/deno.land/x/ini@v2.1.0/mod.js");
|
|
33
|
+
const argv = (0, mod_js_3.parse)(dntShim.Deno.args, {
|
|
34
|
+
default: {
|
|
35
|
+
file: "CHANGELOG.md",
|
|
36
|
+
format: "compact",
|
|
37
|
+
release: null,
|
|
38
|
+
url: null,
|
|
39
|
+
https: true,
|
|
40
|
+
quiet: false,
|
|
41
|
+
},
|
|
42
|
+
string: ["file", "format", "release", "url"],
|
|
43
|
+
boolean: ["https", "init", "latest-release", "quiet"],
|
|
44
|
+
});
|
|
45
|
+
const file = (0, mod_js_1.join)(dntShim.Deno.cwd(), argv.file);
|
|
46
|
+
try {
|
|
47
|
+
if (argv.init) {
|
|
48
|
+
const changelog = new mod_js_2.Changelog("Changelog").addRelease(new mod_js_2.Release("0.1.0", new Date(), "First version"));
|
|
49
|
+
changelog.format = argv.format;
|
|
50
|
+
save(file, changelog, true);
|
|
51
|
+
dntShim.Deno.exit(0);
|
|
52
|
+
}
|
|
53
|
+
const changelog = (0, mod_js_2.parser)(dntShim.Deno.readTextFileSync(file));
|
|
54
|
+
changelog.format = argv.format;
|
|
55
|
+
if (argv["latest-release"]) {
|
|
56
|
+
const release = changelog.releases.find((release) => release.date && release.version);
|
|
57
|
+
if (release) {
|
|
58
|
+
console.log(release.version?.toString());
|
|
59
|
+
}
|
|
60
|
+
dntShim.Deno.exit(0);
|
|
61
|
+
}
|
|
62
|
+
if (argv.release) {
|
|
63
|
+
const release = changelog.releases.find((release) => {
|
|
64
|
+
if (release.date) {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
if (typeof argv.release === "string") {
|
|
68
|
+
return !release.version || argv.release === release.version.toString();
|
|
69
|
+
}
|
|
70
|
+
return !!release.version;
|
|
71
|
+
});
|
|
72
|
+
if (release) {
|
|
73
|
+
release.date = new Date();
|
|
74
|
+
if (typeof argv.release === "string") {
|
|
75
|
+
release.setVersion(argv.release);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
console.error("Not found any valid unreleased version");
|
|
80
|
+
dntShim.Deno.exit(1);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (!changelog.url) {
|
|
84
|
+
if (argv.url) {
|
|
85
|
+
changelog.url = argv.url;
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
const url = getRemoteUrl(argv.https);
|
|
89
|
+
if (url) {
|
|
90
|
+
changelog.url = url;
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
console.error(red('Please, set the repository url with --url="https://github.com/username/repository"'));
|
|
94
|
+
dntShim.Deno.exit(1);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
save(file, changelog);
|
|
99
|
+
}
|
|
100
|
+
catch (err) {
|
|
101
|
+
console.error(red(err.message));
|
|
102
|
+
if (!argv.quiet) {
|
|
103
|
+
dntShim.Deno.exit(1);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function save(file, changelog, isNew = false) {
|
|
107
|
+
const url = changelog.url;
|
|
108
|
+
if (url && url.includes("gitlab.com")) {
|
|
109
|
+
changelog.head = "master";
|
|
110
|
+
}
|
|
111
|
+
dntShim.Deno.writeTextFileSync(file, changelog.toString());
|
|
112
|
+
if (isNew) {
|
|
113
|
+
console.log(green("Generated new file"), file);
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
console.log(green("Updated file"), file);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
function red(message) {
|
|
120
|
+
return "\u001b[" + 31 + "m" + message + "\u001b[" + 39 + "m";
|
|
121
|
+
}
|
|
122
|
+
function green(message) {
|
|
123
|
+
return "\u001b[" + 32 + "m" + message + "\u001b[" + 39 + "m";
|
|
124
|
+
}
|
|
125
|
+
function getRemoteUrl(https = true) {
|
|
126
|
+
try {
|
|
127
|
+
const file = (0, mod_js_1.join)(dntShim.Deno.cwd(), ".git", "config");
|
|
128
|
+
const content = dntShim.Deno.readTextFileSync(file);
|
|
129
|
+
const data = (0, mod_js_4.parse)(content);
|
|
130
|
+
const url = data?.['remote "origin"']?.url;
|
|
131
|
+
if (!url) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
const remoteUrl = new URL(url.replace(/^git@([^:]+):(.*)\.git$/, "https://$1/$2"));
|
|
135
|
+
if (https) {
|
|
136
|
+
remoteUrl.protocol = "https:";
|
|
137
|
+
}
|
|
138
|
+
return remoteUrl.href;
|
|
139
|
+
}
|
|
140
|
+
catch (err) {
|
|
141
|
+
console.error(red(err.message));
|
|
142
|
+
// Ignore
|
|
143
|
+
}
|
|
144
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
3
|
+
// This module is browser compatible.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.unreachable = exports.assert = exports.DenoStdInternalError = void 0;
|
|
6
|
+
/**
|
|
7
|
+
* All internal non-test code, that is files that do not have `test` or `bench` in the name, must use the assertion functions within `_utils/asserts.ts` and not `testing/asserts.ts`. This is to create a separation of concerns between internal and testing assertions.
|
|
8
|
+
*/
|
|
9
|
+
class DenoStdInternalError extends Error {
|
|
10
|
+
constructor(message) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.name = "DenoStdInternalError";
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.DenoStdInternalError = DenoStdInternalError;
|
|
16
|
+
/** Make an assertion, if not `true`, then throw. */
|
|
17
|
+
function assert(expr, msg = "") {
|
|
18
|
+
if (!expr) {
|
|
19
|
+
throw new DenoStdInternalError(msg);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.assert = assert;
|
|
23
|
+
/** Use this to assert unreachable code. */
|
|
24
|
+
function unreachable() {
|
|
25
|
+
throw new DenoStdInternalError("unreachable");
|
|
26
|
+
}
|
|
27
|
+
exports.unreachable = unreachable;
|
|
@@ -0,0 +1,44 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.isLinux = exports.isWindows = exports.osType = void 0;
|
|
27
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
28
|
+
// This module is browser compatible.
|
|
29
|
+
const dntShim = __importStar(require("../../../../_dnt.shims.js"));
|
|
30
|
+
exports.osType = (() => {
|
|
31
|
+
// deno-lint-ignore no-explicit-any
|
|
32
|
+
const { Deno } = dntShim.dntGlobalThis;
|
|
33
|
+
if (typeof Deno?.build?.os === "string") {
|
|
34
|
+
return Deno.build.os;
|
|
35
|
+
}
|
|
36
|
+
// deno-lint-ignore no-explicit-any
|
|
37
|
+
const { navigator } = dntShim.dntGlobalThis;
|
|
38
|
+
if (navigator?.appVersion?.includes?.("Win")) {
|
|
39
|
+
return "windows";
|
|
40
|
+
}
|
|
41
|
+
return "linux";
|
|
42
|
+
})();
|
|
43
|
+
exports.isWindows = exports.osType === "windows";
|
|
44
|
+
exports.isLinux = exports.osType === "linux";
|
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parse = void 0;
|
|
4
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
5
|
+
/**
|
|
6
|
+
* Command line arguments parser based on
|
|
7
|
+
* [minimist](https://github.com/minimistjs/minimist).
|
|
8
|
+
*
|
|
9
|
+
* This module is browser compatible.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { parse } from "https://deno.land/std@$STD_VERSION/flags/mod.ts";
|
|
14
|
+
*
|
|
15
|
+
* console.dir(parse(Deno.args));
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* ```sh
|
|
19
|
+
* $ deno run https://deno.land/std/examples/flags.ts -a beep -b boop
|
|
20
|
+
* { _: [], a: 'beep', b: 'boop' }
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* ```sh
|
|
24
|
+
* $ deno run https://deno.land/std/examples/flags.ts -x 3 -y 4 -n5 -abc --beep=boop foo bar baz
|
|
25
|
+
* { _: [ 'foo', 'bar', 'baz' ],
|
|
26
|
+
* x: 3,
|
|
27
|
+
* y: 4,
|
|
28
|
+
* n: 5,
|
|
29
|
+
* a: true,
|
|
30
|
+
* b: true,
|
|
31
|
+
* c: true,
|
|
32
|
+
* beep: 'boop' }
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @module
|
|
36
|
+
*/
|
|
37
|
+
const asserts_js_1 = require("../_util/asserts.js");
|
|
38
|
+
const { hasOwn } = Object;
|
|
39
|
+
function get(obj, key) {
|
|
40
|
+
if (hasOwn(obj, key)) {
|
|
41
|
+
return obj[key];
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function getForce(obj, key) {
|
|
45
|
+
const v = get(obj, key);
|
|
46
|
+
(0, asserts_js_1.assert)(v != null);
|
|
47
|
+
return v;
|
|
48
|
+
}
|
|
49
|
+
function isNumber(x) {
|
|
50
|
+
if (typeof x === "number")
|
|
51
|
+
return true;
|
|
52
|
+
if (/^0x[0-9a-f]+$/i.test(String(x)))
|
|
53
|
+
return true;
|
|
54
|
+
return /^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(String(x));
|
|
55
|
+
}
|
|
56
|
+
function hasKey(obj, keys) {
|
|
57
|
+
let o = obj;
|
|
58
|
+
keys.slice(0, -1).forEach((key) => {
|
|
59
|
+
o = (get(o, key) ?? {});
|
|
60
|
+
});
|
|
61
|
+
const key = keys[keys.length - 1];
|
|
62
|
+
return hasOwn(o, key);
|
|
63
|
+
}
|
|
64
|
+
/** Take a set of command line arguments, optionally with a set of options, and
|
|
65
|
+
* return an object representing the flags found in the passed arguments.
|
|
66
|
+
*
|
|
67
|
+
* By default, any arguments starting with `-` or `--` are considered boolean
|
|
68
|
+
* flags. If the argument name is followed by an equal sign (`=`) it is
|
|
69
|
+
* considered a key-value pair. Any arguments which could not be parsed are
|
|
70
|
+
* available in the `_` property of the returned object.
|
|
71
|
+
*
|
|
72
|
+
* By default, the flags module tries to determine the type of all arguments
|
|
73
|
+
* automatically and the return type of the `parse` method will have an index
|
|
74
|
+
* signature with `any` as value (`{ [x: string]: any }`).
|
|
75
|
+
*
|
|
76
|
+
* If the `string`, `boolean` or `collect` option is set, the return value of
|
|
77
|
+
* the `parse` method will be fully typed and the index signature of the return
|
|
78
|
+
* type will change to `{ [x: string]: unknown }`.
|
|
79
|
+
*
|
|
80
|
+
* Any arguments after `'--'` will not be parsed and will end up in `parsedArgs._`.
|
|
81
|
+
*
|
|
82
|
+
* Numeric-looking arguments will be returned as numbers unless `options.string`
|
|
83
|
+
* or `options.boolean` is set for that argument name.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```ts
|
|
87
|
+
* import { parse } from "https://deno.land/std@$STD_VERSION/flags/mod.ts";
|
|
88
|
+
* const parsedArgs = parse(Deno.args);
|
|
89
|
+
* ```
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```ts
|
|
93
|
+
* import { parse } from "https://deno.land/std@$STD_VERSION/flags/mod.ts";
|
|
94
|
+
* const parsedArgs = parse(["--foo", "--bar=baz", "./quux.txt"]);
|
|
95
|
+
* // parsedArgs: { foo: true, bar: "baz", _: ["./quux.txt"] }
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
function parse(args, { "--": doubleDash = false, alias = {}, boolean = false, default: defaults = {}, stopEarly = false, string = [], collect = [], negatable = [], unknown = (i) => i, } = {}) {
|
|
99
|
+
const aliases = {};
|
|
100
|
+
const flags = {
|
|
101
|
+
bools: {},
|
|
102
|
+
strings: {},
|
|
103
|
+
unknownFn: unknown,
|
|
104
|
+
allBools: false,
|
|
105
|
+
collect: {},
|
|
106
|
+
negatable: {},
|
|
107
|
+
};
|
|
108
|
+
if (alias !== undefined) {
|
|
109
|
+
for (const key in alias) {
|
|
110
|
+
const val = getForce(alias, key);
|
|
111
|
+
if (typeof val === "string") {
|
|
112
|
+
aliases[key] = [val];
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
aliases[key] = val;
|
|
116
|
+
}
|
|
117
|
+
for (const alias of getForce(aliases, key)) {
|
|
118
|
+
aliases[alias] = [key].concat(aliases[key].filter((y) => alias !== y));
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (boolean !== undefined) {
|
|
123
|
+
if (typeof boolean === "boolean") {
|
|
124
|
+
flags.allBools = !!boolean;
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
const booleanArgs = typeof boolean === "string"
|
|
128
|
+
? [boolean]
|
|
129
|
+
: boolean;
|
|
130
|
+
for (const key of booleanArgs.filter(Boolean)) {
|
|
131
|
+
flags.bools[key] = true;
|
|
132
|
+
const alias = get(aliases, key);
|
|
133
|
+
if (alias) {
|
|
134
|
+
for (const al of alias) {
|
|
135
|
+
flags.bools[al] = true;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
if (string !== undefined) {
|
|
142
|
+
const stringArgs = typeof string === "string"
|
|
143
|
+
? [string]
|
|
144
|
+
: string;
|
|
145
|
+
for (const key of stringArgs.filter(Boolean)) {
|
|
146
|
+
flags.strings[key] = true;
|
|
147
|
+
const alias = get(aliases, key);
|
|
148
|
+
if (alias) {
|
|
149
|
+
for (const al of alias) {
|
|
150
|
+
flags.strings[al] = true;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if (collect !== undefined) {
|
|
156
|
+
const collectArgs = typeof collect === "string"
|
|
157
|
+
? [collect]
|
|
158
|
+
: collect;
|
|
159
|
+
for (const key of collectArgs.filter(Boolean)) {
|
|
160
|
+
flags.collect[key] = true;
|
|
161
|
+
const alias = get(aliases, key);
|
|
162
|
+
if (alias) {
|
|
163
|
+
for (const al of alias) {
|
|
164
|
+
flags.collect[al] = true;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
if (negatable !== undefined) {
|
|
170
|
+
const negatableArgs = typeof negatable === "string"
|
|
171
|
+
? [negatable]
|
|
172
|
+
: negatable;
|
|
173
|
+
for (const key of negatableArgs.filter(Boolean)) {
|
|
174
|
+
flags.negatable[key] = true;
|
|
175
|
+
const alias = get(aliases, key);
|
|
176
|
+
if (alias) {
|
|
177
|
+
for (const al of alias) {
|
|
178
|
+
flags.negatable[al] = true;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
const argv = { _: [] };
|
|
184
|
+
function argDefined(key, arg) {
|
|
185
|
+
return ((flags.allBools && /^--[^=]+$/.test(arg)) ||
|
|
186
|
+
get(flags.bools, key) ||
|
|
187
|
+
!!get(flags.strings, key) ||
|
|
188
|
+
!!get(aliases, key));
|
|
189
|
+
}
|
|
190
|
+
function setKey(obj, name, value, collect = true) {
|
|
191
|
+
let o = obj;
|
|
192
|
+
const keys = name.split(".");
|
|
193
|
+
keys.slice(0, -1).forEach(function (key) {
|
|
194
|
+
if (get(o, key) === undefined) {
|
|
195
|
+
o[key] = {};
|
|
196
|
+
}
|
|
197
|
+
o = get(o, key);
|
|
198
|
+
});
|
|
199
|
+
const key = keys[keys.length - 1];
|
|
200
|
+
const collectable = collect && !!get(flags.collect, name);
|
|
201
|
+
if (!collectable) {
|
|
202
|
+
o[key] = value;
|
|
203
|
+
}
|
|
204
|
+
else if (get(o, key) === undefined) {
|
|
205
|
+
o[key] = [value];
|
|
206
|
+
}
|
|
207
|
+
else if (Array.isArray(get(o, key))) {
|
|
208
|
+
o[key].push(value);
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
o[key] = [get(o, key), value];
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
function setArg(key, val, arg = undefined, collect) {
|
|
215
|
+
if (arg && flags.unknownFn && !argDefined(key, arg)) {
|
|
216
|
+
if (flags.unknownFn(arg, key, val) === false)
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
const value = !get(flags.strings, key) && isNumber(val) ? Number(val) : val;
|
|
220
|
+
setKey(argv, key, value, collect);
|
|
221
|
+
const alias = get(aliases, key);
|
|
222
|
+
if (alias) {
|
|
223
|
+
for (const x of alias) {
|
|
224
|
+
setKey(argv, x, value, collect);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
function aliasIsBoolean(key) {
|
|
229
|
+
return getForce(aliases, key).some((x) => typeof get(flags.bools, x) === "boolean");
|
|
230
|
+
}
|
|
231
|
+
let notFlags = [];
|
|
232
|
+
// all args after "--" are not parsed
|
|
233
|
+
if (args.includes("--")) {
|
|
234
|
+
notFlags = args.slice(args.indexOf("--") + 1);
|
|
235
|
+
args = args.slice(0, args.indexOf("--"));
|
|
236
|
+
}
|
|
237
|
+
for (let i = 0; i < args.length; i++) {
|
|
238
|
+
const arg = args[i];
|
|
239
|
+
if (/^--.+=/.test(arg)) {
|
|
240
|
+
const m = arg.match(/^--([^=]+)=(.*)$/s);
|
|
241
|
+
(0, asserts_js_1.assert)(m != null);
|
|
242
|
+
const [, key, value] = m;
|
|
243
|
+
if (flags.bools[key]) {
|
|
244
|
+
const booleanValue = value !== "false";
|
|
245
|
+
setArg(key, booleanValue, arg);
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
setArg(key, value, arg);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
else if (/^--no-.+/.test(arg) && get(flags.negatable, arg.replace(/^--no-/, ""))) {
|
|
252
|
+
const m = arg.match(/^--no-(.+)/);
|
|
253
|
+
(0, asserts_js_1.assert)(m != null);
|
|
254
|
+
setArg(m[1], false, arg, false);
|
|
255
|
+
}
|
|
256
|
+
else if (/^--.+/.test(arg)) {
|
|
257
|
+
const m = arg.match(/^--(.+)/);
|
|
258
|
+
(0, asserts_js_1.assert)(m != null);
|
|
259
|
+
const [, key] = m;
|
|
260
|
+
const next = args[i + 1];
|
|
261
|
+
if (next !== undefined &&
|
|
262
|
+
!/^-/.test(next) &&
|
|
263
|
+
!get(flags.bools, key) &&
|
|
264
|
+
!flags.allBools &&
|
|
265
|
+
(get(aliases, key) ? !aliasIsBoolean(key) : true)) {
|
|
266
|
+
setArg(key, next, arg);
|
|
267
|
+
i++;
|
|
268
|
+
}
|
|
269
|
+
else if (/^(true|false)$/.test(next)) {
|
|
270
|
+
setArg(key, next === "true", arg);
|
|
271
|
+
i++;
|
|
272
|
+
}
|
|
273
|
+
else {
|
|
274
|
+
setArg(key, get(flags.strings, key) ? "" : true, arg);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
else if (/^-[^-]+/.test(arg)) {
|
|
278
|
+
const letters = arg.slice(1, -1).split("");
|
|
279
|
+
let broken = false;
|
|
280
|
+
for (let j = 0; j < letters.length; j++) {
|
|
281
|
+
const next = arg.slice(j + 2);
|
|
282
|
+
if (next === "-") {
|
|
283
|
+
setArg(letters[j], next, arg);
|
|
284
|
+
continue;
|
|
285
|
+
}
|
|
286
|
+
if (/[A-Za-z]/.test(letters[j]) && /=/.test(next)) {
|
|
287
|
+
setArg(letters[j], next.split(/=(.+)/)[1], arg);
|
|
288
|
+
broken = true;
|
|
289
|
+
break;
|
|
290
|
+
}
|
|
291
|
+
if (/[A-Za-z]/.test(letters[j]) &&
|
|
292
|
+
/-?\d+(\.\d*)?(e-?\d+)?$/.test(next)) {
|
|
293
|
+
setArg(letters[j], next, arg);
|
|
294
|
+
broken = true;
|
|
295
|
+
break;
|
|
296
|
+
}
|
|
297
|
+
if (letters[j + 1] && letters[j + 1].match(/\W/)) {
|
|
298
|
+
setArg(letters[j], arg.slice(j + 2), arg);
|
|
299
|
+
broken = true;
|
|
300
|
+
break;
|
|
301
|
+
}
|
|
302
|
+
else {
|
|
303
|
+
setArg(letters[j], get(flags.strings, letters[j]) ? "" : true, arg);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
const [key] = arg.slice(-1);
|
|
307
|
+
if (!broken && key !== "-") {
|
|
308
|
+
if (args[i + 1] &&
|
|
309
|
+
!/^(-|--)[^-]/.test(args[i + 1]) &&
|
|
310
|
+
!get(flags.bools, key) &&
|
|
311
|
+
(get(aliases, key) ? !aliasIsBoolean(key) : true)) {
|
|
312
|
+
setArg(key, args[i + 1], arg);
|
|
313
|
+
i++;
|
|
314
|
+
}
|
|
315
|
+
else if (args[i + 1] && /^(true|false)$/.test(args[i + 1])) {
|
|
316
|
+
setArg(key, args[i + 1] === "true", arg);
|
|
317
|
+
i++;
|
|
318
|
+
}
|
|
319
|
+
else {
|
|
320
|
+
setArg(key, get(flags.strings, key) ? "" : true, arg);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
else {
|
|
325
|
+
if (!flags.unknownFn || flags.unknownFn(arg) !== false) {
|
|
326
|
+
argv._.push(flags.strings["_"] ?? !isNumber(arg) ? arg : Number(arg));
|
|
327
|
+
}
|
|
328
|
+
if (stopEarly) {
|
|
329
|
+
argv._.push(...args.slice(i + 1));
|
|
330
|
+
break;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
for (const [key, value] of Object.entries(defaults)) {
|
|
335
|
+
if (!hasKey(argv, key.split("."))) {
|
|
336
|
+
setKey(argv, key, value);
|
|
337
|
+
if (aliases[key]) {
|
|
338
|
+
for (const x of aliases[key]) {
|
|
339
|
+
setKey(argv, x, value);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
for (const key of Object.keys(flags.bools)) {
|
|
345
|
+
if (!hasKey(argv, key.split("."))) {
|
|
346
|
+
const value = get(flags.collect, key) ? [] : false;
|
|
347
|
+
setKey(argv, key, value, false);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
for (const key of Object.keys(flags.strings)) {
|
|
351
|
+
if (!hasKey(argv, key.split(".")) && get(flags.collect, key)) {
|
|
352
|
+
setKey(argv, key, [], false);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
if (doubleDash) {
|
|
356
|
+
argv["--"] = [];
|
|
357
|
+
for (const key of notFlags) {
|
|
358
|
+
argv["--"].push(key);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
else {
|
|
362
|
+
for (const key of notFlags) {
|
|
363
|
+
argv._.push(key);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
return argv;
|
|
367
|
+
}
|
|
368
|
+
exports.parse = parse;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
3
|
+
// Copyright the Browserify authors. MIT License.
|
|
4
|
+
// Ported from https://github.com/browserify/path-browserify/
|
|
5
|
+
// This module is browser compatible.
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.CHAR_9 = exports.CHAR_0 = exports.CHAR_EQUAL = exports.CHAR_AMPERSAND = exports.CHAR_AT = exports.CHAR_GRAVE_ACCENT = exports.CHAR_CIRCUMFLEX_ACCENT = exports.CHAR_SEMICOLON = exports.CHAR_PERCENT = exports.CHAR_SINGLE_QUOTE = exports.CHAR_DOUBLE_QUOTE = exports.CHAR_PLUS = exports.CHAR_HYPHEN_MINUS = exports.CHAR_RIGHT_CURLY_BRACKET = exports.CHAR_LEFT_CURLY_BRACKET = exports.CHAR_RIGHT_ANGLE_BRACKET = exports.CHAR_LEFT_ANGLE_BRACKET = exports.CHAR_RIGHT_SQUARE_BRACKET = exports.CHAR_LEFT_SQUARE_BRACKET = exports.CHAR_ZERO_WIDTH_NOBREAK_SPACE = exports.CHAR_NO_BREAK_SPACE = exports.CHAR_SPACE = exports.CHAR_HASH = exports.CHAR_EXCLAMATION_MARK = exports.CHAR_FORM_FEED = exports.CHAR_TAB = exports.CHAR_CARRIAGE_RETURN = exports.CHAR_LINE_FEED = exports.CHAR_UNDERSCORE = exports.CHAR_QUESTION_MARK = exports.CHAR_COLON = exports.CHAR_VERTICAL_LINE = exports.CHAR_BACKWARD_SLASH = exports.CHAR_FORWARD_SLASH = exports.CHAR_DOT = exports.CHAR_LOWERCASE_Z = exports.CHAR_UPPERCASE_Z = exports.CHAR_LOWERCASE_A = exports.CHAR_UPPERCASE_A = void 0;
|
|
8
|
+
// Alphabet chars.
|
|
9
|
+
exports.CHAR_UPPERCASE_A = 65; /* A */
|
|
10
|
+
exports.CHAR_LOWERCASE_A = 97; /* a */
|
|
11
|
+
exports.CHAR_UPPERCASE_Z = 90; /* Z */
|
|
12
|
+
exports.CHAR_LOWERCASE_Z = 122; /* z */
|
|
13
|
+
// Non-alphabetic chars.
|
|
14
|
+
exports.CHAR_DOT = 46; /* . */
|
|
15
|
+
exports.CHAR_FORWARD_SLASH = 47; /* / */
|
|
16
|
+
exports.CHAR_BACKWARD_SLASH = 92; /* \ */
|
|
17
|
+
exports.CHAR_VERTICAL_LINE = 124; /* | */
|
|
18
|
+
exports.CHAR_COLON = 58; /* : */
|
|
19
|
+
exports.CHAR_QUESTION_MARK = 63; /* ? */
|
|
20
|
+
exports.CHAR_UNDERSCORE = 95; /* _ */
|
|
21
|
+
exports.CHAR_LINE_FEED = 10; /* \n */
|
|
22
|
+
exports.CHAR_CARRIAGE_RETURN = 13; /* \r */
|
|
23
|
+
exports.CHAR_TAB = 9; /* \t */
|
|
24
|
+
exports.CHAR_FORM_FEED = 12; /* \f */
|
|
25
|
+
exports.CHAR_EXCLAMATION_MARK = 33; /* ! */
|
|
26
|
+
exports.CHAR_HASH = 35; /* # */
|
|
27
|
+
exports.CHAR_SPACE = 32; /* */
|
|
28
|
+
exports.CHAR_NO_BREAK_SPACE = 160; /* \u00A0 */
|
|
29
|
+
exports.CHAR_ZERO_WIDTH_NOBREAK_SPACE = 65279; /* \uFEFF */
|
|
30
|
+
exports.CHAR_LEFT_SQUARE_BRACKET = 91; /* [ */
|
|
31
|
+
exports.CHAR_RIGHT_SQUARE_BRACKET = 93; /* ] */
|
|
32
|
+
exports.CHAR_LEFT_ANGLE_BRACKET = 60; /* < */
|
|
33
|
+
exports.CHAR_RIGHT_ANGLE_BRACKET = 62; /* > */
|
|
34
|
+
exports.CHAR_LEFT_CURLY_BRACKET = 123; /* { */
|
|
35
|
+
exports.CHAR_RIGHT_CURLY_BRACKET = 125; /* } */
|
|
36
|
+
exports.CHAR_HYPHEN_MINUS = 45; /* - */
|
|
37
|
+
exports.CHAR_PLUS = 43; /* + */
|
|
38
|
+
exports.CHAR_DOUBLE_QUOTE = 34; /* " */
|
|
39
|
+
exports.CHAR_SINGLE_QUOTE = 39; /* ' */
|
|
40
|
+
exports.CHAR_PERCENT = 37; /* % */
|
|
41
|
+
exports.CHAR_SEMICOLON = 59; /* ; */
|
|
42
|
+
exports.CHAR_CIRCUMFLEX_ACCENT = 94; /* ^ */
|
|
43
|
+
exports.CHAR_GRAVE_ACCENT = 96; /* ` */
|
|
44
|
+
exports.CHAR_AT = 64; /* @ */
|
|
45
|
+
exports.CHAR_AMPERSAND = 38; /* & */
|
|
46
|
+
exports.CHAR_EQUAL = 61; /* = */
|
|
47
|
+
// Digits
|
|
48
|
+
exports.CHAR_0 = 48; /* 0 */
|
|
49
|
+
exports.CHAR_9 = 57; /* 9 */
|