Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(publish): use file name as label when multiple #179

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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