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

Commit

Permalink
Add pkg.outputPath as a configuration option. (#574)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Symbitic committed Mar 26, 2021
1 parent 165fcd5 commit f08d083
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 6 deletions.
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ are taken from current platform/Node.js. By default targets are
During packaging process `pkg` parses your sources, detects
calls to `require`, traverses the dependencies of your project
and includes them into executable. In most cases you
don't need to specify anything manually. However your code
may have `require(variable)` calls (so called non-literal
don't need to specify anything manually.

However your code may have `require(variable)` calls (so called non-literal
argument to `require`) or use non-javascript files (for
example views, css, images etc).

Expand All @@ -78,18 +79,24 @@ your `package.json` file.
```json
"pkg": {
"scripts": "build/**/*.js",
"assets": "views/**/*"
"assets": "views/**/*",
"targets": [ "node4-linux-armv6" ],
"outputPath: "dist"
}
```

The above example will include everything in `assets/` and
every .js file in `build/`, build only for `node4-linux-armv6`,
and place the executable inside `dist/`.

You may also specify arrays of globs:

```
"assets": [ "assets/**/*", "images/**/*" ]
```

Just be sure to call `pkg package.json` or `pkg .` to make use
of `scripts` and `assets` entries.
Just be sure to call `pkg package.json` or `pkg .` to make
use of `package.json` configuration.

### Scripts

Expand Down
11 changes: 10 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ export async function exec(argv2) {
// output, outputPath

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

if (output && outputPath) {
Expand All @@ -310,6 +310,15 @@ export async function exec(argv2) {
if (!name) {
name = path.basename(inputFin);
}
if (!outputPath) {
if (inputJson && inputJson.pkg) {
outputPath = inputJson.pkg.outputPath;
} else
if (configJson && configJson.pkg) {
outputPath = configJson.pkg.outputPath;
}
outputPath = outputPath || '';
}
autoOutput = true;
const ext = path.extname(name);
output = name.slice(0, -ext.length || undefined);
Expand Down
26 changes: 26 additions & 0 deletions test/test-46-input-package-json-outputdir/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env node

'use strict';

const assert = require('assert');
const utils = require('../utils.js');

assert(!module.parent);
assert(__dirname === process.cwd());

const input = '.';

const newcomers = [
'out/palookaville-linux',
'out/palookaville-macos',
'out/palookaville-win.exe'
];

const before = utils.filesBefore(newcomers);

utils.pkg.sync([
input
], { stdio: 'inherit' });

utils.filesAfter(before, newcomers);
utils.vacuum.sync('out');
7 changes: 7 additions & 0 deletions test/test-46-input-package-json-outputdir/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "palookaville",
"bin": "test-x-index.js",
"pkg": {
"outputPath": "out"
}
}
3 changes: 3 additions & 0 deletions test/test-46-input-package-json-outputdir/test-x-index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

console.log(42);

0 comments on commit f08d083

Please sign in to comment.