zarro 1.217.0 → 1.217.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/README.md +24 -0
- package/index-modules/load-defaults.js +92 -0
- package/index.js +2 -77
- package/package.json +10 -10
package/README.md
CHANGED
|
@@ -193,6 +193,30 @@ TEST_EXCLUDE=src/PeanutButter/**/*
|
|
|
193
193
|
Note also here the shorthand of `@` - if a task has the same name as the npm script
|
|
194
194
|
used to invoke it, this is a quick way to surface that task to `npm run` -space.
|
|
195
195
|
|
|
196
|
+
#### Variables for one npm script only
|
|
197
|
+
Variables can be limited to a single npm script by putting them under a `[section]` header,
|
|
198
|
+
named for the npm script (so `npm run release-beta` is `[release-beta]`). Names are
|
|
199
|
+
matched case-insensitively. Variables before any header, or under `[defaults]`, always apply:
|
|
200
|
+
|
|
201
|
+
```
|
|
202
|
+
DOTNET_CORE=1
|
|
203
|
+
|
|
204
|
+
[release]
|
|
205
|
+
NPM_PUBLISH_ACCESS=public
|
|
206
|
+
|
|
207
|
+
[defaults]
|
|
208
|
+
# back to variables which apply to every script
|
|
209
|
+
TEST_EXCLUDE=src/PeanutButter/**/*
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
A section applies until the next header. The usual rules still hold inside a section: the
|
|
213
|
+
value of an existing environment variable wins unless the name is prefixed with `!`.
|
|
214
|
+
|
|
215
|
+
#### Taking a value from another environment variable
|
|
216
|
+
A value which starts with `$` is replaced with the value of the environment variable of
|
|
217
|
+
that name, eg `NPM_TOKEN=$MY_SECRET_TOKEN`. If that variable isn't set, the value is empty
|
|
218
|
+
(which, for a forced `!NAME=$OTHER`, removes `NAME`).
|
|
219
|
+
|
|
196
220
|
## Custom tasks
|
|
197
221
|
|
|
198
222
|
Zarro will also search two folders:
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
(function () {
|
|
3
|
+
const { fileExists, readTextFileLines, writeTextFile } = require("yafs"), debug = require("debug")("zarro::main"), log = requireModule("log");
|
|
4
|
+
const defaultDefaultsFile = ".zarro-defaults", defaultsSection = "defaults", // the section before any [header]
|
|
5
|
+
// the whole (comment-stripped) line must be the header: otherwise a value like PATTERN=[abc] would be one
|
|
6
|
+
sectionHeaderRe = /^\s*\[([\w\s.-]+)]\s*$/;
|
|
7
|
+
async function createZarroDefaultsEmpty(defaultsFile) {
|
|
8
|
+
await writeTextFile(defaultsFile, `# zarro defaults file:
|
|
9
|
+
# place one VARIABLE=VALUE per line below
|
|
10
|
+
# variables here will not override existing environment variables
|
|
11
|
+
# unless prepended with a bang, ie
|
|
12
|
+
# !VARIABLE=Value
|
|
13
|
+
# so this means anything you set in your package.json, eg with
|
|
14
|
+
# cross-env, will override what's in here unless you've specifically
|
|
15
|
+
# marked the setting in here as forced with !
|
|
16
|
+
#
|
|
17
|
+
# a variable can take its value from another environment variable:
|
|
18
|
+
# VARIABLE=$OTHER_VARIABLE
|
|
19
|
+
#
|
|
20
|
+
# variables can be limited to one npm script with a [section] header, eg
|
|
21
|
+
# [release]
|
|
22
|
+
# VARIABLE=Value
|
|
23
|
+
# applies only when running \`npm run release\`; use [defaults] to go
|
|
24
|
+
# back to variables which apply to everything
|
|
25
|
+
`);
|
|
26
|
+
}
|
|
27
|
+
async function loadDefaults(options) {
|
|
28
|
+
var _a, _b, _c;
|
|
29
|
+
const defaultsFile = (_a = options === null || options === void 0 ? void 0 : options.defaultsFile) !== null && _a !== void 0 ? _a : defaultDefaultsFile, env = (_b = options === null || options === void 0 ? void 0 : options.env) !== null && _b !== void 0 ? _b : process.env, taskName = (_c = (options && "taskName" in options
|
|
30
|
+
? options.taskName
|
|
31
|
+
: process.env.npm_lifecycle_event)) !== null && _c !== void 0 ? _c : "", exists = await fileExists(defaultsFile);
|
|
32
|
+
if (!exists) {
|
|
33
|
+
await createZarroDefaultsEmpty(defaultsFile);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const lines = await readTextFileLines(defaultsFile), currentTask = taskName.toLowerCase();
|
|
37
|
+
let currentSection = defaultsSection;
|
|
38
|
+
for (const line of lines) {
|
|
39
|
+
const [code] = splitComment(line);
|
|
40
|
+
if (isEmpty(code)) {
|
|
41
|
+
// comment-only line or empty line
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
const sectionMatch = code.match(sectionHeaderRe);
|
|
45
|
+
if (sectionMatch) {
|
|
46
|
+
currentSection = sectionMatch[1].toLowerCase();
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
if (currentSection !== defaultsSection && currentSection !== currentTask) {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (looksInvalid(code)) {
|
|
53
|
+
log.warn(`invalid config line in ${defaultsFile}:\n${line}`);
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
const parts = code.trim().split("="), name = parts[0], value = parts.slice(1).join("="), forced = name[0] === "!", forwarded = value[0] === "$", notYetSet = env[name] === undefined;
|
|
57
|
+
if (notYetSet || forced) {
|
|
58
|
+
const key = name.replace(/^!/, ""), finalValue = forwarded
|
|
59
|
+
? env[value.substring(1)]
|
|
60
|
+
: value;
|
|
61
|
+
if (finalValue) {
|
|
62
|
+
debug(`setting env var ${key} to '${finalValue}'`);
|
|
63
|
+
env[key] = finalValue;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
debug(`deleting env var ${key}`);
|
|
67
|
+
delete env[key];
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
debug(`env var ${name} is already set, force it by setting !${name}=${value} in ${defaultsFile}`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function looksInvalid(code) {
|
|
76
|
+
return (code || "").indexOf("=") === -1;
|
|
77
|
+
}
|
|
78
|
+
function isEmpty(text) {
|
|
79
|
+
return (text || "").trim() === "";
|
|
80
|
+
}
|
|
81
|
+
function splitComment(line) {
|
|
82
|
+
if (!line) {
|
|
83
|
+
return ["", ""];
|
|
84
|
+
}
|
|
85
|
+
const idx = line.indexOf("#");
|
|
86
|
+
if (idx === -1) {
|
|
87
|
+
return [line, ""];
|
|
88
|
+
}
|
|
89
|
+
return [line.substring(0, idx), line.substring(idx + 1)];
|
|
90
|
+
}
|
|
91
|
+
module.exports = loadDefaults;
|
|
92
|
+
})();
|
package/index.js
CHANGED
|
@@ -11,7 +11,6 @@ const
|
|
|
11
11
|
ls,
|
|
12
12
|
readTextFile,
|
|
13
13
|
fileExists,
|
|
14
|
-
readTextFileLines,
|
|
15
14
|
writeTextFile,
|
|
16
15
|
rm
|
|
17
16
|
} = require("yafs"),
|
|
@@ -19,8 +18,8 @@ const
|
|
|
19
18
|
path = require("path"),
|
|
20
19
|
debug = require("debug")("zarro::main"),
|
|
21
20
|
ZarroError = require("./gulp-tasks/modules/zarro-error"),
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
gatherArgs = require("./index-modules/gather-args"),
|
|
22
|
+
loadDefaults = require("./index-modules/load-defaults");
|
|
24
23
|
|
|
25
24
|
function requireHandler(name) {
|
|
26
25
|
const result = require(`./index-modules/handlers/${name}`);
|
|
@@ -53,80 +52,6 @@ async function findHandlerFor(args) {
|
|
|
53
52
|
return null;
|
|
54
53
|
}
|
|
55
54
|
|
|
56
|
-
const defaultsFile = ".zarro-defaults";
|
|
57
|
-
|
|
58
|
-
async function createZarroDefaultsEmpty() {
|
|
59
|
-
await writeTextFile(defaultsFile, `# zarro defaults file:
|
|
60
|
-
# place one VARIABLE=VALUE per line below
|
|
61
|
-
# variables here will not override existing environment variables
|
|
62
|
-
# unless prepended with a bang, ie
|
|
63
|
-
# !VARIABLE=Value
|
|
64
|
-
# so this means anything you set in your package.json, eg with
|
|
65
|
-
# cross-env, will override what's in here unless you've specifically
|
|
66
|
-
# marked the setting in here as forced with !
|
|
67
|
-
`);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
async function loadDefaults() {
|
|
71
|
-
const
|
|
72
|
-
exists = await fileExists(defaultsFile);
|
|
73
|
-
if (!exists) {
|
|
74
|
-
await createZarroDefaultsEmpty();
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
const
|
|
78
|
-
lines = await readTextFileLines(defaultsFile);
|
|
79
|
-
for (const line of lines) {
|
|
80
|
-
const
|
|
81
|
-
[ code, _ ] = splitComment(line);
|
|
82
|
-
if (isEmpty(code)) {
|
|
83
|
-
// comment-only line or empty line
|
|
84
|
-
continue;
|
|
85
|
-
}
|
|
86
|
-
if (looksInvalid(code)) {
|
|
87
|
-
log.warn(`invalid config line in ${defaultsFile}:\n${line}`);
|
|
88
|
-
continue;
|
|
89
|
-
}
|
|
90
|
-
const
|
|
91
|
-
parts = code.trim().split("="),
|
|
92
|
-
name = parts[0],
|
|
93
|
-
value = Array.from(skip(parts, 1)).join("="),
|
|
94
|
-
forced = name[0] === '!',
|
|
95
|
-
notYetSet = process.env[name] === undefined;
|
|
96
|
-
if (notYetSet || forced) {
|
|
97
|
-
const key = name.replace(/^!/, "");
|
|
98
|
-
if (value) {
|
|
99
|
-
debug(`setting env var ${key} to '${value}'`);
|
|
100
|
-
process.env[key] = value;
|
|
101
|
-
} else {
|
|
102
|
-
debug(`deleting env var ${key}`);
|
|
103
|
-
delete process.env[key];
|
|
104
|
-
}
|
|
105
|
-
} else {
|
|
106
|
-
debug(`env var ${name} is already set, force it by setting !${name}=${value} in ${defaultsFile}`)
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
function looksInvalid(code) {
|
|
112
|
-
return (code || "").indexOf("=") === -1;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function isEmpty(text) {
|
|
116
|
-
return (text || "").trim() === "";
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
function splitComment(line) {
|
|
120
|
-
if (!line) {
|
|
121
|
-
return [ "", "" ];
|
|
122
|
-
}
|
|
123
|
-
const idx = line.indexOf("#");
|
|
124
|
-
if (idx === -1) {
|
|
125
|
-
return [ line, "" ];
|
|
126
|
-
}
|
|
127
|
-
return [ line.substring(0, idx), line.substring(idx + 1) ];
|
|
128
|
-
}
|
|
129
|
-
|
|
130
55
|
async function transpileLocalTaskModules() {
|
|
131
56
|
await Promise.all([
|
|
132
57
|
transpileModulesUnder("local-tasks"),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zarro",
|
|
3
|
-
"version": "1.217.
|
|
3
|
+
"version": "1.217.1",
|
|
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"
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"homepage": "https://github.com/fluffynuts/zarro",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "https://github.com/fluffynuts/zarro"
|
|
11
|
+
"url": "git+https://github.com/fluffynuts/zarro.git"
|
|
12
12
|
},
|
|
13
13
|
"main": "index.js",
|
|
14
14
|
"scripts": {
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"pull-repo-root": "git pull --rebase",
|
|
40
40
|
"pull": "run-s pull-gulp-tasks pull-repo-root",
|
|
41
41
|
"prebuild": "rimraf tsconfig.tsbuildinfo",
|
|
42
|
-
"build": "run-
|
|
42
|
+
"build": "run-s build-fetch-github-release build-zarro",
|
|
43
43
|
"build-zarro": "tsc",
|
|
44
44
|
"prebuild-fetch-github-release": "rimraf gulp-tasks/modules/fetch-github-release/dist",
|
|
45
45
|
"build-fetch-github-release": "tsc -p gulp-tasks/modules/fetch-github-release/tsconfig.json",
|
|
@@ -115,28 +115,28 @@
|
|
|
115
115
|
"license": "BSD-3-Clause",
|
|
116
116
|
"devDependencies": {
|
|
117
117
|
"@faker-js/faker": "^9.9.0",
|
|
118
|
-
"@jest/types": "^
|
|
118
|
+
"@jest/types": "^30.5.1",
|
|
119
119
|
"@types/decompress": "^4.2.4",
|
|
120
120
|
"@types/event-stream": "^4.0.6",
|
|
121
121
|
"@types/fancy-log": "^1.3.1",
|
|
122
122
|
"@types/gulp": "^4.0.8",
|
|
123
|
-
"@types/jest": "^
|
|
123
|
+
"@types/jest": "^30.0.0",
|
|
124
124
|
"@types/node": "^26.6.6",
|
|
125
125
|
"@types/request": "^2.48.8",
|
|
126
126
|
"@types/rimraf": "^3.0.0",
|
|
127
|
-
"@types/semver": "^7.
|
|
127
|
+
"@types/semver": "^7.8.0",
|
|
128
128
|
"@types/through2": "^2.0.38",
|
|
129
129
|
"@types/typescript": "^2.0.0",
|
|
130
130
|
"@types/which": "^3.0.3",
|
|
131
131
|
"@types/xml2js": "^0.4.8",
|
|
132
|
-
"@types/yargs": "^
|
|
132
|
+
"@types/yargs": "^17.0.35",
|
|
133
133
|
"console-cls": "^1.2.2",
|
|
134
134
|
"debug": "^4.3.4",
|
|
135
|
-
"debugger-is-attached": "^1.
|
|
135
|
+
"debugger-is-attached": "^2.1.0",
|
|
136
136
|
"expect-even-more-jest": "^1.19.0",
|
|
137
137
|
"filesystem-sandbox": "^1.20.0",
|
|
138
138
|
"ioredis": "^6.0.0",
|
|
139
|
-
"jest": "^
|
|
139
|
+
"jest": "^30.5.2",
|
|
140
140
|
"nodemon": "^3.0.1",
|
|
141
141
|
"proxyquire": "^2.1.3",
|
|
142
142
|
"redlock": "^5.0.0-beta.2",
|
|
@@ -144,4 +144,4 @@
|
|
|
144
144
|
"typescript": "^6.0.3",
|
|
145
145
|
"yargs": "^18.2.0"
|
|
146
146
|
}
|
|
147
|
-
}
|
|
147
|
+
}
|