@papit/create 0.0.10 → 0.0.12
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 +161 -113
- package/asset/component-templates/browser/views/style.css +1 -1
- package/asset/component-templates/game/views/main.js +11 -12
- package/asset/component-templates/web-component/src/component.ts +1 -1
- package/asset/component-templates/web-component/views/style.css +1 -1
- package/asset/package-templates/browser/README.md +1 -9
- package/asset/package-templates/game/README.md +0 -8
- package/asset/package-templates/game/package.json +1 -2
- package/asset/package-templates/node/README.md +0 -8
- package/asset/package-templates/theme/README.md +1 -9
- package/asset/package-templates/web-component/README.md +1 -10
- package/asset/package-templates/web-component/package.json +11 -2
- package/asset/project-template/.vscode/settings.json +6 -1
- package/asset/project-template/package.json +4 -2
- package/asset/showcase-templates/global/index.html +33 -0
- package/asset/showcase-templates/global/main.js +24 -0
- package/asset/showcase-templates/global/public/icons/.gitkeep +0 -0
- package/asset/showcase-templates/global/public/images/.gitkeep +0 -0
- package/asset/showcase-templates/global/public/translations/en.json +7 -0
- package/asset/showcase-templates/global/style.css +9 -0
- package/asset/showcase-templates/individual/index.html +35 -0
- package/asset/showcase-templates/individual/main.js +24 -0
- package/asset/showcase-templates/individual/public/icons/.gitkeep +0 -0
- package/asset/showcase-templates/individual/public/images/.gitkeep +0 -0
- package/asset/showcase-templates/individual/public/translations/en.json +7 -0
- package/asset/showcase-templates/individual/style.css +9 -0
- package/lib/bundle.js +3 -3
- package/package.json +13 -5
package/README.md
CHANGED
|
@@ -1,17 +1,9 @@
|
|
|
1
1
|
# @papit/create
|
|
2
2
|
|
|
3
|
-
|
|
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
|

|
|
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
|

