screw-up 0.9.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,332 +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
- * Supported pack/publish CLI interface. When publishing using this feature, the package is generated after applying the above processing to `package.json`.
53
-
54
- ## Installation
55
-
56
- ```bash
57
- npm install --save-dev screw-up
58
- ```
59
-
60
- ----
61
-
62
- ## Usage
63
-
64
- ### Basic Usage
65
-
66
- Add the plugin to your `vite.config.ts`:
67
-
68
- ```typescript
69
- import { defineConfig } from 'vite';
70
- import screwUp from 'screw-up';
71
-
72
- export default defineConfig({
73
- plugins: [
74
- screwUp() // Uses default output keys
75
- ],
76
- build: {
77
- lib: {
78
- entry: 'src/index.ts',
79
- name: 'MyLibrary',
80
- fileName: 'index'
81
- }
82
- }
83
- });
84
- ```
85
-
86
- When no `outputKeys` are specified, the plugin uses these default keys with exact sequence:
87
- `name`, `version`, `description`, `author`, `license` and `repository.url`.
88
-
89
- ### Custom Output Keys
90
-
91
- You can specify which metadata fields to include and in what order:
92
-
93
- ```typescript
94
- import { defineConfig } from 'vite';
95
- import screwUp from 'screw-up';
96
-
97
- export default defineConfig({
98
- plugins: [
99
- screwUp({
100
- outputKeys: ['name', 'version', 'license'] // Only include these fields
101
- })
102
- ],
103
- build: {
104
- lib: {
105
- entry: 'src/index.ts',
106
- name: 'MyLibrary',
107
- fileName: 'index'
108
- }
109
- }
110
- });
111
- ```
112
-
113
- This will generate a banner with only the specified fields:
114
-
115
- ```javascript
116
- /*!
117
- * name: my-awesome-library
118
- * version: 2.1.0
119
- * license: Apache-2.0
120
- */
121
- ```
122
-
123
- ### Working with Nested Objects
124
-
125
- The plugin automatically flattens nested objects using dot notation:
126
-
127
- ```json
128
- {
129
- "name": "my-package",
130
- "author": {
131
- "name": "Jane Developer",
132
- "email": "jane@example.com"
133
- },
134
- "repository": {
135
- "type": "git",
136
- "url": "https://github.com/user/my-package"
137
- }
138
- }
139
- ```
140
-
141
- You can reference nested fields in your `outputKeys`:
142
-
143
- ```typescript
144
- screwUp({
145
- outputKeys: ['name', 'author.name', 'author.email', 'repository.url']
146
- })
147
- ```
148
-
149
- Results in:
150
-
151
- ```javascript
152
- /*!
153
- * name: my-package
154
- * author.name: Jane Developer
155
- * author.email: jane@example.com
156
- * repository.url: https://github.com/user/my-package
157
- */
158
- ```
159
-
160
- ### TypeScript Metadata Generation
161
-
162
- The plugin can generate TypeScript files containing metadata constants that you can import and use in your source code:
163
-
164
- ```typescript
165
- import { defineConfig } from 'vite';
166
- import screwUp from 'screw-up';
167
-
168
- export default defineConfig({
169
- plugins: [
170
- screwUp({
171
- outputMetadataFile: true, // Enable metadata file generation
172
- outputMetadataFilePath: 'src/generated/packageMetadata.ts', // Custom path (optional)
173
- outputMetadataKeys: ['name', 'version', 'description', 'author', 'license'] // Keys to include
174
- })
175
- ],
176
- build: {
177
- lib: {
178
- entry: 'src/index.ts',
179
- name: 'MyLibrary',
180
- fileName: 'index'
181
- }
182
- }
183
- });
184
- ```
185
-
186
- This generates `src/generated/packageMetadata.ts` with sanitized TypeScript constants:
187
-
188
- ```typescript
189
- // This file is auto-generated by screw-up plugin
190
- // Do not edit manually
191
-
192
- export const name = "my-awesome-library";
193
- export const version = "2.1.0";
194
- export const description = "An awesome TypeScript library";
195
- export const author = "Jane Developer <jane@example.com>";
196
- export const license = "Apache-2.0";
197
- ```
198
-
199
- You can then import and use these constants in your source code:
200
-
201
- ```typescript
202
- import { name, version } from './generated/packageMetadata.js';
203
-
204
- console.log(`${name} v${version}`);
205
- // Output: my-awesome-library v2.1.0
206
-
207
- export function getLibraryInfo() {
208
- return { name, version };
209
- }
210
- ```
211
-
212
- #### Key Sanitization
213
-
214
- Keys with special characters are automatically sanitized to valid TypeScript identifiers:
215
-
216
- - `repository.url` → `repository_url`
217
- - `custom-key` → `custom_key`
218
- - `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`.
219
54
 
220
55
  ----
221
56
 
