screw-up 0.8.1 → 0.10.0

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/README.md CHANGED
@@ -4,7 +4,6 @@ Simply package metadata inserter for Vite plugins.
4
4
 
5
5
  [![Project Status: WIP – Initial development is in progress, but there has not yet been a stable, usable release suitable for the public.](https://www.repostatus.org/badges/latest/wip.svg)](https://www.repostatus.org/#wip)
6
6
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
- [![npm version](https://img.shields.io/npm/v/screw-up.svg)](https://www.npmjs.com/package/screw-up)
8
7
 
9
8
  ----
10
9
 
@@ -37,6 +36,7 @@ To insert banner header each bundled source files (`dist/index.js` and etc.):
37
36
  * author: Jane Developer <jane@example.com>
38
37
  * license: Apache-2.0
39
38
  * repository.url: https://github.com/user/my-awesome-library
39
+ * git.commit.hash: c94eaf71dcc6522aae593c7daf85bb745112caf0
40
40
  */
41
41
  // Your bundled code here...
42
42
  ```
@@ -48,253 +48,16 @@ To insert banner header each bundled source files (`dist/index.js` and etc.):
48
48
  * Flexible output: Specify exactly which keys to include and in what order.
49
49
  * Nested object support: Handles nested objects like `author.name`, `repository.url`.
50
50
  * Customizable: Choose which metadata fields to include in your banner.
51
- * TypeScript metadata generation: Automatically generates TypeScript files with metadata constants for use in your source code.
52
-
53
- ## Installation
54
-
55
- ```bash
56
- npm install --save-dev screw-up
57
- ```
58
-
59
- ----
60
-
61
- ## Usage
62
-
63
- ### Basic Usage
64
-
65
- Add the plugin to your `vite.config.ts`:
66
-
67
- ```typescript
68
- import { defineConfig } from 'vite';
69
- import screwUp from 'screw-up';
70
-
71
- export default defineConfig({
72
- plugins: [
73
- screwUp() // Uses default output keys
74
- ],
75
- build: {
76
- lib: {
77
- entry: 'src/index.ts',
78
- name: 'MyLibrary',
79
- fileName: 'index'
80
- }
81
- }
82
- });
83
- ```
84
-
85
- When no `outputKeys` are specified, the plugin uses these default keys with exact sequence:
86
- `name`, `version`, `description`, `author`, `license` and `repository.url`.
87
-
88
- ### Custom Output Keys
89
-
90
- You can specify which metadata fields to include and in what order:
91
-
92
- ```typescript
93
- import { defineConfig } from 'vite';
94
- import screwUp from 'screw-up';
95
-
96
- export default defineConfig({
97
- plugins: [
98
- screwUp({
99
- outputKeys: ['name', 'version', 'license'] // Only include these fields
100
- })
101
- ],
102
- build: {
103
- lib: {
104
- entry: 'src/index.ts',
105
- name: 'MyLibrary',
106
- fileName: 'index'
107
- }
108
- }
109
- });
110
- ```
111
-
112
- This will generate a banner with only the specified fields:
113
-
114
- ```javascript
115
- /*!
116
- * name: my-awesome-library
117
- * version: 2.1.0
118
- * license: Apache-2.0
119
- */
120
- ```
121
-
122
- ### Working with Nested Objects
123
-
124
- The plugin automatically flattens nested objects using dot notation:
125
-
126
- ```json
127
- {
128
- "name": "my-package",
129
- "author": {
130
- "name": "Jane Developer",
131
- "email": "jane@example.com"
132
- },
133
- "repository": {
134
- "type": "git",
135
- "url": "https://github.com/user/my-package"
136
- }
137
- }
138
- ```
139
-
140
- You can reference nested fields in your `outputKeys`:
141
-
142
- ```typescript
143
- screwUp({
144
- outputKeys: ['name', 'author.name', 'author.email', 'repository.url']
145
- })
146
- ```
147
-
148
- Results in:
149
-
150
- ```javascript
151
- /*!
152
- * name: my-package
153
- * author.name: Jane Developer
154
- * author.email: jane@example.com
155
- * repository.url: https://github.com/user/my-package
156
- */
157
- ```
158
-
159
- ### TypeScript Metadata Generation
160
-
161
- The plugin can generate TypeScript files containing metadata constants that you can import and use in your source code:
162
-
163
- ```typescript
164
- import { defineConfig } from 'vite';
165
- import screwUp from 'screw-up';
166
-
167
- export default defineConfig({
168
- plugins: [
169
- screwUp({
170
- outputMetadataFile: true, // Enable metadata file generation
171
- outputMetadataFilePath: 'src/generated/packageMetadata.ts', // Custom path (optional)
172
- outputMetadataKeys: ['name', 'version', 'description', 'author', 'license'] // Keys to include
173
- })
174
- ],
175
- build: {
176
- lib: {
177
- entry: 'src/index.ts',
178
- name: 'MyLibrary',
179
- fileName: 'index'
180
- }
181
- }
182
- });
183
- ```
184
-
185
- This generates `src/generated/packageMetadata.ts` with sanitized TypeScript constants:
186
-
187
- ```typescript
188
- // This file is auto-generated by screw-up plugin
189
- // Do not edit manually
190
-
191
- export const name = "my-awesome-library";
192
- export const version = "2.1.0";
193
- export const description = "An awesome TypeScript library";
194
- export const author = "Jane Developer <jane@example.com>";
195
- export const license = "Apache-2.0";
196
- ```
197
-
198
- You can then import and use these constants in your source code:
199
-
200
- ```typescript
201
- import { name, version } from './generated/packageMetadata.js';
202
-
203
- console.log(`${name} v${version}`);
204
- // Output: my-awesome-library v2.1.0
205
-
206
- export function getLibraryInfo() {
207
- return { name, version };
208
- }
209
- ```
210
-
211
- #### Key Sanitization
212
-
213
- Keys with special characters are automatically sanitized to valid TypeScript identifiers:
214
-
215
- - `repository.url` → `repository_url`
216
- - `custom-key` → `custom_key`
217
- - `123invalid` → `_123invalid`
51
+ * TypeScript metadata generation: Can automatically generates TypeScript files with metadata constants for use in your source code.
52
+ * Git metadata extraction: Automatically extracts Git commit hash, tags, branches, and version information from local Git repository.
53
+ * Supported pack/publish CLI interface: When publishing using this feature, the package is generated after applying the above processing to `package.json`.
218
54
 
219
55
  ----
220
56
 
221
- ## Advanced Usage
222
-
223
- ### Monorepo Support
224
-
225
- The plugin automatically detects workspace configurations and inherits metadata from parent packages:
226
-
227
- ```
228
- my-monorepo/
229
- ├── package.json # Root package with shared metadata
230
- ├── packages/
231
- │ ├── ui/
232
- │ │ └── package.json # Child package
233
- │ └── core/
234
- │ └── package.json # Child package
235
- ```
236
-
237
- Child packages automatically inherit metadata from the root package, with the ability to override specific fields:
238
-
239
- ```json
240
- // Root package.json
241
- {
242
- "name": "my-monorepo",
243
- "version": "1.0.0",
244
- "author": "Company Team",
245
- "license": "MIT"
246
- }
247
-
248
- // packages/ui/package.json
249
- {
250
- "name": "@my-monorepo/ui",
251
- "description": "UI components library"
252
- }
253
- ```
254
-
255
- When building the UI package, the banner will include:
256
-
257
- ```javascript
258
- /*!
259
- * name: @my-monorepo/ui
260
- * version: 1.0.0
261
- * description: UI components library
262
- * author: Company Team
263
- * license: MIT
264
- */
265
- ```
266
-
267
- ### Programmatic Usage
268
-
269
- You can also use the utility functions directly:
270
-
271
- ```typescript
272
- import { generateBanner, readPackageMetadata } from 'screw-up/internal';
273
-
274
- // Read package metadata
275
- const metadata = await readPackageMetadata('./package.json');
276
-
277
- // Generate banner with custom keys
278
- const banner = generateBanner(metadata, ['name', 'version', 'license']);
57
+ ## Documentation
279
58
 
280
- console.log(banner);
281
- // /*!
282
- // * name: my-package
283
- // * version: 1.0.0
284
- // * license: MIT
285
- // */
286
- ```
287
-
288
- ## Supported Workspace Types
289
-
290
- The plugin automatically detects and supports:
291
-
292
- - npm/yarn workspaces: Detected via `workspaces` field in `package.json`
293
- - pnpm workspaces: Detected via `pnpm-workspace.yaml` file
294
- - Lerna: Detected via `lerna.json` file
295
-
296
- ----
59
+ [See the repository](https://github.com/kekyo/screw-up/)
297
60
 
298
61
  ## License
299
62
 
300
- Under MIT
63
+ Under MIT.
package/README_pack.md ADDED
@@ -0,0 +1,63 @@
1
+ # Screw-UP
2
+
3
+ Simply package metadata inserter for Vite plugins.
4
+
5
+ [![Project Status: WIP – Initial development is in progress, but there has not yet been a stable, usable release suitable for the public.](https://www.repostatus.org/badges/latest/wip.svg)](https://www.repostatus.org/#wip)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+
8
+ ----
9
+
10
+ ## What is this?
11
+
12
+ This is a Vite plugin that automatically inserts banner comments containing package metadata (name, version, description, author, license, etc.) into your bundled files.
13
+
14
+ This will automatically read metadata from your `package.json`:
15
+
16
+ ```json
17
+ {
18
+ "name": "my-awesome-library",
19
+ "version": "2.1.0",
20
+ "description": "An awesome TypeScript library",
21
+ "author": "Jane Developer <jane@example.com>",
22
+ "license": "Apache-2.0",
23
+ "repository": {
24
+ "url": "https://github.com/user/my-awesome-library"
25
+ }
26
+ }
27
+ ```
28
+
29
+ To insert banner header each bundled source files (`dist/index.js` and etc.):
30
+
31
+ ```javascript
32
+ /*!
33
+ * name: my-awesome-library
34
+ * version: 2.1.0
35
+ * description: An awesome TypeScript library
36
+ * author: Jane Developer <jane@example.com>
37
+ * license: Apache-2.0
38
+ * repository.url: https://github.com/user/my-awesome-library
39
+ * git.commit.hash: c94eaf71dcc6522aae593c7daf85bb745112caf0
40
+ */
41
+ // Your bundled code here...
42
+ ```
43
+
44
+ ## Key Features
45
+
46
+ * Automatic metadata extraction: Reads metadata from `package.json` automatically.
47
+ * Workspace support: Works with monorepos and automatically inherits metadata from parent packages.
48
+ * Flexible output: Specify exactly which keys to include and in what order.
49
+ * Nested object support: Handles nested objects like `author.name`, `repository.url`.
50
+ * Customizable: Choose which metadata fields to include in your banner.
51
+ * TypeScript metadata generation: Can automatically generates TypeScript files with metadata constants for use in your source code.
52
+ * Git metadata extraction: Automatically extracts Git commit hash, tags, branches, and version information from local Git repository.
53
+ * Supported pack/publish CLI interface: When publishing using this feature, the package is generated after applying the above processing to `package.json`.
54
+
55
+ ----
56
+
57
+ ## Documentation
58
+
59
+ [See the repository](https://github.com/kekyo/screw-up/)
60
+
61
+ ## License
62
+
63
+ Under MIT.
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Get default Git metadata from local repository.
3
+ * @param repositoryPath - Local Git repository directory
4
+ * @param checkWorkingDirectoryStatus - Check working directory status to increase version
5
+ * @returns The metadata object with git metadata
6
+ */
7
+ export declare const getGitMetadata: (repositoryPath: string, checkWorkingDirectoryStatus: boolean) => Promise<any>;
8
+ //# sourceMappingURL=analyzer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"analyzer.d.ts","sourceRoot":"","sources":["../src/analyzer.ts"],"names":[],"mappings":"AAkeA;;;;;GAKG;AACH,eAAO,MAAM,cAAc,GAAU,gBAAgB,MAAM,EAAE,6BAA6B,OAAO,iBAyDhG,CAAC"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Pack assets into a tar archive
3
+ * @param targetDir - Target directory to pack
4
+ * @param outputDir - Output directory to write the tarball
5
+ * @param checkWorkingDirectoryStatus - Check working directory status
6
+ * @param inheritableFields - Package metadata fields that should be inherited from parent
7
+ * @param readmeReplacementPath - Optional path to replacement README file
8
+ * @returns Package metadata (package.json) or undefined if failed
9
+ */
10
+ export declare const packAssets: (targetDir: string, outputDir: string, checkWorkingDirectoryStatus: boolean, inheritableFields: Set<string>, readmeReplacementPath: string | undefined) => Promise<any>;
11
+ /**
12
+ * Get computed package.json object
13
+ * @param targetDir - Target directory to resolve package metadata
14
+ * @param checkWorkingDirectoryStatus - Check working directory status
15
+ * @param inheritableFields - Package metadata fields that should be inherited from parent
16
+ * @returns Computed package.json object or undefined if failed
17
+ */
18
+ export declare const getComputedPackageJsonObject: (targetDir: string, checkWorkingDirectoryStatus: boolean, inheritableFields: Set<string>) => Promise<any>;
19
+ export interface ParsedArgs {
20
+ command?: string;
21
+ positional: string[];
22
+ options: Record<string, string | boolean>;
23
+ }
24
+ export declare const parseArgs: (argv: string[]) => ParsedArgs;
25
+ //# sourceMappingURL=cli-internal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli-internal.d.ts","sourceRoot":"","sources":["../src/cli-internal.ts"],"names":[],"mappings":"AAwEA;;;;;;;;GAQG;AACH,eAAO,MAAM,UAAU,GACrB,WAAW,MAAM,EACjB,WAAW,MAAM,EACjB,6BAA6B,OAAO,EACpC,mBAAmB,GAAG,CAAC,MAAM,CAAC,EAC9B,uBAAuB,MAAM,GAAG,SAAS,KAAI,OAAO,CAAC,GAAG,CA4DzD,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,4BAA4B,GACvC,WAAW,MAAM,EACjB,6BAA6B,OAAO,EACpC,mBAAmB,GAAG,CAAC,MAAM,CAAC,KAAI,OAAO,CAAC,GAAG,CAW9C,CAAC;AAIF,MAAM,WAAW,UAAU;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC;CAC3C;AAED,eAAO,MAAM,SAAS,GAAI,MAAM,MAAM,EAAE,KAAG,UAoE1C,CAAC"}