@open-xchange/vite-plugin-project-meta 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vscode/settings.json +3 -0
- package/CHANGELOG.md +5 -0
- package/LICENSE +21 -0
- package/README.md +63 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +49 -0
- package/dist/virtual.d.ts +37 -0
- package/package.json +47 -0
package/CHANGELOG.md
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 OX Software GmbH, Germany <info@open-xchange.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# @open-xchange/vite-plugin-project-meta
|
|
2
|
+
|
|
3
|
+
A Vite plugin providing a virtual import for project metadata with build information.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
Add the plugin to your Vite configuration:
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
// vite.config.ts
|
|
11
|
+
|
|
12
|
+
import { defineConfig } from "vite" // or "vitest/config"
|
|
13
|
+
import metaPlugin from "@open-xchange/vite-plugin-project-meta"
|
|
14
|
+
|
|
15
|
+
export default defineConfig(() => {
|
|
16
|
+
|
|
17
|
+
// ...
|
|
18
|
+
|
|
19
|
+
plugins: [
|
|
20
|
+
// ...
|
|
21
|
+
|
|
22
|
+
metaPlugin({
|
|
23
|
+
id: "my-project-ui"
|
|
24
|
+
name: "My Project UI",
|
|
25
|
+
}),
|
|
26
|
+
],
|
|
27
|
+
})
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Register TypeScript type definitions for the "virtual:metadata" module import:
|
|
31
|
+
|
|
32
|
+
```json
|
|
33
|
+
// src/tsconfig.json
|
|
34
|
+
|
|
35
|
+
{
|
|
36
|
+
// ...
|
|
37
|
+
|
|
38
|
+
"types": [
|
|
39
|
+
"vite/client",
|
|
40
|
+
"@open-xchange/vite-plugin-project-meta/virtual"
|
|
41
|
+
],
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Use the virtual module in your code:
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
// src/path/to/some/module.ts
|
|
49
|
+
|
|
50
|
+
import metadata from "virtual:metadata"
|
|
51
|
+
|
|
52
|
+
console.log(metadata.id) // from package.json ("name")
|
|
53
|
+
console.log(metadata.name) // from `options.projectName`
|
|
54
|
+
console.log(metadata.version) // from package.json ("version")
|
|
55
|
+
console.log(metadata.builddate) // plugin execution timestamp
|
|
56
|
+
console.log(metadata.commitsha) // from env variable "CI_COMMIT_SHA"
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Options
|
|
60
|
+
|
|
61
|
+
| Name | Type | Default | Description |
|
|
62
|
+
| - | - | - | - |
|
|
63
|
+
| `projectName` | `string` | _required_ | Display name of the project, for metadata property "name". |
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Plugin } from "vite";
|
|
2
|
+
/**
|
|
3
|
+
* Configuration options for the plugin "@open-xchange/vite-plugin-project-meta".
|
|
4
|
+
*/
|
|
5
|
+
export interface VitePluginProjectMetaOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The display name of the project.
|
|
8
|
+
*/
|
|
9
|
+
projectName: string;
|
|
10
|
+
}
|
|
11
|
+
export declare const PROJECT_NAME = "@open-xchange/vite-plugin-project-meta";
|
|
12
|
+
/**
|
|
13
|
+
* Vite plugin that provides a virtual module "virtual:metadata" exporting a
|
|
14
|
+
* metadata object with project build information (timestamp, commit ID, etc.).
|
|
15
|
+
*
|
|
16
|
+
* @param options
|
|
17
|
+
* Plugin configuration.
|
|
18
|
+
*
|
|
19
|
+
* @returns
|
|
20
|
+
* The Vite plugin object.
|
|
21
|
+
*/
|
|
22
|
+
export default function vitePluginProjectMeta(options: VitePluginProjectMetaOptions): Plugin;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) Open-Xchange GmbH, Germany <info@open-xchange.com>
|
|
3
|
+
*
|
|
4
|
+
* This program is proprietary software and licensed to you under Open-Xchange
|
|
5
|
+
* GmbH's Software License Agreement.
|
|
6
|
+
*/
|
|
7
|
+
import { join } from "node:path";
|
|
8
|
+
import { readFileSync } from "node:fs";
|
|
9
|
+
// constants ==================================================================
|
|
10
|
+
export const PROJECT_NAME = "@open-xchange/vite-plugin-project-meta";
|
|
11
|
+
// plugin =====================================================================
|
|
12
|
+
/**
|
|
13
|
+
* Vite plugin that provides a virtual module "virtual:metadata" exporting a
|
|
14
|
+
* metadata object with project build information (timestamp, commit ID, etc.).
|
|
15
|
+
*
|
|
16
|
+
* @param options
|
|
17
|
+
* Plugin configuration.
|
|
18
|
+
*
|
|
19
|
+
* @returns
|
|
20
|
+
* The Vite plugin object.
|
|
21
|
+
*/
|
|
22
|
+
export default function vitePluginProjectMeta(options) {
|
|
23
|
+
const MODULE_NAME = "virtual:metadata";
|
|
24
|
+
const MODULE_ID = `\0${PROJECT_NAME}/${MODULE_NAME}`;
|
|
25
|
+
let metadata;
|
|
26
|
+
return {
|
|
27
|
+
name: PROJECT_NAME,
|
|
28
|
+
configResolved(config) {
|
|
29
|
+
const pkg = JSON.parse(readFileSync(join(config.root, "package.json"), { encoding: "utf8" }));
|
|
30
|
+
metadata = {
|
|
31
|
+
id: pkg.name,
|
|
32
|
+
name: options.projectName,
|
|
33
|
+
version: pkg.version,
|
|
34
|
+
builddate: new Date().toISOString(),
|
|
35
|
+
commitsha: process.env.CI_COMMIT_SHA,
|
|
36
|
+
};
|
|
37
|
+
},
|
|
38
|
+
resolveId(source) {
|
|
39
|
+
return (source === MODULE_NAME) ? MODULE_ID : null;
|
|
40
|
+
},
|
|
41
|
+
load(id) {
|
|
42
|
+
if (id !== MODULE_ID) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
const code = `export default ${JSON.stringify(metadata)};`;
|
|
46
|
+
return { code, map: { mappings: "" } };
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
declare module "virtual:metadata" {
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Shape of the metadata object provided by the virtual module "virtual:metadata".
|
|
5
|
+
*/
|
|
6
|
+
export interface VirtualProjectMetadata {
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Internal identifier of the project.
|
|
10
|
+
*/
|
|
11
|
+
id: string;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The display name of the project.
|
|
15
|
+
*/
|
|
16
|
+
name: string;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The version string of the package.
|
|
20
|
+
*/
|
|
21
|
+
version: string;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The date when the package was built (ISO timestamp).
|
|
25
|
+
*/
|
|
26
|
+
builddate: string;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The identifier of the last GIT commit the package has been built on.
|
|
30
|
+
* Will be picked from the environment variable "CI_COMMIT_SHA".
|
|
31
|
+
*/
|
|
32
|
+
commitsha: string | undefined;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const metadata: VirtualProjectMetadata;
|
|
36
|
+
export default metadata;
|
|
37
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@open-xchange/vite-plugin-project-meta",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Vite plugin providing a virtual import for project metadata",
|
|
5
|
+
"repository": {
|
|
6
|
+
"url": "https://gitlab.open-xchange.com/fspd/npm-packages/vite-plugin-project-meta"
|
|
7
|
+
},
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"engines": {
|
|
10
|
+
"node": "18.18.0 || ^20.9.0 || >=21.1.0"
|
|
11
|
+
},
|
|
12
|
+
"packageManager": "yarn@4.3.1",
|
|
13
|
+
"type": "module",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"default": "./dist/index.js"
|
|
18
|
+
},
|
|
19
|
+
"./virtual": {
|
|
20
|
+
"types": "./dist/virtual.d.ts"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"prepare": "husky",
|
|
25
|
+
"prepack": "yarn build && yarn lint",
|
|
26
|
+
"build": "npx --yes rimraf dist && tsc && cpy --flat src/virtual.d.ts dist/",
|
|
27
|
+
"lint": "eslint ."
|
|
28
|
+
},
|
|
29
|
+
"lint-staged": {
|
|
30
|
+
"*.{js,ts,json}": "yarn lint"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@open-xchange/linter-presets": "0.1.11",
|
|
34
|
+
"@types/node": "20.14.13",
|
|
35
|
+
"cpy-cli": "5.0.0",
|
|
36
|
+
"eslint": "9.8.0",
|
|
37
|
+
"husky": "9.1.4",
|
|
38
|
+
"typescript": "5.5.4",
|
|
39
|
+
"vite": "5.3.5"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"vite": "^5.3"
|
|
43
|
+
},
|
|
44
|
+
"resolutions": {
|
|
45
|
+
"semver": "^7.6.2"
|
|
46
|
+
}
|
|
47
|
+
}
|