npm-pkgbuild 7.8.0 → 7.9.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/package.json +1 -1
- package/src/npm-pkgbuild-cli.mjs +7 -7
- package/src/output/deb.mjs +5 -17
- package/src/output/packager.mjs +1 -1
- package/src/output/pkg.mjs +4 -15
- package/src/output/rpm.mjs +4 -15
- package/src/util.mjs +30 -4
package/package.json
CHANGED
package/src/npm-pkgbuild-cli.mjs
CHANGED
|
@@ -31,6 +31,7 @@ program
|
|
|
31
31
|
return Object.fromEntries([kv]);
|
|
32
32
|
})
|
|
33
33
|
.option("-d --destination <dir>", "where to put the package(s)", cwd)
|
|
34
|
+
.option("--verbose", "be more verbose", false)
|
|
34
35
|
.option("-s --staging <dir>", "staging directory", "build")
|
|
35
36
|
.option(
|
|
36
37
|
"-c --content <dir>",
|
|
@@ -50,10 +51,7 @@ program
|
|
|
50
51
|
|
|
51
52
|
const { properties, sources, output } = await extractFromPackage(
|
|
52
53
|
JSON.parse(
|
|
53
|
-
await readFile(
|
|
54
|
-
join(pkgDir, "package.json"),
|
|
55
|
-
utf8StreamOptions
|
|
56
|
-
)
|
|
54
|
+
await readFile(join(pkgDir, "package.json"), utf8StreamOptions)
|
|
57
55
|
),
|
|
58
56
|
pkgDir
|
|
59
57
|
);
|
|
@@ -77,13 +75,15 @@ program
|
|
|
77
75
|
const context = createContext({ properties });
|
|
78
76
|
const output = new outputFactory(properties);
|
|
79
77
|
|
|
78
|
+
if (options.verbose) {
|
|
79
|
+
console.log(output.properties);
|
|
80
|
+
}
|
|
81
|
+
|
|
80
82
|
const fileName = await output.execute(
|
|
81
83
|
aggregateFifo(sources.map(c => c[Symbol.asyncIterator]())),
|
|
82
84
|
options,
|
|
83
|
-
|
|
85
|
+
path => context.expand(path)
|
|
84
86
|
);
|
|
85
|
-
|
|
86
|
-
console.log(fileName);
|
|
87
87
|
}
|
|
88
88
|
} catch (e) {
|
|
89
89
|
console.log(e);
|
package/src/output/deb.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { execa } from "execa";
|
|
|
3
3
|
import { EmptyContentEntry, ReadableStreamContentEntry } from "content-entry";
|
|
4
4
|
import { keyValueTransformer } from "key-value-transformer";
|
|
5
5
|
import { Packager } from "./packager.mjs";
|
|
6
|
-
import { copyEntries, transform } from "../util.mjs";
|
|
6
|
+
import { copyEntries, transform, fieldProvider } from "../util.mjs";
|
|
7
7
|
|
|
8
8
|
const attributes = [{ pattern: /DEBIAN\/.*(inst|rm)/, mode: 0o775 }];
|
|
9
9
|
|
|
@@ -30,18 +30,7 @@ export class DEB extends Packager {
|
|
|
30
30
|
const mandatoryFields = this.mandatoryFields;
|
|
31
31
|
const staging = await this.tmpdir;
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
if (k === undefined) {
|
|
35
|
-
for (const p of mandatoryFields) {
|
|
36
|
-
if (!presentKeys.has(p)) {
|
|
37
|
-
const v = properties[p];
|
|
38
|
-
yield [p, v === undefined ? fields[p].default : v];
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
} else {
|
|
42
|
-
yield [k, properties[k] || v];
|
|
43
|
-
}
|
|
44
|
-
}
|
|
33
|
+
const fp = fieldProvider(properties, fields, mandatoryFields);
|
|
45
34
|
|
|
46
35
|
const debianControlName = "DEBIAN/control";
|
|
47
36
|
const transformers = [
|
|
@@ -50,7 +39,7 @@ export class DEB extends Packager {
|
|
|
50
39
|
transform: async entry =>
|
|
51
40
|
new ReadableStreamContentEntry(
|
|
52
41
|
entry.name,
|
|
53
|
-
keyValueTransformer(await entry.readStream,
|
|
42
|
+
keyValueTransformer(await entry.readStream, fp)
|
|
54
43
|
),
|
|
55
44
|
createEntryWhenMissing: () => new EmptyContentEntry(debianControlName)
|
|
56
45
|
}
|
|
@@ -59,7 +48,6 @@ export class DEB extends Packager {
|
|
|
59
48
|
await copyEntries(transform(sources, transformers), staging, expander, attributes);
|
|
60
49
|
|
|
61
50
|
const dpkg = await execa("dpkg", ["-b", staging, options.destination]);
|
|
62
|
-
//console.log(dpkg.stdout);
|
|
63
51
|
|
|
64
52
|
return join(options.destination, this.packageFileName);
|
|
65
53
|
}
|
|
@@ -75,8 +63,8 @@ const fields = {
|
|
|
75
63
|
Version: { alias: "version", type: "string", mandatory: true },
|
|
76
64
|
Maintainer: { alias: "maintainer", type: "string", mandatory: true },
|
|
77
65
|
Description: { alias: "description", type: "string", mandatory: true },
|
|
78
|
-
Section: { type: "string"
|
|
79
|
-
Priority: { type: "string"
|
|
66
|
+
Section: { type: "string" },
|
|
67
|
+
Priority: { type: "string" },
|
|
80
68
|
Essential: { type: "boolean" },
|
|
81
69
|
Origin: { type: "string" },
|
|
82
70
|
Architecture: {
|
package/src/output/packager.mjs
CHANGED
package/src/output/pkg.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
equalSeparatedKeyValuePairOptions
|
|
7
7
|
} from "key-value-transformer";
|
|
8
8
|
import { Packager } from "./packager.mjs";
|
|
9
|
-
import { copyEntries, transform } from "../util.mjs";
|
|
9
|
+
import { copyEntries, transform, fieldProvider } from "../util.mjs";
|
|
10
10
|
import { quote, createExpressionTransformer } from "../util.mjs";
|
|
11
11
|
|
|
12
12
|
/**
|
|
@@ -56,19 +56,6 @@ export class PKG extends Packager {
|
|
|
56
56
|
const mandatoryFields = this.mandatoryFields;
|
|
57
57
|
const staging = await this.tmpdir;
|
|
58
58
|
|
|
59
|
-
function* controlProperties(k, v, presentKeys) {
|
|
60
|
-
if (k === undefined) {
|
|
61
|
-
for (const p of mandatoryFields) {
|
|
62
|
-
if (!presentKeys.has(p)) {
|
|
63
|
-
const v = properties[p];
|
|
64
|
-
yield [p, v === undefined ? fields[p].default : v];
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
} else {
|
|
68
|
-
yield [k, properties[k] || v];
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
59
|
async function* trailingLines() {
|
|
73
60
|
yield `
|
|
74
61
|
package() {
|
|
@@ -79,13 +66,15 @@ package() {
|
|
|
79
66
|
|
|
80
67
|
await copyEntries(transform(sources, [createExpressionTransformer(properties)]), join(staging, "src"), expander);
|
|
81
68
|
|
|
69
|
+
const fp = fieldProvider(properties, fields, mandatoryFields);
|
|
70
|
+
|
|
82
71
|
const metaTransformers = [
|
|
83
72
|
{
|
|
84
73
|
match: entry => entry.name === "PKGBUILD",
|
|
85
74
|
transform: async entry =>
|
|
86
75
|
new ReadableStreamContentEntry(
|
|
87
76
|
entry.name,
|
|
88
|
-
keyValueTransformer(await entry.readStream,
|
|
77
|
+
keyValueTransformer(await entry.readStream, fp, {
|
|
89
78
|
...pkgKeyValuePairOptions,
|
|
90
79
|
trailingLines
|
|
91
80
|
})
|
package/src/output/rpm.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
colonSeparatedKeyValuePairOptions
|
|
8
8
|
} from "key-value-transformer";
|
|
9
9
|
import { Packager } from "./packager.mjs";
|
|
10
|
-
import { copyEntries, transform } from "../util.mjs";
|
|
10
|
+
import { copyEntries, transform, fieldProvider } from "../util.mjs";
|
|
11
11
|
|
|
12
12
|
export class RPM extends Packager {
|
|
13
13
|
static get name() {
|
|
@@ -40,18 +40,7 @@ export class RPM extends Packager {
|
|
|
40
40
|
|
|
41
41
|
const staging = join(tmp, "staging");
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
if (k === undefined) {
|
|
45
|
-
for (const p of mandatoryFields) {
|
|
46
|
-
if (!presentKeys.has(p)) {
|
|
47
|
-
const v = properties[p];
|
|
48
|
-
yield [p, v === undefined ? fields[p].default : v];
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
} else {
|
|
52
|
-
yield [k, properties[k] || v];
|
|
53
|
-
}
|
|
54
|
-
}
|
|
43
|
+
const fp = fieldProvider(properties, fields, mandatoryFields);
|
|
55
44
|
|
|
56
45
|
const specFileName = `${properties.name}.spec`;
|
|
57
46
|
|
|
@@ -67,7 +56,7 @@ export class RPM extends Packager {
|
|
|
67
56
|
transform: async entry =>
|
|
68
57
|
new ReadableStreamContentEntry(
|
|
69
58
|
entry.name,
|
|
70
|
-
keyValueTransformer(await entry.readStream,
|
|
59
|
+
keyValueTransformer(await entry.readStream, fp, {
|
|
71
60
|
...colonSeparatedKeyValuePairOptions,
|
|
72
61
|
trailingLines
|
|
73
62
|
})
|
|
@@ -89,7 +78,7 @@ export class RPM extends Packager {
|
|
|
89
78
|
await cp(
|
|
90
79
|
join(tmp, "RPMS", properties.arch, this.packageFileName),
|
|
91
80
|
join(options.destination, this.packageFileName),
|
|
92
|
-
{preserveTimestamps
|
|
81
|
+
{ preserveTimestamps: true }
|
|
93
82
|
);
|
|
94
83
|
return join(options.destination, this.packageFileName);
|
|
95
84
|
}
|
package/src/util.mjs
CHANGED
|
@@ -25,6 +25,24 @@ export function asArray(o) {
|
|
|
25
25
|
return Array.isArray(o) ? o : [o];
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
export function fieldProvider(properties, fields, mandatoryFields) {
|
|
29
|
+
return function* controlProperties(k, v, presentKeys) {
|
|
30
|
+
if (k === undefined) {
|
|
31
|
+
for (const p of mandatoryFields) {
|
|
32
|
+
if (!presentKeys.has(p)) {
|
|
33
|
+
const v = properties[p];
|
|
34
|
+
if (v === undefined && fields[p].default === undefined) {
|
|
35
|
+
console.log(`Missing value for mandatory field ${p}`);
|
|
36
|
+
}
|
|
37
|
+
yield [p, v === undefined ? fields[p].default : v];
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
} else {
|
|
41
|
+
yield [k, properties[k] || v];
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
28
46
|
/**
|
|
29
47
|
* Extract package definition from package.json.
|
|
30
48
|
* @param {Object} pkg package.json content
|
|
@@ -91,7 +109,10 @@ export async function extractFromPackage(pkg, dir) {
|
|
|
91
109
|
return { properties, sources, dependencies, output };
|
|
92
110
|
}
|
|
93
111
|
|
|
94
|
-
export function createExpressionTransformer(
|
|
112
|
+
export function createExpressionTransformer(
|
|
113
|
+
properties,
|
|
114
|
+
match = entry => entry.name.match(/\.(conf|json)$/)
|
|
115
|
+
) {
|
|
95
116
|
async function* transformer(expression, remainder, source, cb) {
|
|
96
117
|
const value = properties[expression];
|
|
97
118
|
console.log("EXPRESSION", expression, value);
|
|
@@ -99,7 +120,7 @@ export function createExpressionTransformer(properties) {
|
|
|
99
120
|
}
|
|
100
121
|
|
|
101
122
|
return {
|
|
102
|
-
match
|
|
123
|
+
match,
|
|
103
124
|
transform: async entry =>
|
|
104
125
|
new ReadableStreamContentEntry(
|
|
105
126
|
entry.name,
|
|
@@ -144,11 +165,17 @@ export async function* transform(source, transformers = [], onlyMatching) {
|
|
|
144
165
|
}
|
|
145
166
|
}
|
|
146
167
|
|
|
168
|
+
/**
|
|
169
|
+
* @typedef {Function} Expander
|
|
170
|
+
* @param {string} path
|
|
171
|
+
* @return {string}
|
|
172
|
+
*/
|
|
173
|
+
|
|
147
174
|
/**
|
|
148
175
|
* Copy content from source into destinationDirectory.
|
|
149
176
|
* @param {AsyncIterator<ContentEntry>} source
|
|
150
177
|
* @param {string} destinationDirectory
|
|
151
|
-
* @param {
|
|
178
|
+
* @param {Expander} expander
|
|
152
179
|
* @param {ContentEntryAttribute[]} attributes
|
|
153
180
|
*/
|
|
154
181
|
export async function copyEntries(
|
|
@@ -175,7 +202,6 @@ export async function copyEntries(
|
|
|
175
202
|
}
|
|
176
203
|
}
|
|
177
204
|
|
|
178
|
-
console.log(destName);
|
|
179
205
|
await pipeline(
|
|
180
206
|
await entry.readStream,
|
|
181
207
|
createWriteStream(destName, options)
|