Skip to content

Commit c2d47dd

Browse files
authored
Merge pull request #4 from simonkovtyk/feat/2.0.0-next.0
Feat/2.0.0 next.0
2 parents 42455e6 + 4944cf0 commit c2d47dd

File tree

10 files changed

+398
-212
lines changed

10 files changed

+398
-212
lines changed

.github/workflows/pull-request.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Pull request checks
2+
on:
3+
pull_request:
4+
types:
5+
- opened
6+
- reopened
7+
branches:
8+
- main
9+
10+
jobs:
11+
pull_request:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v4
16+
17+
- name: Install
18+
uses: pnpm/action-setup@v4
19+
with:
20+
version: latest
21+
run_install: true
22+
23+
- name: TypeScript Compiler
24+
run: tsc --noEmit
25+
26+
- name: Lint
27+
run: pnpx eslint .

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2024 Simon
3+
Copyright (c) 2024 Simon Kovtyk
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 107 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,147 +1,166 @@
1-
# esbuild plugin for copying files
1+
<div align="center">
22

3-
![NPM Downloads](https://img.shields.io/npm/dw/esbuild-plugin-file-copy) ![NPM License](https://img.shields.io/npm/l/esbuild-plugin-file-copy)
3+
<img width="196" src="https://raw.githubusercontent.com/simonkovtyk/esbuild-plugin-file-copy/611c5c4942c8460ec6247ab833418908e9213a9b/docs/esbuild-favicon.svg" />
44

5-
The plugin copies files to the esbuild out folder, ensuring that all required files are included alongside the built code.
5+
<h1>File Copy Plugin</h1>
66

7-
* Supports newest esbuild version
8-
* Advanced with globs
9-
* Uses raw filesystem calls
10-
* Uses esbuild config to determine the out folder
11-
* Type declarations (d.ts) included
7+
<p>This esbuild plugin copies specified files to the output folder after the bundling process. It ensures static assets are included in the final build without interrupting or altering the main esbuild workflow.</p>
128

13-
## How It Works
9+
![NPM Downloads](https://img.shields.io/npm/dw/esbuild-plugin-file-copy)
10+
![NPM License](https://img.shields.io/npm/l/esbuild-plugin-file-copy)
11+
![GitHub package.json version](https://img.shields.io/npm/v/esbuild-plugin-file-copy)
12+
![TypeScript types](https://img.shields.io/badge/TypeScript_types-included-blue)
1413

15-
1. Parses the file paths by globs
16-
2. Creates folder for the file paths, if there are not exists.
17-
3. Determines the out-folder by using the existing esbuild configuration.
18-
4. Writes the files to their responsible out paths.
14+
<br />
1915

20-
This plugin prefers an ``outdir`` over an ``outfile``, but if only an ``outfile`` is provided, the plugin will choose the directory of the ``outfile`` as base output directory for the files
21-
instead.\
22-
The ``outbase`` is used as a prefix for the ``outdir`` or ``outfile`` and it can be left as empty, if it is not needed.
16+
Add a ⭐ to this repository — *it motivates me a lot!*
2317

24-
## Options
18+
</div>
2519

26-
### Input files to copy them
20+
## ⚡️ Getting started
2721

28-
Files can be provided as glob.\
29-
[See here for more about the syntax of globs.](https://github.com/mrmlnc/fast-glob?tab=readme-ov-file#pattern-syntax)
22+
Simply install this package with your package manager.
3023

31-
#### Simple including
32-
33-
It is possible to provide globs only as ``string``:
34-
````typescript
35-
fileCopyPlugin({
36-
inputs: [
37-
"src/**/README.md"
38-
]
39-
})
24+
````shell
25+
npm install -D esbuild-plugin-file-copy
4026
````
4127

42-
In this case, the output directory of the matching files is the output directory of the esbuild configuration, because no output directory else was specified.
28+
<details>
29+
<summary>📦 other package manager</summary>
4330

44-
If you want an option to handle the output directory of the files by yourself, you should follow the advanced including.
31+
Here are examples for installing the package with other package manager.
4532

46-
#### Advanced including
33+
> 💾 **yarn**
34+
> ````shell
35+
> yarn add -D esbuild-plugin-file-copy
36+
> ````
4737
48-
It is also possible to provide globs as ``Object``.
38+
> 💾 **pnpm**
39+
> ````shell
40+
> pnpm install -D esbuild-plugin-file-copy
41+
> ````
4942
50-
````typescript
51-
fileCopyPlugin({
52-
inputs: [
53-
{
54-
glob: "src/**/README.md",
55-
output: "somefolder/anyfolder"
56-
}
57-
]
58-
})
59-
````
43+
</details>
44+
45+
Looks good so far 🔥 — now you have installed the latest version!
6046
61-
The ``Object`` expects a key "glob" and an optional key "output".
47+
## 💡 Introduction
6248
49+
This esbuild plugin simply copies specified files to the output folder during the build process. It reads a list of file paths or patterns, then moves those files into the output directory after
50+
esbuild finishes bundling.
6351
64-
If the key "output" is set, the output directory of the files will be the given output directory **without** the output directory of the esbuild configuration as base output directory.
52+
The plugin ensures that static assets, such as images or configuration files, are included in the final build. It’s lightweight and works without altering the bundling
53+
process itself. By automating file copying, it reduces manual steps and keeps the build process smooth and consistent.
6554
66-
If the key "output" is not set, the output directory will be the base output directory of the esbuild configuration.
55+
## 🔧 Usage
6756
68-
### Base output directory
57+
```typescript
58+
fileCopyPlugin(options);
59+
```
6960
70-
This plugin will use the esbuild configuration to determine the base output directory for the files.\
71-
Sometimes it can be helpful to overwrite the base output directory.
61+
This function needs to be called inside the esbuild configuration in order to use this plugin. It will provide the plugin inside the build process of esbuild.
62+
63+
<details>
64+
<summary>Show an example of the integration</summary>
7265
7366
````typescript
74-
fileCopyPlugin(
75-
overrideOutBase?: string | undefined,
76-
overrideOutDir?: string | undefined,
77-
overrideOutFile?: string | undefined
78-
);
67+
esbuild.build({
68+
// some esbuild configuration...
69+
plugins: [
70+
fileCopyPlugin(
71+
// configure it here...
72+
);
73+
// more esbuild plugins here...
74+
]
75+
})
7976
````
8077
81-
Each overwrite will overwrite the specific esbuild configuration.
78+
</details>
79+
80+
### Properties
8281

83-
[See here for more details about the out configuration of esbuild.](https://esbuild.github.io/api/#outbase)
82+
#### ``inputs``
8483

85-
### Lifecycle
84+
> Default: ``undefined``
8685
87-
You can configure at which lifecycle of esbuild the plugin will be called.
86+
A ``Array`` of ``object`` with the following properties:
8887

8988
````typescript
90-
fileCopyPlugin(
91-
lifecycle: "onStart" | "onEnd" | "onDispose" | undefined
92-
);
89+
{
90+
from: string,
91+
to: string
92+
}
9393
````
9494

95-
[See here for more about the esbuild lifecycles.](https://esbuild.github.io/plugins/#concepts)
95+
Any file or directory from the source path (``from`` key) will be copied to the target path (``to`` key).
9696

97-
## Usage
97+
The file name will be kept while copying the file from source path to target path.
9898

99-
### Installation
99+
<details>
100+
<summary>Show an example</summary>
100101

101-
The plugin can be installed by any package manager.
102+
````typescript
103+
fileCopyPlugin({
104+
inputs: [{
105+
from: "my-lib/example.ts", // input path
106+
to: "dist/my-lib" // copied to path
107+
}]
108+
});
109+
````
102110

103-
<details><summary><b>Show instructions</b></summary>
111+
</details>
104112

105-
> npm \
106-
> ``npm install esbuild-plugin-file-copy``
113+
#### ``globs``
107114

108-
> yarn \
109-
> ``yarn install esbuild-plugin-file-copy``
115+
> Default: ``undefined``
110116
111-
> pnpm \
112-
> ``pnpm install esbuild-plugin-file-copy``
117+
A ``Array`` of ``object`` with the following properties:
113118

114-
</details>
119+
````typescript
120+
{
121+
from: string,
122+
to: string
123+
}
124+
````
115125

116-
### Integration
126+
Any matching file or directory from the source path (``from`` key) will be copied to the target path (``to`` key).
117127

118-
The easy way to integrate this plugin in esbuild.
128+
The file name will be kept while copying the file from source path to target path.
119129

120-
<details><summary><b>Show instructions</b></summary>
130+
This option enables the use of glob patterns. [See here](https://www.malikbrowne.com/blog/a-beginners-guide-glob-patterns/) for more about glob patterns.
131+
132+
<details>
133+
<summary>Show an example</summary>
121134

122135
````typescript
123-
await esbuild.build({
124-
[...]
125-
plugins: [
126-
fileCopyPlugin(...)
127-
]
128-
})
136+
fileCopyPlugin({
137+
globs: [{
138+
from: "my-lib/**/*.env", // input path
139+
to: "dist/my-lib" // copied to path
140+
}]
141+
});
129142
````
130143

131-
[See here for more about the esbuild plugin integration.](https://esbuild.github.io/plugins/#using-plugins)
132-
133144
</details>
134145

146+
### Returns
147+
148+
Type: ``Plugin``
149+
150+
An instance of this plugin, that will be used by esbuild automatically.
151+
135152
## License
136153

137-
The MIT License (MIT) - Please have a look at the LICENSE file for more details.
154+
The MIT License (MIT) - Please have a look at the [License](https://github.com/simonkovtyk/esbuild-plugin-file-copy/blob/main/LICENSE) file for more details.
138155

139156
## Contributing
140157

141-
Feel free to contribute to this project.\
142-
You can fork this project and create a new pull request for contributing.
158+
Want to contribute to an open-source project on GitHub but unsure where to start? Check out this comprehensive step-by-step guide on how to contribute effectively!
159+
160+
From forking the repository to creating pull requests, this guide walks you through every stage of the process, helping you make a successful contribution to this GitHub project. Start collaborating,
161+
learn new skills, and make an impact on this project!
143162

144-
[Get to the repository at GitHub.](https://github.com/simonkovtyk/esbuild-plugin-file-copy)
163+
[See here](https://github.com/simonkovtyk/esbuild-plugin-file-copy/blob/main/docs/guides/HOW_TO_CONTRIBUTE.md) for the contribute guide at GitHub.
145164

146165
<hr>
147166

docs/esbuild-favicon.svg

Lines changed: 7 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)