|
|
@@ -20,168 +12,216 @@ to generate a fully initialized Papit package, component, or project with zero o
|
|
|
20
12
|
|
|
21
13
|
---
|
|
22
14
|
|
|
23
|
-
|
|
15
|
+
# Installation
|
|
24
16
|
|
|
25
|
-
|
|
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
|
-
|
|
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
|
-
|
|
25
|
+
```bash
|
|
26
|
+
npm install -D @papit/create
|
|
27
|
+
```
|
|
40
28
|
|
|
41
|
-
|
|
29
|
+
# Usage
|
|
42
30
|
|
|
43
|
-
|
|
31
|
+
Pick a runner from a menu:
|
|
44
32
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
33
|
+
```bash
|
|
34
|
+
npm create @papit
|
|
35
|
+
```
|
|
48
36
|
|
|
49
|
-
|
|
37
|
+
Go straight to a runner (npm needs the `--` to pass the flags on):
|
|
50
38
|
|
|
51
|
-
```
|
|
52
|
-
|
|
39
|
+
```bash
|
|
40
|
+
npm create @papit -- --package
|
|
41
|
+
npm create @papit -- --component
|
|
42
|
+
npm create @papit -- --project
|
|
53
43
|
```
|
|
54
44
|
|
|
55
|
-
|
|
45
|
+
The papit repo root wires it up as `npm run create`:
|
|
56
46
|
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
47
|
+
```json
|
|
48
|
+
{
|
|
49
|
+
"scripts": {
|
|
50
|
+
"create": "npm create @papit -- --package --html-prefix=pap"
|
|
51
|
+
}
|
|
62
52
|
}
|
|
63
53
|
```
|
|
64
54
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
-
|
|
61
|
+
The folder under `packages/` is still picked from a menu.
|
|
73
62
|
|
|
74
|
-
|
|
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
|
-
|
|
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
|
-
|
|
87
|
+
# Runners
|
|
83
88
|
|
|
84
|
-
|
|
89
|
+
## package
|
|
85
90
|
|
|
86
|
-
|
|
87
|
-
|
|
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
|
-
|
|
99
|
+
## component
|
|
91
100
|
|
|
92
|
-
The
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
114
|
+
## showcase
|
|
112
115
|
|
|
113
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
125
|
-
|
|
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
|
-
|
|
143
|
+
# Package templates
|
|
132
144
|
|
|
133
|
-
|
|
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
|
-
##
|
|
155
|
+
## web-component
|
|
141
156
|
|
|
142
|
-
|
|
157
|
+
On top of the above, a web component package gets:
|
|
143
158
|
|
|
144
|
-
|
|
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
|
-
|
|
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
|
-
|
|
165
|
+
```json
|
|
166
|
+
"./react": { "import": "./lib/react-wrapper.js", "types": "./lib/react-wrapper.d.ts" }
|
|
150
167
|
```
|
|
151
168
|
|
|
152
|
-
|
|
169
|
+
Without the file, `@papit/bundle-js` would build that entry from `src/index.ts` instead.
|
|
153
170
|
|
|
154
|
-
|
|
171
|
+
# Component templates
|
|
155
172
|
|
|
156
|
-
|
|
173
|
+
One per package type, each filled in with the component's name:
|
|
157
174
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
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
|
-
|
|
185
|
+
A root `package.json` with npm workspaces (`packages/**/*`, excluding `asset/` folders) and these scripts:
|
|
166
186
|
|
|
167
|
-
|
|
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` |
|
|
168
196
|
|
|
169
|
-
|
|
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.
|
|
170
198
|
|
|
171
|
-
|
|
172
|
-
- Runners remain deterministic
|
|
173
|
-
- Interactive prompts stay minimal
|
|
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/`.
|
|
174
200
|
|
|
175
|
-
|
|
201
|
+
# Template variables
|
|
176
202
|
|
|
177
|
-
|
|
203
|
+
Replaced in every copied file.
|
|
178
204
|
|
|
179
|
-
|
|
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
|
|
180
220
|
|
|
181
221
|
Licensed under the **@Papit License 1.0**
|
|
182
222
|
Copyright (c) 2024 Henry Pap (@onkelhoy)
|
|
183
223
|
|
|
184
|
-
**Key points
|
|
224
|
+
**Key points**
|
|
185
225
|
|
|
186
226
|
- ✅ Free to use in commercial projects
|
|
187
227
|
- ✅ Free to modify and distribute
|
|
@@ -192,7 +232,15 @@ See the [LICENSE](https://github.com/onkelhoy/papit/blob/main/LICENSE) file for
|
|
|
192
232
|
|
|
193
233
|
---
|
|
194
234
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
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.
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
body {
|
|
4
4
|
background-color: var(--background, light-dark(oklch(96% 0 0), oklch(17% 0 0)));
|
|
5
|
-
color: var(--
|
|
5
|
+
color: contrast-color(var(--background));
|
|
6
6
|
display: flex;
|
|
7
7
|
flex-direction: column;
|
|
8
8
|
gap: var(--space-4, 16px);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
// core
|
|
2
|
-
import { Engine } from '@papit/game-engine';
|
|
3
|
-
import { InputEvents } from "@papit/game-input-events";
|
|
2
|
+
import { Engine, InputEvents } from '@papit/game-engine';
|
|
4
3
|
|
|
5
4
|
// component
|
|
6
5
|
import 'VARIABLE_FULL_NAME';
|
|
@@ -8,27 +7,27 @@ import 'VARIABLE_FULL_NAME';
|
|
|
8
7
|
let engine, events;
|
|
9
8
|
|
|
10
9
|
window.onload = () => {
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
engine = new Engine("canvas");
|
|
11
|
+
events = new InputEvents(engine.canvas, { mouse: { pointerlock: false } });
|
|
13
12
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
events.on("mouse-up", handlemouseup);
|
|
14
|
+
events.on("mouse-down", handlemousedown);
|
|
15
|
+
events.on("mouse-move", handlemousemove);
|
|
17
16
|
|
|
18
|
-
|
|
17
|
+
engine.loop(draw); // cool function
|
|
19
18
|
}
|
|
20
19
|
|
|
21
20
|
function draw() {
|
|
22
|
-
|
|
21
|
+
engine.ctx.clearRect(0, 0, engine.width, engine.height);
|
|
23
22
|
}
|
|
24
23
|
|
|
25
24
|
// event handlers
|
|
26
25
|
function handlemousemove(e) {
|
|
27
|
-
|
|
26
|
+
// mouse move
|
|
28
27
|
}
|
|
29
28
|
function handlemousedown(e) {
|
|
30
|
-
|
|
29
|
+
// mouse down
|
|
31
30
|
}
|
|
32
31
|
function handlemouseup(e) {
|
|
33
|
-
|
|
32
|
+
// mouse up
|
|
34
33
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { CustomElement, html, property } from "@papit/web-component";
|
|
4
4
|
|
|
5
5
|
// local
|
|
6
|
-
import sheet from "./style.css"
|
|
6
|
+
import sheet from "./style.css" with { type: "css" };
|
|
7
7
|
import { ClickEvent } from "./types";
|
|
8
8
|
|
|
9
9
|
export class VARIABLE_CLASS_NAME extends CustomElement {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
body {
|
|
4
4
|
background-color: var(--background, light-dark(oklch(96% 0 0), oklch(17% 0 0)));
|
|
5
|
-
color: var(--
|
|
5
|
+
color: contrast-color(var(--background));
|
|
6
6
|
display: flex;
|
|
7
7
|
flex-direction: column;
|
|
8
8
|
gap: var(--space-4, 16px);
|
|
@@ -18,10 +18,6 @@ VARIABLE_DESCRIPTION
|
|
|
18
18
|
npm install VARIABLE_FULL_NAME
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
## Contributing
|
|
22
|
-
|
|
23
|
-
Contributions are welcome! Please follow the development guidelines above and ensure all tests pass before submitting a pull request.
|
|
24
|
-
|
|
25
21
|
## License
|
|
26
22
|
|
|
27
23
|
Licensed under the @Papit License 1.0 - Copyright (c) 2024 Henry Pap (@onkelhoy)
|
|
@@ -37,8 +33,4 @@ See the [LICENSE](https://github.com/onkelhoy/papit/blob/main/LICENSE) file for
|
|
|
37
33
|
|
|
38
34
|
## Related Components
|
|
39
35
|
|
|
40
|
-
- [@papit/web-component](https://github.com/onkelhoy/papit/tree/main/packages/
|
|
41
|
-
|
|
42
|
-
## Support
|
|
43
|
-
|
|
44
|
-
For issues, questions, or contributions, please visit the [GitHub repository](https://github.com/onkelhoy/papit).
|
|
36
|
+
- [@papit/web-component](https://github.com/onkelhoy/papit/tree/main/packages/web/engines/web-component): Core utilities, decorators, and base component class
|
|
@@ -18,10 +18,6 @@ VARIABLE_DESCRIPTION
|
|
|
18
18
|
npm install VARIABLE_FULL_NAME
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
## Contributing
|
|
22
|
-
|
|
23
|
-
Contributions are welcome! Please follow the development guidelines above and ensure all tests pass before submitting a pull request.
|
|
24
|
-
|
|
25
21
|
## License
|
|
26
22
|
|
|
27
23
|
Licensed under the @Papit License 1.0 - Copyright (c) 2024 Henry Pap (@onkelhoy)
|
|
@@ -34,7 +30,3 @@ Licensed under the @Papit License 1.0 - Copyright (c) 2024 Henry Pap (@onkelhoy)
|
|
|
34
30
|
- ❌ Cannot resell the component itself as a standalone product
|
|
35
31
|
|
|
36
32
|
See the [LICENSE](https://github.com/onkelhoy/papit/blob/main/LICENSE) file for full details.
|
|
37
|
-
|
|
38
|
-
## Support
|
|
39
|
-
|
|
40
|
-
For issues, questions, or contributions, please visit the [GitHub repository](https://github.com/onkelhoy/papit).
|
|
@@ -18,10 +18,6 @@ VARIABLE_DESCRIPTION
|
|
|
18
18
|
npm install VARIABLE_FULL_NAME
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
## Contributing
|
|
22
|
-
|
|
23
|
-
Contributions are welcome! Please follow the development guidelines above and ensure all tests pass before submitting a pull request.
|
|
24
|
-
|
|
25
21
|
## License
|
|
26
22
|
|
|
27
23
|
Licensed under the @Papit License 1.0 - Copyright (c) 2024 Henry Pap (@onkelhoy)
|
|
@@ -34,7 +30,3 @@ Licensed under the @Papit License 1.0 - Copyright (c) 2024 Henry Pap (@onkelhoy)
|
|
|
34
30
|
- ❌ Cannot resell the component itself as a standalone product
|
|
35
31
|
|
|
36
32
|
See the [LICENSE](https://github.com/onkelhoy/papit/blob/main/LICENSE) file for full details.
|
|
37
|
-
|
|
38
|
-
## Support
|
|
39
|
-
|
|
40
|
-
For issues, questions, or contributions, please visit the [GitHub repository](https://github.com/onkelhoy/papit).
|
|
@@ -18,10 +18,6 @@ VARIABLE_DESCRIPTION
|
|
|
18
18
|
npm install VARIABLE_FULL_NAME
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
## Contributing
|
|
22
|
-
|
|
23
|
-
Contributions are welcome! Please follow the development guidelines above and ensure all tests pass before submitting a pull request.
|
|
24
|
-
|
|
25
21
|
## License
|
|
26
22
|
|
|
27
23
|
Licensed under the @Papit License 1.0 - Copyright (c) 2024 Henry Pap (@onkelhoy)
|
|
@@ -37,8 +33,4 @@ See the [LICENSE](https://github.com/onkelhoy/papit/blob/main/LICENSE) file for
|
|
|
37
33
|
|
|
38
34
|
## Related Components
|
|
39
35
|
|
|
40
|
-
- [@papit/web-component](https://github.com/onkelhoy/papit/tree/main/packages/
|
|
41
|
-
|
|
42
|
-
## Support
|
|
43
|
-
|
|
44
|
-
For issues, questions, or contributions, please visit the [GitHub repository](https://github.com/onkelhoy/papit).
|
|
36
|
+
- [@papit/web-component](https://github.com/onkelhoy/papit/tree/main/packages/web/engines/web-component): Core utilities, decorators, and base component class
|
|
@@ -28,11 +28,6 @@ npm install VARIABLE_FULL_NAME
|
|
|
28
28
|
<VARIABLE_HTML_NAME></VARIABLE_HTML_NAME>
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
## Contributing
|
|
33
|
-
|
|
34
|
-
Contributions are welcome! Please follow the development guidelines above and ensure all tests pass before submitting a pull request.
|
|
35
|
-
|
|
36
31
|
## License
|
|
37
32
|
|
|
38
33
|
Licensed under the @Papit License 1.0 - Copyright (c) 2024 Henry Pap (@onkelhoy)
|
|
@@ -48,8 +43,4 @@ See the [LICENSE](https://github.com/onkelhoy/papit/blob/main/LICENSE) file for
|
|
|
48
43
|
|
|
49
44
|
## Related Components
|
|
50
45
|
|
|
51
|
-
- [@papit/web-component](https://github.com/onkelhoy/papit/tree/main/packages/
|
|
52
|
-
|
|
53
|
-
## Support
|
|
54
|
-
|
|
55
|
-
For issues, questions, or contributions, please visit the [GitHub repository](https://github.com/onkelhoy/papit).
|
|
46
|
+
- [@papit/web-component](https://github.com/onkelhoy/papit/tree/main/packages/web/engines/web-component): Core utilities, decorators, and base component class
|
|
@@ -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,6 +57,14 @@
|
|
|
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
69
|
"@playwright/test": "1.58.0",
|
|
61
70
|
"playwright": "1.58.0",
|
|
@@ -15,5 +15,10 @@
|
|
|
15
15
|
"typescript.format.placeOpenBraceOnNewLineForFunctions": false,
|
|
16
16
|
"typescript.format.placeOpenBraceOnNewLineForControlBlocks": true,
|
|
17
17
|
"javascript.format.placeOpenBraceOnNewLineForControlBlocks": true,
|
|
18
|
-
"files.associations": {
|
|
18
|
+
"files.associations": {
|
|
19
|
+
"*.json": "jsonc"
|
|
20
|
+
},
|
|
21
|
+
"lit-plugin.rules": {
|
|
22
|
+
"no-incompatible-type-binding": "off"
|
|
23
|
+
}
|
|
19
24
|
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"description": "VARIABLE_DESCRIPTION",
|
|
5
5
|
"private": true,
|
|
6
6
|
"scripts": {
|
|
7
|
-
"analyse": "
|
|
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
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="UTF-8">
|
|
6
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
7
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
8
|
+
<title>VARIABLE_TITLE</title>
|
|
9
|
+
|
|
10
|
+
<link rel="icon" type="image/x-icon" href="favicon.ico">
|
|
11
|
+
|
|
12
|
+
<!-- Styles -->
|
|
13
|
+
<link rel="stylesheet" href="style.css" />
|
|
14
|
+
|
|
15
|
+
<script defer type="module" src="main.js"></script>
|
|
16
|
+
</head>
|
|
17
|
+
|
|
18
|
+
<body>
|
|
19
|
+
<pap-sidebar>
|
|
20
|
+
<h2 slot="header">Showcase</h2>
|
|
21
|
+
VARIABLE_SIDEBAR_CONTENT
|
|
22
|
+
</pap-sidebar>
|
|
23
|
+
|
|
24
|
+
<pap-router>
|
|
25
|
+
VARIABLE_ROUTER_PATHS
|
|
26
|
+
</pap-router>
|
|
27
|
+
|
|
28
|
+
<footer>
|
|
29
|
+
Footer
|
|
30
|
+
</footer>
|
|
31
|
+
</body>
|
|
32
|
+
|
|
33
|
+
</html>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// core
|
|
2
|
+
import { translator } from '@papit/translator';
|
|
3
|
+
import "@papit/codeblock";
|
|
4
|
+
import "@papit/tabs";
|
|
5
|
+
import "@papit/router";
|
|
6
|
+
|
|
7
|
+
// component
|
|
8
|
+
import 'VARIABLE_NAME';
|
|
9
|
+
|
|
10
|
+
window.onload = () => {
|
|
11
|
+
console.log('[demo]: window loaded');
|
|
12
|
+
|
|
13
|
+
translator.add({ id: "en", url: "/en.json" });
|
|
14
|
+
translator.change("en");
|
|
15
|
+
|
|
16
|
+
const tabs = document.querySelector("pap-tabs.individual-showcase");
|
|
17
|
+
const router = document.querySelector("pap-router.individual-showcase");
|
|
18
|
+
|
|
19
|
+
tabs.addEventListener("change", e => {
|
|
20
|
+
console.log(tabs, e.target.value);
|
|
21
|
+
router.url = e.target.value;
|
|
22
|
+
})
|
|
23
|
+
}
|
|
24
|
+
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="UTF-8">
|
|
6
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
7
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
8
|
+
<title>VARIABLE_CLASS_NAME</title>
|
|
9
|
+
|
|
10
|
+
<link rel="icon" type="image/x-icon" href="favicon.ico">
|
|
11
|
+
|
|
12
|
+
<!-- Styles -->
|
|
13
|
+
<link rel="stylesheet" href="style.css" />
|
|
14
|
+
|
|
15
|
+
<script defer type="module" src="main.js"></script>
|
|
16
|
+
</head>
|
|
17
|
+
|
|
18
|
+
<body>
|
|
19
|
+
<article>
|
|
20
|
+
<pap-tabs class="individual-showcase" value="VARIABLE_SELECTED_TAB">
|
|
21
|
+
|
|
22
|
+
<header>
|
|
23
|
+
<h1>VARIABLE_CLASS_NAME</h1>
|
|
24
|
+
|
|
25
|
+
VARIABLE_TABS_TAB
|
|
26
|
+
</header>
|
|
27
|
+
|
|
28
|
+
<pap-router class="individual-showcase">
|
|
29
|
+
VARIABLE_TABS_CONTENT
|
|
30
|
+
</pap-router>
|
|
31
|
+
</pap-tabs>
|
|
32
|
+
</article>
|
|
33
|
+
</body>
|
|
34
|
+
|
|
35
|
+
</html>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// core
|
|
2
|
+
import { translator } from '@papit/translator';
|
|
3
|
+
import "@papit/codeblock";
|
|
4
|
+
import "@papit/tabs";
|
|
5
|
+
import "@papit/router";
|
|
6
|
+
|
|
7
|
+
// component
|
|
8
|
+
import 'VARIABLE_NAME';
|
|
9
|
+
|
|
10
|
+
window.onload = () => {
|
|
11
|
+
console.log('[demo]: window loaded');
|
|
12
|
+
|
|
13
|
+
translator.add({ id: "en", url: "/en.json" });
|
|
14
|
+
translator.change("en");
|
|
15
|
+
|
|
16
|
+
const tabs = document.querySelector("pap-tabs.individual-showcase");
|
|
17
|
+
const router = document.querySelector("pap-router.individual-showcase");
|
|
18
|
+
|
|
19
|
+
tabs.addEventListener("change", e => {
|
|
20
|
+
console.log(tabs, e.target.value);
|
|
21
|
+
router.url = e.target.value;
|
|
22
|
+
})
|
|
23
|
+
}
|
|
24
|
+
|
|
File without changes
|
|
File without changes
|
package/lib/bundle.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
3
|
-
`)}import
|
|
4
|
-
`),
|
|
2
|
+
import G from"node:path";import se from"node:fs";import{Arguments as K}from"@papit/arguments";import{Information as ye,PackageGraph as he}from"@papit/information";import{Terminal as E}from"@papit/terminal";import k from"node:path";import U from"node:fs";import{Terminal as i}from"@papit/terminal";import{Information as P,PackageGraph as ie}from"@papit/information";import{Arguments as x}from"@papit/arguments";import v from"node:path";import C from"node:fs";import{Information as b}from"@papit/information";import{Terminal as d}from"@papit/terminal";import{Arguments as T}from"@papit/arguments";import{Arguments as ce}from"@papit/arguments";import{Information as X,PackageGraph as pe}from"@papit/information";import{Terminal as N}from"@papit/terminal";import L from"node:fs";import I from"node:path";function _(e){return L.readdirSync(e).filter(n=>L.statSync(I.join(e,n)).isDirectory())}function le(e){return L.readdirSync(e).filter(n=>{let a=I.join(e,n);return!(!L.statSync(a).isDirectory()||pe.search(a))})}async function te(){return N.sessionBlock(async()=>{let e=I.join(X.root.location,"packages"),n=e;for(;e;){let a=N.createSession(),o=le(e);N.write("Current: ",e.replace(X.root.location,X.scope)),N.write();let p=await N.option([["Choose Folder","Create Folder"],e===n?o:["..",...o]]);if(p.index===0)break;if(p.index===1){let s=await N.prompt("folder name",!1,e),r=I.join(e,s.input);await me(r)&&(e=I.join(e,s.input))}else p.index===2&&e!==n?e=I.resolve(e,".."):e=I.join(e,o[p.index-(e===n?2:3)]);N.clearSession(a)}return e})}async function me(e){return N.createSession(),N.write(`[${e}]`),ce.has("agree")||await N.confirm("confirm folder creation",!0)?(L.mkdirSync(e,{recursive:!0}),N.clearSession(),!0):!1}async function F(e,n,a){L.mkdirSync(n,{recursive:!0});let o=L.readdirSync(e,{withFileTypes:!0});for(let p of o){let s=I.join(e,p.name),r=I.join(n,p.name);if(p.isDirectory()){await F(s,r,a);continue}if(typeof a!="function"){L.copyFileSync(s,r);continue}let f=L.readFileSync(s,"utf-8"),t=await a(f,s,r);t!==!1&&(L.copyFileSync(s,r),L.writeFileSync(r,t,"utf-8"))}}function $(e){if(!e)return;let n=e.split(/[ |-]/),a=n.join("-");return{className:ne(n.map(ne).join("")),name:a.toLowerCase()}}function ne(e){return e?e.charAt(0).toUpperCase()+e.slice(1):""}function fe(e){try{return C.readdirSync(e).length>0}catch{return!1}}function ue(e){C.existsSync(e)&&C.statSync(e).isDirectory()||C.mkdirSync(e)}async function W(e,n,a){let o=v.join(n?.destination??b.package.location,"package.json"),p=n?JSON.parse(C.readFileSync(o,{encoding:"utf-8"})):b.package.packageJSON;p==null&&(d.error("could not find package's package.json file"),process.exit(1)),p.name===b.root.name&&(d.error("cannot create a component to root"),process.exit(1));let s=p,r=_(v.join(e,"asset/component-templates")),f=new Set;try{_(v.join(b.root.location,"bin/runners/component")).forEach(m=>{r.push(m),f.add(m)})}catch{}let t={index:r.findIndex(m=>m===s.papit?.type),text:""};if(t.text=r[t.index],t.index<0){let m=T.string("package")??T.string("type");t.index=r.findIndex(u=>u===m),t.index<0&&(d.createSession(),d.write("type of component"),t=await d.option(r),d.clearSession())}let w=T.string("html-prefix")??n?.htmlprefix??b.package.packageJSON.papit.htmlprefix??b.root.packageJSON.papit.htmlprefix;if(w?.trim()===""&&(w=void 0),w===void 0&&/web-components?/i.test(t.text)){let m=d.createSession();for(;;){let u;if(w!==void 0?(u=(await d.prompt(`use default "${w}" or override?`)).input,u||(u=w)):u=(await d.prompt("html prefix",!0)).input,u){w=u;break}else d.clearSession(),d.write("you must use a html-prefix for web-components")}d.clearSession(m)}let y=n?.nameInfo;for(;!y;){d.clearSession();let m=T.string("name");if(m||(m=(await d.prompt("(component) name",!0)).input),y=$(m),!y){d.write("name missing, try again");continue}if(s.papit.components[y.name]){d.write("name already exist, try again");continue}break}d.createSession();let R=n?.shouldCommit??T.true("agree")??T.true("commit")??await d.confirm("git commit",!0);d.clearSession();let V=f.has(t.text)?v.join(b.root.location,"bin","runners","component",t.text):v.join(e,"asset","component-templates",t.text),h=_(V);s.papit.components[y.name]={className:y.className,htmlprefix:w},C.writeFileSync(o,JSON.stringify(s,null,2),{encoding:"utf-8"}),R&&await d.execute(`git add ${o}`,b.root.location);for(let m of h){let u=v.join(n?.destination??b.package.location,m),g=u,S=v.join(V,m);if(m==="src"?fe(u)&&(u=v.join(u,"components"),g=v.join(u,y.name)):g=v.join(u,y.name),ue(u),a&&(g=a(g,m)),await F(S,g,M=>M.replace(/VARIABLE_NAME/g,y.name).replace(/VARIABLE_FULL_NAME/g,s.name).replace(/VARIABLE_HTML_NAME/g,`${w}-${y.name}`).replace(/VARIABLE_CLASS_NAME/g,y.className)),R)try{await d.execute(`git add ${g}`,b.root.location)}catch{d.warn(`"git add ${g}" failed`)}}!n?.shouldCommit&&R&&await d.execute(`git commit -m "add: ${y.name} component"`,b.root.location)}async function oe(e){let n=i.createSession(),a=P.root.packageJSON;a===null&&(i.error("root package.json not found"),process.exit(1));let o=await te(),p=_(k.join(e,"asset","package-templates")),s=new Set;try{_(k.join(P.root.location,"bin","runners","package")).forEach(c=>{U.existsSync(k.join(P.root.location,"bin","runners","package",c,"package.json"))&&(p.push(c),s.add(c))})}catch{}let r=x.string("package")??x.string("type"),f={index:p.findIndex(c=>c===r),text:""};f.text=p[f.index],f.index<0&&(i.write("type of package"),f=await i.option(p)),i.clearSession();let t=x.string("html-prefix");if(t?.trim()===""&&(t=void 0),!t&&/web-components?/i.test(f.text)){for(t||(t=a.papit?.htmlprefix),x.info||i.createSession();;){let c;if(t?(c=(await i.prompt(`use default "${t}" or override?`)).input,c||(c=t)):(c=(await i.prompt("html prefix",!0)).input,a.papit?.htmlprefix||await i.confirm(`you wish to set "${c}" as the default html-prefix?`)&&(a.papit.htmlprefix=c,U.writeFileSync(k.join(P.root.location,"package.json"),JSON.stringify(a,null,2),{encoding:"utf-8"}))),c){t=c;break}else x.info||i.clearSession(),i.warn("you must use a html-prefix for web-components")}x.info||i.clearSession()}let w=k.relative(P.root.location,o),y=k.basename(o);a.repository?.url||i.warn("root package.json does not have 'repository.url'");let R=(a.repository?.url??"").replace(/\.git$/,"").replace(/^git\+/,""),V=k.join(P.root.location,"package-lock.json");i.clearSession(n);let h,m;for(;m===void 0||h===void 0;){i.clearSession();let c=x.string("name");if(c||(c=(await i.prompt("(package) name",!0)).input),h=$(c),!h){i.write("name missing, try again");continue}let j=`${P.scope}/${h.name}`;ie.get(j)?i.write("package already exists, try again"):m=j}let u=x.string("description");u||(u=(await i.prompt("description",!0)).input),i.write(),i.createSession();let g=k.join(o,h.name),S=c=>c.replace(/\\/g,"/"),M=s.has(f.text)?k.join(P.root.location,"bin","runners","package",f.text):k.join(e,"asset","package-templates",f.text);await F(M,g,async(c,j)=>j.endsWith(".gitkeep")?!1:c.replace(/VARIABLE_NAME/g,h.name).replace(/VARIABLE_FULL_NAME/g,m).replace(/VARIABLE_DESCRIPTION/g,u).replace(/VARIABLE_LAYER_FOLDER/g,y).replace(/VARIABLE_PROJECTLICENSE/g,a.license||"MIT").replace(/VARIABLE_GITHUB_REPO/g,R).replace(/VARIABLE_LOCAL_DESTINATION/g,S(k.join(w,h.name))).replace(/VARIABLE_CLASS_NAME/g,h.className).replace(/VARIABLE_HTML_PREFIX/g,t??"").replace(/VARIABLE_HTML_NAME/g,`${t}-${h.name}`).replace(/VARIABLE_USER/g,process.env.USER??"anonymous"));let B=JSON.parse(U.readFileSync(k.join(g,"package.json"),{encoding:"utf-8"}));B||(i.error(`package.json not found at "${g}"`),process.exit(1)),B.papit||(B.papit={main:h.name,components:{},publish:!0,type:f.text}),ie.add(g),i.createSession();let J=!1;x.has("no")?J=!1:x.has("yes")?J=!0:J=x.true("agree")||x.true("commit")||await i.confirm("git commit",!0),i.clearSession(),await W(e,{destination:g,nameInfo:h,htmlprefix:t,shouldCommit:J},(c,j)=>(j==="src"&&(c=c.replace(/[/\\]components[/\\].*/,"")),j==="lib"&&(c=c.replace(new RegExp(h.name+"$"),"")),j==="views"&&(c=c.replace(new RegExp(h.name+"$"),"experiment")),x.debug&&i.info(JSON.stringify({dest:c,folder:j})),c));let Z=k.join(g,"src","components");U.existsSync(Z)&&U.rmdirSync(Z),i.createSession();let z=!1;if(x.has("no")?z=!1:x.has("yes")?z=!0:z=x.true("agree")||x.true("install")||await i.confirm("install package",!0),z){let{close:c}=i.loading("installing");try{await i.execute("npm install",u)}catch(j){i.warn("error during install"),console.log(j),i.createSession()}finally{c(),i.clearSession()}}else i.clearSession();if(J)try{await i.execute(`git add ${V}`,g),await i.execute(`git add ${g}`,g),await i.execute(`git commit -m "add: ${m} package"`,g)}catch{i.warn("error during commit")}i.write(i.yellow(k.relative(P.root.location,g))),i.write(`${m} created
|
|
3
|
+
`)}import ae from"node:path";import Y from"node:fs";import{Arguments as D}from"@papit/arguments";import{Terminal as l}from"@papit/terminal";async function Q(e){l.write(`Project Creation
|
|
4
|
+
`),l.createSession();let n=D.string("name");n===void 0&&(n=(await l.prompt("name",!0)).input);let a=D.string("description");a===void 0&&(a=(await l.prompt("description",!0)).input);let o=D.string("location");if(o===void 0){let t=await l.prompt(process.cwd(),!0,process.cwd());o=ae.join(t.path,n)}l.write(),l.createSession(),await l.sessionBlock(async()=>{if(!Y.existsSync(o))return;await l.confirm(`confirm to remove it [${o}]`)?Y.rmSync(o,{recursive:!0,force:!0}):(l.error("must choose a empty location"),process.exit(1))}),await l.confirm(`confirm location [${l.yellow(o)}]`,!0)||(l.warn("abort"),process.exit(0)),Y.mkdirSync(o,{recursive:!0}),l.clearSession(),l.write();let s=D.string("license")??"MIT";s===void 0&&(s=(await l.prompt("license (default MIT)")).input),l.clearSession();let r=!D.has("skip-git");if(r){let{close:t,update:w}=l.loading("git init",3e3,y=>{y>400?w("runnign slow"):y>800?w("something seems wrong"):y>1500&&w("yeah somethign is very wrong")});await l.execute("git init",{cwd:o}),l.clearSession(),t()}await F(ae.join(e,"asset/project-template"),o,async(t,w)=>w.endsWith(".gitkeep")?!1:t.replace(/VARIABLE_NAME/g,`@${n}/root`).replace(/VARIABLE_DESCRIPTION/g,a).replace(/VARIABLE_PROJECTLICENSE/g,s||"MIT").replace(/VARIABLE_USER/g,process.env.USER??"anonymous")),r&&(await l.execute("git add .",{cwd:o}),await l.execute(`git commit -m "init: ${n} initialized"`,{cwd:o}));let{close:f}=l.loading("installing",2e4);await l.execute("npm install",{cwd:o}),f(),l.clearSession(),l.write(),l.write("project initialized"),l.write("try it:"),l.write(" (1)",l.yellow(`cd ${o}`)),l.write(" (2)",l.yellow("npm start")),process.exit(0)}import q from"node:fs";import A from"node:path";import{meta as ge}from"@papit/server";import{Arguments as O}from"@papit/arguments";import{Information as H}from"@papit/information";async function re(e){let{importmap:n}=await ge(),a=A.join(e,"asset","showcase-templates"),o=O.string("output");o&&q.existsSync(o)||O.debug&&console.log("no output argument provided");let p=we(["web-component","game","theme"]),s=new Map,r=[];for(let f of p)for(let t of f){let w=A.relative(A.join(H.root.location,"packages"),t.location),y=A.dirname(w);s.set(y,(s.get(y)??[]).concat([t]));let R=O.get("view-filter")??["showcase","raw","experiment"];try{let h=A.join(t.location,"views"),m=q.readdirSync(h).map(S=>A.join(h,S)).filter(S=>q.statSync(S).isDirectory()&&q.existsSync(A.join(S,"index.html"))&&R.includes(A.basename(S))).map(S=>A.basename(S)).sort((S,M)=>(R.findIndex(B=>B===S)??R.length)-(R.findIndex(B=>B===M)??R.length)),u=m.at(0);u!=="showcase"&&(O.debug&&console.log("no showcase view folder, showcase view generated"),await de(t,m,a));let g={realpath:A.join(w,"views/:view"),path:A.join(w,":view"),view:u?A.join(w,"views",u):""};for(let S=1;S<m.length;S++)g[`fallback-view${S!==1?S:""}`]=m[S];r.push()}catch{}let V=[]}}async function de(e,n,a){let o=$(e.name.replace(H.scope+"/",""))??{name:e.name,className:e.name},p=O.string("html-prefix")??e.packageJSON.papit.htmlprefix??H.root.packageJSON.papit.htmlprefix;await F(A.join(a,"individual"),A.join(e.location,"views/showcase"),s=>s.replace(/VARIABLE_NAME/g,e.name).replace(/VARIABLE_HTML_NAME/g,`${p}-${o.name}`).replace(/VARIABLE_CLASS_NAME/g,o.className).replace(/VARIABLE_TABS_TAB/g,'<pap-tab slot="tab" value="showcase">showcase</pap-tab>'+n.map(r=>`<pap-tab slot="tab" value="${r}">${r}</pap-tab>`).join(" ")).replace(/VARIABLE_TABS_CONTENT/g,['<pap-tabpanel value="showcase" path=":view" view="showcase" realpath="views/:view"></pap-tabpanel>',n.map(r=>`<pap-tabpanel value="${r}" path=":view" view="${r}" realpath="views/:view"></pap-tabpanel>`).join(" ")].join(" ")).replace(/VARIABLE_SELECTED_TAB/g,"showcase"))}function we(e){return H.getPriorityBatches(O.instance,n=>n.name.startsWith(H.scope)).map(n=>n.filter(a=>{if(a.packageJSON.papit.skip)return!1;if(typeof a.packageJSON.papit.type=="string"){if(!e.includes(a.packageJSON.papit.type))return!1}else{let o=a.packageJSON.papit.type,p=!1;for(let s in o)if(e.includes(o[s])){p=!0;break}if(!p)return!1}return!0}))}(async function(){K.init(process.argv,["install","commit","agree"]),K.verbose&&(process.env.verbose="true");let e=G.dirname(import.meta.dirname),n=JSON.parse(se.readFileSync(G.join(e,"package.json"),{encoding:"utf-8"}));if(n||(E.error("could not find @papit/create package.json"),process.exit(1)),!process.env.USER){E.createSession();let r=await E.prompt("your name",!0);process.env.USER=r.input,E.clearSession()}E.write(),E.write("@papit/create",E.yellow(n.version),"- running"),E.write();let a=new Set;if(he.ERROR){await Q(e);return}let o=G.join(ye.root.location,"bin/runners"),p=["package","component","project","showcase"];try{_(o).forEach(f=>{if(p.includes(f))return;let t=G.join(o,f,"runner.js");se.existsSync(t)&&(a.add(f),p.push(f))})}catch{}let s=null;for(let r=0;r<p.length;r++)if(K.has(p[r])){s={index:r,text:p[r]};break}switch(s===null&&(E.createSession(),s=await E.option(p),E.clearSession()),s.index){case 0:await oe(e);break;case 1:await W(e);break;case 2:await Q(e);break;case 3:await re(e);break;default:{a.has(s.text)||(E.error("requested a runner that doesnt exist"),process.exit(1));let r=G.join(o,s.text,"runner.js");K.verbose&&E.write(`running local runner "${s.text}"`);let{default:f}=await import(r);await f();break}}process.exit()})();
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@papit/create",
|
|
3
|
-
"description": "",
|
|
4
|
-
"version": "0.0.
|
|
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.12",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "npx @papit/build -- --error --ancestors",
|
|
7
7
|
"watch": "tsc -w",
|
|
@@ -49,7 +49,8 @@
|
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"@papit/arguments": "0.0.1",
|
|
52
|
-
"@papit/information": "0.0.
|
|
52
|
+
"@papit/information": "0.0.9",
|
|
53
|
+
"@papit/server": "1.0.8",
|
|
53
54
|
"@papit/terminal": "0.0.2"
|
|
54
55
|
},
|
|
55
56
|
"devDependencies": {
|
|
@@ -57,8 +58,15 @@
|
|
|
57
58
|
"typescript": "5.9.3"
|
|
58
59
|
},
|
|
59
60
|
"keywords": [
|
|
61
|
+
"papit",
|
|
62
|
+
"cli",
|
|
60
63
|
"node",
|
|
61
|
-
"typescript"
|
|
64
|
+
"typescript",
|
|
65
|
+
"create",
|
|
66
|
+
"scaffolding",
|
|
67
|
+
"templates",
|
|
68
|
+
"monorepo",
|
|
69
|
+
"web-component"
|
|
62
70
|
],
|
|
63
71
|
"papit": {
|
|
64
72
|
"publish": true,
|
|
@@ -69,5 +77,5 @@
|
|
|
69
77
|
},
|
|
70
78
|
"components": {}
|
|
71
79
|
},
|
|
72
|
-
"remoteVersion": "0.0.
|
|
80
|
+
"remoteVersion": "0.0.11"
|
|
73
81
|
}
|