Skip to content

Commit

Permalink
fix(publish): use file name as label when multiple (#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
nfriend authored Dec 1, 2020
1 parent 5190621 commit 81cd6a8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ Create a [personal access token](https://docs.gitlab.com/ce/user/profile/persona
Can be a [glob](https://github.com/isaacs/node-glob#glob-primer) or and `Array` of
[globs](https://github.com/isaacs/node-glob#glob-primer) and `Object`s with the following properties:

| Property | Description | Default |
| -------- | -------------------------------------------------------------------------------------------------------- | ------------------------------------ |
| `path` | **Required.** A [glob](https://github.com/isaacs/node-glob#glob-primer) to identify the files to upload. | - |
| `label` | Short description of the file displayed on the GitLab release. | File name extracted from the `path`. |
| Property | Description | Default |
| -------- | ----------------------------------------------------------------------------------------------------------- | ------------------------------------ |
| `path` | **Required.** A [glob](https://github.com/isaacs/node-glob#glob-primer) to identify the files to upload. | - |
| `label` | Short description of the file displayed on the GitLab release. Ignored if `path` matches more than one file.| File name extracted from the `path`. |

Each entry in the `assets` `Array` is globbed individually. A [glob](https://github.com/isaacs/node-glob#glob-primer)
can be a `String` (`"dist/**/*.js"` or `"dist/mylib.js"`) or an `Array` of `String`s that will be globbed together
Expand Down
4 changes: 2 additions & 2 deletions lib/glob-assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ module.exports = async ({cwd}, assets) =>
// If asset is an Object with a glob the `path` property that resolve to multiple files,
// Output an Object definition for each file matched and set each one with:
// - `path` of the matched file
// - `name` based on the actual file name (to avoid assets with duplicate `name`)
// - `label` based on the actual file name (to avoid assets with duplicate `label`s)
// - other properties of the original asset definition
return globbed.map(file => ({...asset, path: file, name: basename(file)}));
return globbed.map(file => ({...asset, path: file, label: basename(file)}));
}

// If asset is an Object, output an Object definition with:
Expand Down
6 changes: 3 additions & 3 deletions test/glob-assets.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,13 @@ test('Accept glob array with one value for missing files', async t => {
test('Replace name by filename for Object that match multiple files', async t => {
const cwd = tempy.directory();
await copy(fixtures, cwd);
const globbedAssets = await globAssets({cwd}, [{path: '*.txt', name: 'upload_name', label: 'Upload label'}]);
const globbedAssets = await globAssets({cwd}, [{path: '*.txt', label: 'Upload label'}]);

t.deepEqual(
sortAssets(globbedAssets),
sortAssets([
{path: 'upload.txt', name: 'upload.txt', label: 'Upload label'},
{path: 'upload_other.txt', name: 'upload_other.txt', label: 'Upload label'},
{path: 'upload.txt', label: 'upload.txt'},
{path: 'upload_other.txt', label: 'upload_other.txt'},
])
);
});
Expand Down

0 comments on commit 81cd6a8

Please sign in to comment.