Skip to content
This repository was archived by the owner on Jan 13, 2024. It is now read-only.

Commit f08d083

Browse files
authored
Add pkg.outputPath as a configuration option. (#574)
This allows the output path to be specified in package.json, instead of needing to be manually passed as a command-line argument every time.
1 parent 165fcd5 commit f08d083

File tree

5 files changed

+58
-6
lines changed

5 files changed

+58
-6
lines changed

README.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ are taken from current platform/Node.js. By default targets are
6161
During packaging process `pkg` parses your sources, detects
6262
calls to `require`, traverses the dependencies of your project
6363
and includes them into executable. In most cases you
64-
don't need to specify anything manually. However your code
65-
may have `require(variable)` calls (so called non-literal
64+
don't need to specify anything manually.
65+
66+
However your code may have `require(variable)` calls (so called non-literal
6667
argument to `require`) or use non-javascript files (for
6768
example views, css, images etc).
6869

@@ -78,18 +79,24 @@ your `package.json` file.
7879
```json
7980
"pkg": {
8081
"scripts": "build/**/*.js",
81-
"assets": "views/**/*"
82+
"assets": "views/**/*",
83+
"targets": [ "node4-linux-armv6" ],
84+
"outputPath: "dist"
8285
}
8386
```
8487

88+
The above example will include everything in `assets/` and
89+
every .js file in `build/`, build only for `node4-linux-armv6`,
90+
and place the executable inside `dist/`.
91+
8592
You may also specify arrays of globs:
8693

8794
```
8895
"assets": [ "assets/**/*", "images/**/*" ]
8996
```
9097

91-
Just be sure to call `pkg package.json` or `pkg .` to make use
92-
of `scripts` and `assets` entries.
98+
Just be sure to call `pkg package.json` or `pkg .` to make
99+
use of `package.json` configuration.
93100

94101
### Scripts
95102

lib/index.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ export async function exec(argv2) {
290290
// output, outputPath
291291

292292
let output = argv.o || argv.output;
293-
const outputPath = argv['out-path'] || argv.outdir || argv['out-dir'];
293+
let outputPath = argv['out-path'] || argv.outdir || argv['out-dir'];
294294
let autoOutput = false;
295295

296296
if (output && outputPath) {
@@ -310,6 +310,15 @@ export async function exec(argv2) {
310310
if (!name) {
311311
name = path.basename(inputFin);
312312
}
313+
if (!outputPath) {
314+
if (inputJson && inputJson.pkg) {
315+
outputPath = inputJson.pkg.outputPath;
316+
} else
317+
if (configJson && configJson.pkg) {
318+
outputPath = configJson.pkg.outputPath;
319+
}
320+
outputPath = outputPath || '';
321+
}
313322
autoOutput = true;
314323
const ext = path.extname(name);
315324
output = name.slice(0, -ext.length || undefined);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env node
2+
3+
'use strict';
4+
5+
const assert = require('assert');
6+
const utils = require('../utils.js');
7+
8+
assert(!module.parent);
9+
assert(__dirname === process.cwd());
10+
11+
const input = '.';
12+
13+
const newcomers = [
14+
'out/palookaville-linux',
15+
'out/palookaville-macos',
16+
'out/palookaville-win.exe'
17+
];
18+
19+
const before = utils.filesBefore(newcomers);
20+
21+
utils.pkg.sync([
22+
input
23+
], { stdio: 'inherit' });
24+
25+
utils.filesAfter(before, newcomers);
26+
utils.vacuum.sync('out');
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "palookaville",
3+
"bin": "test-x-index.js",
4+
"pkg": {
5+
"outputPath": "out"
6+
}
7+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict';
2+
3+
console.log(42);

0 commit comments

Comments
 (0)