Skip to content

Commit

Permalink
Initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
xuhdev committed Nov 13, 2024
0 parents commit ecc8a0b
Show file tree
Hide file tree
Showing 19 changed files with 4,303 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .dir-locals.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
((nil .
((eval .
(add-to-list 'exec-path
(concat (locate-dominating-file default-directory dir-locals-file)
"node_modules/.bin/"))))))
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*.ts]
indent_size = 2
indent_style = space

[*.json]
indent_size = 2
indent_style = space

[README.md]
max_line_length = 100
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @xuhdev
45 changes: 45 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright (C) 2024 8 Hobbies, LLC <[email protected]>
#
# Permission to use, copy, modify, and/or distribute this software for anypurpose with or without
# fee is hereby granted.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIESWITH REGARD TO THIS
# SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OFMERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
# AUTHOR BE LIABLE FORANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
# DAMAGESWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN ANACTION OF CONTRACT,
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OFOR IN CONNECTION WITH THE USE OR PERFORMANCE
# OF THIS SOFTWARE.

name: Lint

on:
push:
branches: ["master"]
pull_request:
branches: ["master"]

jobs:
lint:
name: Lint
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [22.x]

steps:
- uses: actions/checkout@v4

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: "npm"

- name: Install Dependencies
run: |
npm install
- name: Lint
run: |
npm run lint
32 changes: 32 additions & 0 deletions .github/workflows/publish-dry-run.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright (C) 2024 8 Hobbies, LLC <[email protected]>
#
# Permission to use, copy, modify, and/or distribute this software for anypurpose with or without
# fee is hereby granted.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIESWITH REGARD TO THIS
# SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OFMERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
# AUTHOR BE LIABLE FORANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
# DAMAGESWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN ANACTION OF CONTRACT,
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OFOR IN CONNECTION WITH THE USE OR PERFORMANCE
# OF THIS SOFTWARE.
#

name: Publish Dry Run

on:
push:
branches: ["master"]
pull_request:
branches: ["master"]

jobs:
run:
name: Publish Dry Run
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "22.x"
- run: npm ci
- run: npm publish --dry-run
32 changes: 32 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright (C) 2024 8 Hobbies, LLC <[email protected]>
#
# Permission to use, copy, modify, and/or distribute this software for anypurpose with or without
# fee is hereby granted.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIESWITH REGARD TO THIS
# SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OFMERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
# AUTHOR BE LIABLE FORANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
# DAMAGESWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN ANACTION OF CONTRACT,
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OFOR IN CONNECTION WITH THE USE OR PERFORMANCE
# OF THIS SOFTWARE.

name: Publish to npmjs

on:
push:
tags: ["v*"]
jobs:
run:
name: Publish to npmjs
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
# Setup .npmrc file to publish to npm
- uses: actions/setup-node@v4
with:
node-version: "22.x"
registry-url: "https://registry.npmjs.org"
- run: npm ci
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
56 changes: 56 additions & 0 deletions .github/workflows/runtime.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Copyright (C) 2024 8 Hobbies, LLC <[email protected]>
#
# Permission to use, copy, modify, and/or distribute this software for anypurpose with or without
# fee is hereby granted.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIESWITH REGARD TO THIS
# SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OFMERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
# AUTHOR BE LIABLE FORANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
# DAMAGESWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN ANACTION OF CONTRACT,
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OFOR IN CONNECTION WITH THE USE OR PERFORMANCE
# OF THIS SOFTWARE.

name: Runtime

on:
push:
branches: ["master"]
pull_request:
branches: ["master"]

jobs:
test:
name: Runtime
runs-on: ${{ matrix.os }}

strategy:
matrix:
node-version: [18.x, 20.x, 22.x]
os: [ubuntu-latest, macos-latest, windows-latest]
exclude:
# Only test Node 22 on Windows and MacOS
- os: macos-latest
node-version: 18.x
- os: macos-latest
node-version: 20.x
- os: windows-latest
node-version: 18.x
- os: windows-latest
node-version: 20.x

steps:
- uses: actions/checkout@v4

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: "npm"