222
- ## Advanced Usage
223
-
224
- ### Monorepo Support
225
-
226
- The plugin automatically detects workspace configurations and inherits metadata from parent packages:
227
-
228
- ```
229
- my-monorepo/
230
- ├── package.json # Root package with shared metadata
231
- ├── packages/
232
- │ ├── ui/
233
- │ │ └── package.json # Child package
234
- │ └── core/
235
- │ └── package.json # Child package
236
- ```
237
-
238
- Child packages automatically inherit metadata from the root package, with the ability to override specific fields:
239
-
240
- ```json
241
- // Root package.json
242
- {
243
- "name": "my-monorepo",
244
- "version": "1.0.0",
245
- "author": "Company Team",
246
- "license": "MIT"
247
- }
248
-
249
- // packages/ui/package.json
250
- {
251
- "name": "@my-monorepo/ui",
252
- "description": "UI components library"
253
- }
254
- ```
255
-
256
- When building the UI package, the banner will include:
257
-
258
- ```javascript
259
- /*!
260
- * name: @my-monorepo/ui
261
- * version: 1.0.0
262
- * description: UI components library
263
- * author: Company Team
264
- * license: MIT
265
- */
266
- ```
267
-
268
- ### Programmatic Usage
269
-
270
- You can also use the utility functions directly:
271
-
272
- ```typescript
273
- import { generateBanner, readPackageMetadata } from 'screw-up/internal';
274
-
275
- // Read package metadata
276
- const metadata = await readPackageMetadata('./package.json');
277
-
278
- // Generate banner with custom keys
279
- const banner = generateBanner(metadata, ['name', 'version', 'license']);
280
-
281
- console.log(banner);
282
- // /*!
283
- // * name: my-package
284
- // * version: 1.0.0
285
- // * license: MIT
286
- // */
287
- ```
288
-
289
- ## Supported Workspace Types
290
-
291
- The plugin automatically detects and supports:
292
-
293
- - npm/yarn workspaces: Detected via `workspaces` field in `package.json`
294
- - pnpm workspaces: Detected via `pnpm-workspace.yaml` file
295
- - Lerna: Detected via `lerna.json` file
57
+ ## Documentation
296
58
 
297
- ----
298
-
299
- ## CLI Usage
300
-
301
- The `screw-up` package includes a command-line interface for packaging and publishing your projects.
302
-
303
- ### Pack Command
304
-
305
- Create a tar archive of your project:
306
-
307
- ```bash
308
- # Pack current directory
309
- screw-up pack
310
-
311
- # Pack specific directory
312
- screw-up pack ./my-project
313
-
314
- # Pack to specific output directory
315
- screw-up pack --pack-destination ./dist
316
- ```
317
-
318
- The pack command:
319
-
320
- - Automatically reads `package.json` for metadata and file inclusion rules
321
- - Respects the `files` field in your `package.json`
322
- - Supports workspace inheritance (inherits metadata from parent packages)
323
- - Creates a compressed `.tgz` archive with format: `{name}-{version}.tgz`
324
-
325
- ### Publish Command
326
-
327
- Publish your project to registry server:
328
-
329
- ```bash
330
- # Publish current directory (creates archive and publishes)
331
- screw-up publish
332
-
333
- # Publish specific directory
334
- screw-up publish ./my-project
335
-
336
- # Publish existing tarball
337
- screw-up publish package.tgz
338
-
339
- # Publish with npm options (all npm publish options are supported)
340
- screw-up publish --dry-run --tag beta --access public
341
- ```
342
-
343
- The publish command:
344
-
345
- - Supports all `npm publish` options transparently
346
- - Can publish from directory (automatically creates archive) or existing tarball
347
- - Handles workspace packages with proper metadata inheritance
348
- - Uses the same packaging logic as the pack command
349
-
350
- ### Examples
351
-
352
- ```bash
353
- # Build and publish with dry run
354
- screw-up publish --dry-run
355
-
356
- # Publish to beta channel
357
- screw-up publish --tag beta
358
-
359
- # Publish scoped package as public
360
- screw-up publish --access public
361
-
362
- # Pack to custom directory then publish
363
- screw-up pack --pack-destination ./release
364
- screw-up publish ./release/my-package-1.0.0.tgz
365
- ```
366
-
367
- For help with any command:
368
-
369
- ```bash
370
- screw-up --help
371
- screw-up pack --help
372
- screw-up publish --help
373
- ```
374
-
375
- ----
59
+ [See the repository](https://github.com/kekyo/screw-up/)
376
60
 
377
61
  ## License
378
62
 
379
- 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"}
@@ -2,9 +2,20 @@
2
2
  * Pack assets into a tar archive
3
3
  * @param targetDir - Target directory to pack
4
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
5
8
  * @returns Package metadata (package.json) or undefined if failed
6
9
  */
7
- export declare const packAssets: (targetDir: string, outputDir: string) => Promise<any>;
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>;
8
19
  export interface ParsedArgs {
9
20
  command?: string;
10
21
  positional: string[];
@@ -1 +1 @@
1
- {"version":3,"file":"cli-internal.d.ts","sourceRoot":"","sources":["../src/cli-internal.ts"],"names":[],"mappings":"AAyCA;;;;;GAKG;AACH,eAAO,MAAM,UAAU,GAAU,WAAW,MAAM,EAAE,WAAW,MAAM,KAAI,OAAO,CAAC,GAAG,CA2EnF,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"}
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"}