@papit/create 0.0.11 → 0.0.13

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
@@ -1,17 +1,9 @@
1
1
  # @papit/create
2
2
 
3
- Project and package scaffolding tool for @papit — opinionated, consistent, and designed to kickstart Papit-based projects with the correct structure from day one.
3
+ Scaffolds papit packages, components and monorepo projects from templates, interactively or through flags. Run it inside a papit workspace to add a package or component, or outside one to start a new project.
4
4
 
5
5
  ![Logo](https://raw.githubusercontent.com/onkelhoy/papit/refs/heads/main/asset/logo.svg)
6
6
 
7
- This package is intended to be used **from within a workspace or an empty directory**. Simply run:
8
-
9
- ```bash
10
- npm create @papit
11
- ```
12
-
13
- to generate a fully initialized Papit package, component, or project with zero or minimal configuration.
14
-
15
7
  ---
16
8
 
17
9
  ![Type](https://img.shields.io/badge/Type-cli-orange)
@@ -20,154 +12,216 @@ to generate a fully initialized Papit package, component, or project with zero o
20
12
 
21
13
  ---
22
14
 
23
- ## CLI Flags
15
+ # Installation
24
16
 
25
- | Flag | Description |
26
- | ------------- | ----------------------------------- |
27
- | `--package` | Create a package |
28
- | `--component` | Create a component |
29
- | `--project` | Create a project |
30
- | `--agree` | Skip confirmations |
31
- | `--install` | Install dependencies after creation |
32
- | `--commit` | Create an initial git commit |
33
- | `--verbose` | Show detailed output |
17
+ No install needed:
34
18
 
35
- If no creation flag is provided, an interactive selector is shown.
19
+ ```bash
20
+ npm create @papit
21
+ ```
36
22
 
37
- ---
23
+ It also installs as a dev dependency with the `papit-create` bin:
38
24
 
39
- ## How it works
25
+ ```bash
26
+ npm install -D @papit/create
27
+ ```
40
28
 
41
- `@papit/create` presents a set of creation options. Some of these can be invoked directly via flags, but the tool is primarily interactive and focused on generating boilerplate code based on predefined templates.
29
+ # Usage
42
30
 
43
- There are currently three built-in runners:
31
+ Pick a runner from a menu:
44
32
 
45
- 1. `package`
46
- 2. `component`
47
- 3. `project`
33
+ ```bash
34
+ npm create @papit
35
+ ```
48
36
 
49
- **Note:** You can provide your own custom runners by placing them in the `bin` folder. Each runner must have a `runner.js` file with a default export, for example:
37
+ Go straight to a runner (npm needs the `--` to pass the flags on):
50
38
 
51
- ```
52
- <workspace-root>/bin/runners/<custom>/runner.js
39
+ ```bash
40
+ npm create @papit -- --package
41
+ npm create @papit -- --component
42
+ npm create @papit -- --project
53
43
  ```
54
44
 
55
- A runner is a function that receives two arguments:
45
+ The papit repo root wires it up as `npm run create`:
56
46
 
57
- ```ts
58
- info: {
59
- root: string; // Location of the workspace root
60
- local: string; // Location of the current package (if any)
61
- script: string | null; // Location of the @papit/create script
47
+ ```json
48
+ {
49
+ "scripts": {
50
+ "create": "npm create @papit -- --package --html-prefix=pap"
51
+ }
62
52
  }
63
53
  ```
64
54
 
65
- ```ts
66
- args: {
67
- flags: Record<string, string | string[] | true | undefined>,
68
- values: string[]
69
- }
55
+ Fully non-interactive, from inside a workspace:
56
+
57
+ ```bash
58
+ npm create @papit -- --package=node --name=my-tool --description="Does a thing." --agree
70
59
  ```
71
60
 
72
- For more details on the structure and behavior of these arguments, see the
61
+ The folder under `packages/` is still picked from a menu.
73
62
 
74
- - `@papit/arguments`
75
- - `@papit/information`
76
- package.
63
+ Outside a papit workspace, it always runs the project runner.
77
64
 
78
- ---
65
+ # CLI flags
79
66
 
80
- ## Package
67
+ | Flag | Runner | Description |
68
+ | --- | --- | --- |
69
+ | `--package[=<template>]` | all | Run the package runner. With a value, it's the template too (`browser`, `game`, `node`, `theme`, `web-component` or a custom one). |
70
+ | `--component` | all | Run the component runner. |
71
+ | `--project` | all | Run the project runner. |
72
+ | `--showcase` | all | Run the showcase runner (experimental, see below). |
73
+ | `--<custom>` | all | Run a custom runner from `bin/runners/<custom>/`. |
74
+ | `--type=<template>` | package, component | Template to use, when `--package` has no value. |
75
+ | `--name=<name>` | package, component, project | Name. Spaces and `-` separate words: `my button` becomes `my-button` / `MyButton`. |
76
+ | `--description=<text>` | package, project | Description for `package.json` and the README. |
77
+ | `--html-prefix=<prefix>` | package, component, showcase | Tag prefix for web components (`pap` gives `pap-<name>`). Falls back to the package's then the root's `papit.htmlprefix`, otherwise prompts. |
78
+ | `--agree` | package, component | Yes to everything: folder creation, git commit and `npm install`. |
79
+ | `--commit` | package, component | Commit the result without asking. |
80
+ | `--install` | package | Run `npm install` without asking. |
81
+ | `--yes` / `--no` | package | Answer the commit and install questions. |
82
+ | `--location=<path>` | project | Where to create the project. Default: prompted, then `<path>/<name>`. |
83
+ | `--license=<id>` | project | License for the generated `package.json`s. Default `MIT`. |
84
+ | `--skip-git` | project | Don't `git init` and commit. |
85
+ | `--verbose`, `--debug` | all | Log levels, see [@papit/arguments](https://github.com/onkelhoy/papit/tree/main/packages/runtime/cli/arguments). |
81
86
 
82
- The **package runner** creates a new package at a selected location (sometimes referred to as layers or folders).
87
+ # Runners
83
88
 
84
- A template is selected — either one of the built-in templates or a custom template located at:
89
+ ## package
85
90
 
86
- ```
87
- <workspace-root>/bin/runners/package/*
88
- ```
91
+ 1. Pick or create a folder under `packages/` (`--agree` skips the creation confirm).
92
+ 2. Pick a template, unless `--package=<template>` or `--type` names one.
93
+ 3. For a web component, settle the html prefix. When the root has none, it offers to save yours as the root's `papit.htmlprefix`.
94
+ 4. Ask for name and description. The name must not already exist in the workspace (`<scope>/<name>`).
95
+ 5. Copy the template into `<folder>/<name>` and replace the [template variables](#template-variables). `.gitkeep` files are dropped.
96
+ 6. Run the component runner for a first component with the package's own name, using the component template of the same type.
97
+ 7. Install and commit (`add: <scope>/<name> package`), when agreed.
89
98
 
90
- The selected template folder is copied, and all files are processed to replace supported variables.
99
+ ## component
91
100
 
92
- The generated license file automatically references the same license as the workspace root.
101
+ Adds a component to the package you're in. The template is the package's `papit.type`, then `--package` / `--type`, otherwise prompted. It registers the component under `papit.components` in the package's `package.json`, then copies each top-level template folder:
93
102
 
94
- ### Available variables
103
+ | Template folder | Goes to |
104
+ | --- | --- |
105
+ | `src` | `src/` when it's empty, otherwise `src/components/<name>/` |
106
+ | `tests`, `views`, others | `<folder>/<name>/` |
95
107
 
96
- - `VARIABLE_NAME`
97
- - `VARIABLE_FULL_NAME`
98
- - `VARIABLE_DESCRIPTION`
99
- - `VARIABLE_LAYER_FOLDER`
100
- - `VARIABLE_PROJECTLICENSE`
101
- - `VARIABLE_GITHUB_REPO`
102
- - `VARIABLE_LOCAL_DESTINATION`
103
- - `VARIABLE_CLASS_NAME`
104
- - `VARIABLE_HTML_PREFIX`
105
- - `VARIABLE_USER`
108
+ The first component of a new package lands directly in `src/` and in `views/experiment/`. Commits as `add: <name> component` when agreed.
106
109
 
107
- ---
110
+ ## project
108
111
 
109
- ## Component
112
+ Creates a new papit monorepo from the [project template](#project-template): prompts for name, description and location, asks before replacing an existing folder, copies the template, then `git init`, commits (`init: <name> initialized`) and runs `npm install`. The root package is named `@<name>/root`.
110
113
 
111
- The **component runner** creates a new component and is intended for adding sub-components to an existing package.
114
+ ## showcase
112
115
 
113
- Like the package runner, it copies a selected template from either built-ins or:
116
+ Experimental. For every `web-component`, `game` and `theme` package in the workspace whose first view isn't `views/showcase`, it generates one from `asset/showcase-templates/individual`, with a tab per existing view (`--view-filter`, default `showcase`, `raw`, `experiment`).
114
117
 
115
- ```
116
- <workspace-root>/bin/runners/component/*
118
+ ## Custom runners
119
+
120
+ Any folder in `<workspace-root>/bin/runners/` with a `runner.js` becomes a runner, listed in the menu and selectable as `--<folder>`. The names `package`, `component`, `project` and `showcase` are taken.
121
+
122
+ ```js
123
+ // bin/runners/release-notes/runner.js
124
+ import { Arguments } from "@papit/arguments";
125
+ import { Information } from "@papit/information";
126
+
127
+ export default async function () {
128
+ console.log(Information.root.location, Arguments.string("since"));
129
+ }
117
130
  ```
118
131
 
119
- ### Folder handling
132
+ The default export is called with no arguments. Read flags and the workspace through [@papit/arguments](https://github.com/onkelhoy/papit/tree/main/packages/runtime/cli/arguments) and [@papit/information](https://github.com/onkelhoy/papit/tree/main/packages/runtime/cli/information).
120
133
 
121
- - **views**
122
- If a `views` folder exists in both the current package and the template, a new subfolder named after the component is created inside the package’s `views` directory and populated with the template content.
134
+ ## Custom templates
123
135
 
124
- - **src**
125
- If the current package already has a `src` folder with files, the template’s `src` content is typically placed under:
136
+ | Location | Requirement |
137
+ | --- | --- |
138
+ | `bin/runners/package/<template>/` | Must contain a `package.json`. |
139
+ | `bin/runners/component/<template>/` | Top-level folders are copied as in the [component runner](#component). |
126
140
 
127
- ```
128
- src/components/<component-name>
129
- ```
141
+ They're listed next to the built-in ones and selected by name. The project runner has no custom templates.
130
142
 
131
- ### Available variables
143
+ # Package templates
132
144
 
133
- - `VARIABLE_NAME`
134
- - `VARIABLE_FULL_NAME`
135
- - `VARIABLE_HTML_NAME`
136
- - `VARIABLE_CLASS_NAME`
145
+ Every package template has `package.json`, `README.md`, `tsconfig.json`, `tsconfig.prod.json`, `.gitignore` and `asset/translations/en.json`. Scripts include `build` (`npx @papit/build`), `test`, `start` and `component`.
137
146
 
138
- ---
147
+ | Template | `papit.type` | Gets |
148
+ | --- | --- | --- |
149
+ | `browser` | `browser` | Playwright tests, `asset/icons`, `asset/images`. |
150
+ | `game` | `game` | Playwright tests, `views/`, `asset/models`, `asset/textures`. |
151
+ | `node` | `node` | `node:test` tests (`npm test`, `npm run test:only`), `npm start` builds and runs `lib/bundle.js`. |
152
+ | `theme` | `theme` | Ships `lib/theme.css` as the package export. Playwright tests. No build script. |
153
+ | `web-component` | `web-component` | Playwright tests, `views/`, `@papit/web-component` as a dependency, `papit.htmlprefix`. |
139
154
 
140
- ## Project
155
+ ## web-component
141
156
 
142
- > ⚠️ This runner is currently under development.
157
+ On top of the above, a web component package gets:
143
158
 
144
- The **project runner** creates a raw monorepo project at a selected destination.
159
+ - `"analyse": "npx @papit/analyse"`, which writes `analyse.json` (see [@papit/analyse](https://github.com/onkelhoy/papit/tree/main/packages/runtime/cli/analyse))
160
+ - `"generate:react": "npx @papit/react"`, which writes `src/react-wrapper.tsx` (see [@papit/react](https://github.com/onkelhoy/papit/tree/main/packages/runtime/cli/react))
161
+ - `react` `^19` as an optional peerDependency, tsconfig `"jsx": "react-jsx"` and `paths` mapping the package's own name to `./index`
145
162
 
146
- As with packages and components, custom templates can be provided at:
163
+ The `./react` export isn't in the template. Add it by hand once `src/react-wrapper.tsx` has been generated, so the import path is `@papit/<name>/react`:
147
164
 
148
- ```
149
- <workspace-root>/bin/runners/project/*
165
+ ```json
166
+ "./react": { "import": "./lib/react-wrapper.js", "types": "./lib/react-wrapper.d.ts" }
150
167
  ```
151
168
 
152
- You will be prompted to select a template during creation.
169
+ Without the file, `@papit/bundle-js` would build that entry from `src/index.ts` instead.
153
170
 
154
- Licensing is handled interactively. You may provide an existing license file or omit it, in which case a standard MIT license is used.
171
+ # Component templates
155
172
 
156
- ### Available variables
173
+ One per package type, each filled in with the component's name:
157
174
 
158
- - `VARIABLE_NAME`
159
- - `VARIABLE_DESCRIPTION`
160
- - `VARIABLE_PROJECTLICENSE`
161
- - `VARIABLE_USER`
175
+ | Template | `src` | `tests` | `views` |
176
+ | --- | --- | --- | --- |
177
+ | `browser` | `component.ts`, `index.ts`, `types.ts` | Playwright `unit.test.ts`, `snapshot.test.ts`, test page | demo page |
178
+ | `game` | `component.ts`, `index.ts`, `types.ts` | Playwright `unit.test.ts`, `snapshot.test.ts`, test page | demo page |
179
+ | `node` | `component.ts`, `index.ts`, `types.ts` | `unit.test.js` | none |
180
+ | `theme` | `theme.css` | Playwright `unit.test.ts`, `snapshot.test.ts`, test page | demo page |
181
+ | `web-component` | a `CustomElement` class, `style.css`, `types.ts`, `index.ts` that defines `<prefix>-<name>` | Playwright `unit.test.ts`, `snapshot.test.ts`, test page | demo page |
162
182
 
163
- ---
183
+ # Project template
164
184
 
165
- ## License
185
+ A root `package.json` with npm workspaces (`packages/**/*`, excluding `asset/` folders) and these scripts:
186
+
187
+ | Script | Runs |
188
+ | --- | --- |
189
+ | `analyse` | Every workspace's `analyse` script (`npm run analyse --workspaces --if-present`). |
190
+ | `build` | `npx @papit/build` |
191
+ | `test` | `node bin/test.mjs`, every package's `npm test`. |
192
+ | `start` | `npx @papit/server --serve --info` |
193
+ | `create` | `npm create @papit -- --package` |
194
+ | `clean` | `node bin/clean.mjs` |
195
+ | `version:reset`, `version:sync` | `npx @papit/version --reset` / `--sync` |
196
+
197
+ devDependencies: `@papit/build`, `@papit/bundle-js`, `@papit/bundle-ts`, `@papit/server`, `@papit/create`, `@papit/version`, `@papit/arguments`, `@papit/terminal`, `@papit/information`, `@papit/analyse`, `@papit/react`, `esbuild` and `typescript`. A project that uses `generate:react` adds `react` and `@types/react` as root devDependencies itself.
198
+
199
+ Also included: `.gitignore` (ignores `packages/**/lib/` and the generated `packages/**/analyse.json`), GitHub workflows for pull requests and publishing, `.vscode` settings, `.nvmrc`, `bin/` helpers and an example custom runner in `bin/runners/example-runner/`.
200
+
201
+ # Template variables
202
+
203
+ Replaced in every copied file.
204
+
205
+ | Variable | Package | Component | Project | Value |
206
+ | --- | :-: | :-: | :-: | --- |
207
+ | `VARIABLE_NAME` | ✓ | ✓ | ✓ | Kebab-case name. Project: `@<name>/root`. |
208
+ | `VARIABLE_FULL_NAME` | ✓ | ✓ | | `<scope>/<name>`. Component: the package's name. |
209
+ | `VARIABLE_CLASS_NAME` | ✓ | ✓ | | PascalCase name. |
210
+ | `VARIABLE_HTML_NAME` | ✓ | ✓ | | `<prefix>-<name>` |
211
+ | `VARIABLE_HTML_PREFIX` | ✓ | | | The html prefix, or empty. |
212
+ | `VARIABLE_DESCRIPTION` | ✓ | | ✓ | The description. |
213
+ | `VARIABLE_LAYER_FOLDER` | ✓ | | | Name of the folder the package goes in, e.g. `atoms`. |
214
+ | `VARIABLE_LOCAL_DESTINATION` | ✓ | | | Package path from the workspace root. |
215
+ | `VARIABLE_GITHUB_REPO` | ✓ | | | Root `repository.url` without `git+` and `.git`. |
216
+ | `VARIABLE_PROJECTLICENSE` | ✓ | | ✓ | Root `license` (default `MIT`). Project: `--license`. |
217
+ | `VARIABLE_USER` | ✓ | | ✓ | `$USER`, prompted when unset. |
218
+
219
+ # License
166
220
 
167
221
  Licensed under the **@Papit License 1.0**
168
222
  Copyright (c) 2024 Henry Pap (@onkelhoy)
169
223
 
170
- **Key points:**
224
+ **Key points**
171
225
 
172
226
  - ✅ Free to use in commercial projects
173
227
  - ✅ Free to modify and distribute
@@ -175,3 +229,18 @@ Copyright (c) 2024 Henry Pap (@onkelhoy)
175
229
  - ❌ Cannot resell the component itself as a standalone product
176
230
 
177
231
  See the [LICENSE](https://github.com/onkelhoy/papit/blob/main/LICENSE) file for full details.
232
+
233
+ ---
234
+
235
+ # Related
236
+
237
+ - [@papit/information](https://github.com/onkelhoy/papit/tree/main/packages/runtime/cli/information)
238
+ Finds the workspace root, its scope and existing packages.
239
+ - [@papit/arguments](https://github.com/onkelhoy/papit/tree/main/packages/runtime/cli/arguments)
240
+ Parses the flags.
241
+ - [@papit/build](https://github.com/onkelhoy/papit/tree/main/packages/runtime/cli/build)
242
+ Builds the packages it creates.
243
+ - [@papit/analyse](https://github.com/onkelhoy/papit/tree/main/packages/runtime/cli/analyse)
244
+ Behind the web component template's `analyse` script.
245
+ - [@papit/react](https://github.com/onkelhoy/papit/tree/main/packages/runtime/cli/react)
246
+ Behind the web component template's `generate:react` script.
@@ -54,8 +54,8 @@
54
54
  },
55
55
  "dependencies": {},
56
56
  "devDependencies": {
57
- "@playwright/test": "1.58.0",
58
- "playwright": "1.58.0",
57
+ "@playwright/test": "1.64.1",
58
+ "playwright": "1.64.1",
59
59
  "typescript": "5.9.3",
60
60
  "@papit/theme": "*",
61
61
  "@papit/translator": "*",
@@ -54,8 +54,8 @@
54
54
  },
55
55
  "dependencies": {},
56
56
  "devDependencies": {
57
- "@playwright/test": "1.58.0",
58
- "playwright": "1.58.0",
57
+ "@playwright/test": "1.64.1",
58
+ "playwright": "1.64.1",
59
59
  "typescript": "5.9.3",
60
60
  "@papit/theme": "*",
61
61
  "@papit/translator": "*",
@@ -49,8 +49,8 @@
49
49
  },
50
50
  "dependencies": {},
51
51
  "devDependencies": {
52
- "@playwright/test": "1.58.0",
53
- "playwright": "1.58.0",
52
+ "@playwright/test": "1.64.1",
53
+ "playwright": "1.64.1",
54
54
  "typescript": "5.9.3",
55
55
  "@papit/theme": "*",
56
56
  "@papit/translator": "*",
@@ -10,6 +10,8 @@
10
10
  "version": "0.0.1",
11
11
  "scripts": {
12
12
  "build": "npx @papit/build --error",
13
+ "analyse": "npx @papit/analyse",
14
+ "generate:react": "npx @papit/react",
13
15
  "watch": "tsc -w",
14
16
  "start": "npx @papit/server --info --live",
15
17
  "test": "npx playwright test -c tests/playwright.config.ts $@",
@@ -17,8 +19,7 @@
17
19
  "postversion": "papit-version",
18
20
  "component": "npm create @papit --component",
19
21
  "test:update-snapshots": "npx playwright test --update-snapshots -c tests/playwright.config.ts",
20
- "test:chrome": "npm test -- --project=chromium",
21
- "build:react": "bash ./bin/_utils/react.sh"
22
+ "test:chrome": "npm test -- --project=chromium"
22
23
  },
23
24
  "main": "./lib/bundle.js",
24
25
  "types": "./lib/bundle.d.ts",
@@ -56,9 +57,17 @@
56
57
  "dependencies": {
57
58
  "@papit/web-component": "*"
58
59
  },
60
+ "peerDependencies": {
61
+ "react": "^19"
62
+ },
63
+ "peerDependenciesMeta": {
64
+ "react": {
65
+ "optional": true
66
+ }
67
+ },
59
68
  "devDependencies": {
60
- "@playwright/test": "1.58.0",
61
- "playwright": "1.58.0",
69
+ "@playwright/test": "1.64.1",
70
+ "playwright": "1.64.1",
62
71
  "typescript": "5.9.3",
63
72
  "@papit/theme": "*",
64
73
  "@papit/translator": "*",
@@ -4,7 +4,7 @@
4
4
  "description": "VARIABLE_DESCRIPTION",
5
5
  "private": true,
6
6
  "scripts": {
7
- "analyse": "to come",
7
+ "analyse": "npm run analyse --workspaces --if-present",
8
8
  "publish": "to come",
9
9
  "clean": "node bin/clean.mjs",
10
10
  "build": "npx @papit/build",
@@ -39,7 +39,9 @@
39
39
  "@papit/build": "*",
40
40
  "@papit/server": "*",
41
41
  "@papit/create": "*",
42
- "@papit/version": "*"
42
+ "@papit/version": "*",
43
+ "@papit/analyse": "*",
44
+ "@papit/react": "*"
43
45
  },
44
46
  "papit": {}
45
47
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@papit/create",
3
- "description": "",
4
- "version": "0.0.11",
3
+ "description": "Scaffolds papit packages, components and monorepo projects from templates, interactively or through flags. Run it inside a papit workspace to add a package or component, or outside one to start a new project.",
4
+ "version": "0.0.13",
5
5
  "scripts": {
6
6
  "build": "npx @papit/build -- --error --ancestors",
7
7
  "watch": "tsc -w",
@@ -49,8 +49,8 @@
49
49
  },
50
50
  "dependencies": {
51
51
  "@papit/arguments": "0.0.1",
52
- "@papit/information": "0.0.8",
53
- "@papit/server": "1.0.7",
52
+ "@papit/information": "0.0.9",
53
+ "@papit/server": "1.0.9",
54
54
  "@papit/terminal": "0.0.2"
55
55
  },
56
56
  "devDependencies": {
@@ -58,8 +58,15 @@
58
58
  "typescript": "5.9.3"
59
59
  },
60
60
  "keywords": [
61
+ "papit",
62
+ "cli",
61
63
  "node",
62
- "typescript"
64
+ "typescript",
65
+ "create",
66
+ "scaffolding",
67
+ "templates",
68
+ "monorepo",
69
+ "web-component"
63
70
  ],
64
71
  "papit": {
65
72
  "publish": true,
@@ -70,5 +77,5 @@
70
77
  },
71
78
  "components": {}
72
79
  },
73
- "remoteVersion": "0.0.10"
80
+ "remoteVersion": "0.0.12"
74
81
  }