- name: Install Dependencies
run: |
npm install
- name: Test
run: |
npm test
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/*.tgz
/coverage
/dist
/docs
/node_modules
10 changes: 10 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Copyright (C) 2024 8 Hobbies, LLC <[email protected]>

Permission to use, copy, modify, and/or distribute this software for anypurpose with or without fee
is hereby granted.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIESWITH REGARD TO THIS SOFTWARE
INCLUDING ALL IMPLIED WARRANTIES OFMERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE
LIABLE FORANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGESWHATSOEVER RESULTING
FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN ANACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
ACTION, ARISING OUT OFOR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
63 changes: 63 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# vite-year-plugin

[![npm version](https://badge.fury.io/js/@8hobbies%2Fvite-year-plugin.svg)](https://badge.fury.io/js/@8hobbies%2Fvite-year-plugin)

[GitLab](https://gitlab.com/8hobbies/vite-year-plugin) | [GitHub](https://github.com/8hobbies/vite-year-plugin)

A [Vite][] plugin that inserts the current year to the html file during build. Useful for adding a copyright year.

## Usage

Install with

```sh
npm install --save-dev '@8hobbies/vite-year-plugin'
```

In `vite.config.ts`, add:

```typescript
import yearPlugin from "@8hobbies/vite-year-plugin";

// ...

export default defineConfig({
// ...

plugins: [
// ...
yearPlugin(),
],
});
```

## Contributing

Source code is available on [GitHub][source code].

To report a bug, visit the [issue tracker][].

To run test, run `npm run test`. To build for production, run `npm pack`.

To send your contribution, open a [pull request][].

## License

```
Copyright (C) 2024 8 Hobbies, LLC <[email protected]>
Permission to use, copy, modify, and/or distribute this software for anypurpose with or without
fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIESWITH REGARD TO THIS
SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OFMERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FORANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
DAMAGESWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN ANACTION OF CONTRACT,
NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OFOR IN CONNECTION WITH THE USE OR PERFORMANCE
OF THIS SOFTWARE.
```

[Vite]: https://vite.dev
[issue tracker]: https://github.com/8hobbies/vite-year-plugin/issues
[merge request]: https://github.com/8hobbies/vite-year-plugin/pulls
[source code]: https://github.com/8hobbies/vite-year-plugin
33 changes: 33 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/** @license 0BSD
* Copyright (C) 2024 8 Hobbies, LLC <[email protected]>
*
* Permission to use, copy, modify, and/or distribute this software for anypurpose with or without
* fee is hereby granted.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIESWITH REGARD TO THIS
* SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OFMERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
* AUTHOR BE LIABLE FORANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
* DAMAGESWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN ANACTION OF CONTRACT,
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OFOR IN CONNECTION WITH THE USE OR PERFORMANCE
* OF THIS SOFTWARE.
*/

import configs from "@8hobbies/eslint-conf-baseline";
import globals from "globals";

export default [
...configs.recommended,
{
files: ["**/*.ts"],
ignores: configs.ignores,
languageOptions: {
globals: {
...globals.node,
},
parserOptions: {
project: ["tsconfig.json", "tsconfig.test.json"],
tsconfigRootDir: import.meta.dirname,
},
},
},
];
28 changes: 28 additions & 0 deletions index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/** @license 0BSD
* Copyright (C) 2024 8 Hobbies, LLC <[email protected]>
*
* Permission to use, copy, modify, and/or distribute this software for anypurpose with or without
* fee is hereby granted.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIESWITH REGARD TO THIS
* SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OFMERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
* AUTHOR BE LIABLE FORANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
* DAMAGESWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN ANACTION OF CONTRACT,
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OFOR IN CONNECTION WITH THE USE OR PERFORMANCE
* OF THIS SOFTWARE.
*/

import yearPlugin from "./index.ts";

test("With __YEAR__", () => {
const input = "<p>__YEAR__ is here.</p>" as const;
const expected =
`<p>${new Date().getFullYear().toString()} is here.</p>` as const;
expect(yearPlugin().transformIndexHtml(input)).toBe(expected);
});

test("Without __YEAR__", () => {
const input = "<p>No __YEAR_ present.</p>" as const;
const expected = input;
expect(yearPlugin().transformIndexHtml(input)).toBe(expected);
});
26 changes: 26 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/** @license 0BSD
* Copyright (C) 2024 8 Hobbies, LLC <[email protected]>
*
* Permission to use, copy, modify, and/or distribute this software for anypurpose with or without
* fee is hereby granted.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIESWITH REGARD TO THIS
* SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OFMERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
* AUTHOR BE LIABLE FORANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
* DAMAGESWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN ANACTION OF CONTRACT,
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OFOR IN CONNECTION WITH THE USE OR PERFORMANCE
* OF THIS SOFTWARE.
*/

/**
* The year plugin. Add it to the list of plugins in vite.config.ts. See README.
*/
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export default function yearPlugin() {
return {
name: "year",
transformIndexHtml(html: string): string {
return html.replace("__YEAR__", new Date().getFullYear().toString());
},
} as const;
}
Loading

0 comments on commit ecc8a0b

Please sign in to comment.