create-znode-plugin 0.1.4 → 0.2.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 +74 -48
- package/index.mjs +103 -14
- package/package.json +6 -1
- package/template/theme/README.md +10 -7
- package/template/theme/gitignore +4 -2
- package/template/theme/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,26 +3,36 @@
|
|
|
3
3
|
Creates a Znode runtime theme project, the way `create-next-app` creates a Next.js app. The project builds on its own
|
|
4
4
|
and runs inside your Znode store: no fork of the store, no webstore rebuild.
|
|
5
5
|
|
|
6
|
-
**In short:** you write a theme in its own folder (its own git repo); `npm run dev` builds it
|
|
7
|
-
plugin folder
|
|
8
|
-
slots, widgets, settings, pages),
|
|
6
|
+
**In short:** you write a theme in its own folder (its own git repo); `npm run dev` builds it **straight into the
|
|
7
|
+
runtime-plugin-store**, the folder the webstore loads themes from (no `dist/` or zip in your theme); the running webstore
|
|
8
|
+
loads it, and you see it with a preview link in your browser only. Examples (colors, slots, widgets, settings, pages),
|
|
9
|
+
versions and every command: [`znode-plugin`](https://www.npmjs.com/package/znode-plugin).
|
|
9
10
|
|
|
10
11
|
```bash
|
|
11
|
-
npm init znode-plugin@latest my-theme # 1. create (answer the store question)
|
|
12
|
+
npm init znode-plugin@latest my-theme # 1. create (answer the store question; Enter makes the runtime-plugin-store)
|
|
12
13
|
cd my-theme
|
|
13
|
-
npm run dev # 2. build
|
|
14
|
+
npm run dev # 2. build into the runtime-plugin-store, again on every save
|
|
14
15
|
# 3. open http://localhost:3000/api/extensions/preview?theme=my-theme (webstore running: npx nx dev webstore)
|
|
15
16
|
```
|
|
16
17
|
|
|
18
|
+
**One runtime-plugin-store per webstore, shared by all its themes.** A customer with five themes keeps them side by side,
|
|
19
|
+
with their runtime-plugin-store next to them; the first theme creates it, the others find it:
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
D:\customers\acme\
|
|
23
|
+
runtime-plugin-store\ plugins.json + every theme's built files (the webstore's RUNTIME_PLUGINS_DIR; not for git)
|
|
24
|
+
acme-b2b\ acme-b2c\ acme-outlet\ acme-dealer\ acme-base\ (sources only)
|
|
25
|
+
```
|
|
26
|
+
|
|
17
27
|
## Before you start
|
|
18
28
|
|
|
19
29
|
| You need | Where to find it |
|
|
20
30
|
| --- | --- |
|
|
21
31
|
| Node.js 20 or newer | `node -v` |
|
|
22
32
|
| **The store repo**, checked out on this machine | The folder that has `tsconfig.base.json` at its root (the webstore and page builder repo), e.g. `D:\znode\my-store` |
|
|
23
|
-
| **The store
|
|
33
|
+
| **The runtime-plugin-store** (optional) | The folder the webstore loads runtime packages from (`RUNTIME_PLUGINS_DIR` in the store's `apps/webstore/.env.local` or `.env`). None yet? It is created for you next to the theme. |
|
|
24
34
|
|
|
25
|
-
You will be asked for the store repo. The plugin
|
|
35
|
+
You will be asked for the store repo. The runtime-plugin-store is found or created for you (step 3 below).
|
|
26
36
|
|
|
27
37
|
## 1. Run one of these
|
|
28
38
|
|
|
@@ -51,25 +61,29 @@ and you are asked for it.
|
|
|
51
61
|
```
|
|
52
62
|
> npm create znode-plugin@latest my-theme
|
|
53
63
|
|
|
54
|
-
|
|
64
|
+
Connect your Znode webstore (recommended: npm run dev needs it)
|
|
65
|
+
Webstore folder, the repo root that has tsconfig.base.json (e.g. D:\znode\webstore): D:\znode\my-store
|
|
66
|
+
Do you already have a runtime-plugin-store (the folder the webstore loads themes from, with plugins.json)?
|
|
67
|
+
Enter its path, or press Enter to create one next to this theme [D:\customers\acme\runtime-plugin-store]:
|
|
55
68
|
Store: D:\znode\my-store
|
|
56
|
-
|
|
57
|
-
|
|
69
|
+
runtime-plugin-store: D:\customers\acme\runtime-plugin-store (created)
|
|
70
|
+
the webstore does not load it yet: add RUNTIME_PLUGINS_DIR=D:\customers\acme\runtime-plugin-store to D:\znode\my-store\apps\webstore\.env.local and restart it
|
|
71
|
+
Created My Theme in D:\customers\acme\my-theme
|
|
58
72
|
Installing dependencies…
|
|
59
73
|
added 32 packages in 30s
|
|
60
|
-
linked D:\
|
|
74
|
+
linked D:\customers\acme\my-theme\tsconfig.store.json to D:\znode\my-store\tsconfig.base.json (69 store aliases)
|
|
61
75
|
|
|
62
76
|
Next:
|
|
63
77
|
cd my-theme
|
|
64
|
-
npm run dev (
|
|
65
|
-
Then enable the theme for your stores in
|
|
78
|
+
npm run dev (builds straight into the runtime-plugin-store, and again on every save)
|
|
79
|
+
Then enable the theme for your stores in D:\customers\acme\runtime-plugin-store\plugins.json, and open /my-theme-welcome.
|
|
66
80
|
```
|
|
67
81
|
|
|
68
82
|
| Step | What you see | What you do |
|
|
69
83
|
| --- | --- | --- |
|
|
70
84
|
| 1. Name | `Project name …` (only when you did not type one) | Type a name such as `my-theme` |
|
|
71
|
-
| 2. **
|
|
72
|
-
| 3. **
|
|
85
|
+
| 2. **Webstore folder** | `Connect your Znode webstore (recommended …)` then `Webstore folder, the repo root that has tsconfig.base.json (e.g. …):` | Type or paste the **store repo folder** (the one with `tsconfig.base.json`), then Enter |
|
|
86
|
+
| 3. **runtime-plugin-store** | Nothing (the webstore sets one), `Found a runtime-plugin-store … Use it?`, or `Do you already have a runtime-plugin-store? …` | Enter (use the one found, or create one next to the theme), or type an existing one's path |
|
|
73
87
|
| 4. Files | `Created My Theme in …` | Nothing: the starter theme is copied and named |
|
|
74
88
|
| 5. Install | `Installing dependencies…` | Nothing: `npm install` runs (`znode-plugin`, React and Next.js types) |
|
|
75
89
|
| 6. Link | `linked … (69 store aliases)` | Nothing: the project now sees the store's real components and types |
|
|
@@ -78,26 +92,31 @@ Then enable the theme for your stores in the plugin folder's plugins.json, and o
|
|
|
78
92
|
### The store path question (step 2)
|
|
79
93
|
|
|
80
94
|
- **What to enter:** the root of the store repo, the folder with `tsconfig.base.json` in it. Not `apps/webstore`, not
|
|
81
|
-
the plugin
|
|
95
|
+
the runtime-plugin-store.
|
|
82
96
|
- **Why:** the project gets the store's real types, so imports such as `@znode/base-components/...` are checked against
|
|
83
97
|
the store's own code while you write your theme.
|
|
84
|
-
- **A wrong folder** is not accepted: you see `… has no tsconfig.base.json
|
|
98
|
+
- **A wrong folder** is not accepted: you see `… has no tsconfig.base.json. Enter the webstore repo's root folder (or leave empty to skip).` and the question again.
|
|
85
99
|
- **A default answer:** set `ZNODE_STORE_DIR` in your environment and it is shown in `[ ]`; press Enter to take it.
|
|
86
|
-
- **Answer it (recommended).**
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
100
|
+
- **Answer it (recommended).** An empty answer skips it: the project is still created (with its runtime-plugin-store),
|
|
101
|
+
but store imports are not type-checked until you connect it (`npm run link-store -- <store repo>`).
|
|
102
|
+
|
|
103
|
+
### The runtime-plugin-store (step 3)
|
|
104
|
+
|
|
105
|
+
The folder the webstore loads themes from (its `RUNTIME_PLUGINS_DIR`, with `plugins.json`). `npm run dev` and
|
|
106
|
+
`npm run deploy` build your theme straight into it. It is chosen in this order:
|
|
107
|
+
|
|
108
|
+
1. **The webstore sets `RUNTIME_PLUGINS_DIR`** (`apps/webstore/.env.local` or `.env`; only that line is read): that
|
|
109
|
+
folder, no question. Created there if it does not exist yet.
|
|
110
|
+
2. **One already exists** next to the theme or in a parent folder (your other themes made it): `Found a
|
|
111
|
+
runtime-plugin-store … Use it?` Enter uses it.
|
|
112
|
+
3. **Otherwise:** `Do you already have a runtime-plugin-store?` Type an existing one's path (a folder without
|
|
113
|
+
`plugins.json` becomes one after you confirm), or press **Enter to create one next to the theme**.
|
|
114
|
+
|
|
115
|
+
- A new runtime-plugin-store gets `plugins.json` and its own `.gitignore`: it is build output, never committed.
|
|
116
|
+
- It is saved in the theme's `znode.local.json` (`{ "pluginsDir": "…" }`, git-ignored: each developer keeps their own).
|
|
117
|
+
- The webstore's `.env.local` is never edited: when the webstore does not load that folder yet, the line to add is
|
|
118
|
+
printed; when it loads a different one, you get a warning.
|
|
119
|
+
- Later, for an existing theme: `npx znode create-store` (next to the theme) or `npx znode create-store <dir>`.
|
|
101
120
|
|
|
102
121
|
## 3. After it is created
|
|
103
122
|
|
|
@@ -121,21 +140,21 @@ Then enable the theme for your stores in the plugin folder's plugins.json, and o
|
|
|
121
140
|
4. Change a file under `src/`, save, wait for `installed theme my-theme@…` in the `npm run dev` window, and **reload the
|
|
122
141
|
page** (the store does not refresh an open page itself).
|
|
123
142
|
|
|
124
|
-
5. To make it live for a store: in the plugin
|
|
125
|
-
store codes to `"stores"`.
|
|
143
|
+
5. To make it live for a store: in the runtime-plugin-store's `plugins.json`, set your theme's `"enabled": true` and add
|
|
144
|
+
the store codes to `"stores"`.
|
|
126
145
|
|
|
127
|
-
**`npm run dev` or `npm run deploy`?** Both build
|
|
128
|
-
it while you work); `deploy` installs once and exits (a fresh machine, after
|
|
129
|
-
both. To release a new version, change `"version"` in `znode-package.json`
|
|
130
|
-
[Versions](https://www.npmjs.com/package/znode-plugin#versions)).
|
|
146
|
+
**`npm run dev` or `npm run deploy`?** Both build straight into the runtime-plugin-store. `dev` keeps watching and
|
|
147
|
+
installs again on every save (use it while you work); `deploy` installs once and exits (a fresh machine, after
|
|
148
|
+
`git pull`, scripts and CI). You do not run both. To release a new version, change `"version"` in `znode-package.json`
|
|
149
|
+
first (see [Versions](https://www.npmjs.com/package/znode-plugin#versions)); the old version's files leave the store.
|
|
131
150
|
|
|
132
151
|
| Command | What it does |
|
|
133
152
|
| --- | --- |
|
|
134
|
-
| `npm run dev` | Build
|
|
135
|
-
| `npm run
|
|
153
|
+
| `npm run dev` | Build into the runtime-plugin-store, and again on every save |
|
|
154
|
+
| `npm run deploy` | Build and install into the runtime-plugin-store once |
|
|
155
|
+
| `npm run build` | Type-check and compile, to see that it builds (nothing kept) |
|
|
136
156
|
| `npm run check` | Marketplace checks (metadata, permissions, settings, sizes) |
|
|
137
|
-
| `npm run pack` |
|
|
138
|
-
| `npm run deploy` | Pack and install into the plugin folder once |
|
|
157
|
+
| `npm run pack` | Zip into `releases/`, for another environment (int, qa, production) |
|
|
139
158
|
| `npm run link-store -- <store repo>` | Connect (or reconnect) the store's types |
|
|
140
159
|
|
|
141
160
|
## What is in the project
|
|
@@ -151,9 +170,12 @@ my-theme/
|
|
|
151
170
|
src/styles/theme.css the theme's styles
|
|
152
171
|
src/i18n/labels.json the theme's labels
|
|
153
172
|
tsconfig.store.json this machine's link to the store's types (git-ignored)
|
|
154
|
-
znode.local.json this machine's plugin
|
|
173
|
+
znode.local.json this machine's runtime-plugin-store (git-ignored)
|
|
155
174
|
```
|
|
156
175
|
|
|
176
|
+
No `dist/` or `.build/`: builds go straight into the runtime-plugin-store (the work folder is
|
|
177
|
+
`node_modules/.cache/znode-plugin`, removed after each build). Only `npm run pack` leaves a file, in `releases/`.
|
|
178
|
+
|
|
157
179
|
Where each kind of customization goes (styles, layouts, slots, widgets, pages, routes, settings, labels): see
|
|
158
180
|
[`znode-plugin`](https://www.npmjs.com/package/znode-plugin).
|
|
159
181
|
|
|
@@ -164,13 +186,16 @@ the options go after `--`; with `npx` they follow the name directly.
|
|
|
164
186
|
|
|
165
187
|
```bash
|
|
166
188
|
npm create znode-plugin@latest my-theme -- --store D:\znode\my-store
|
|
167
|
-
npx create-znode-plugin@latest my-theme --store D:\znode\my-store --plugins-dir D:\
|
|
189
|
+
npx create-znode-plugin@latest my-theme --store D:\znode\my-store --plugins-dir D:\customers\acme\runtime-plugin-store
|
|
168
190
|
```
|
|
169
191
|
|
|
192
|
+
Without `--plugins-dir` and without a terminal, it takes the webstore's `RUNTIME_PLUGINS_DIR`, else a
|
|
193
|
+
runtime-plugin-store next to the theme or in a parent folder, else creates one next to the theme.
|
|
194
|
+
|
|
170
195
|
| Option | Meaning |
|
|
171
196
|
| --- | --- |
|
|
172
197
|
| `--store <dir>` | The store repo (with `tsconfig.base.json`); skips the store question |
|
|
173
|
-
| `--plugins-dir <dir>` | The store
|
|
198
|
+
| `--plugins-dir <dir>` | The runtime-plugin-store to use (made one if it has no `plugins.json`); `--plugins-dir new` creates one next to the theme |
|
|
174
199
|
| `--publisher <name>` | Publisher shown in the marketplace |
|
|
175
200
|
| `--registry <url>` | npm registry for the project's dependencies (written to its `.npmrc`) |
|
|
176
201
|
| `--no-install` | Skip `npm install` (and the store link, which needs it) |
|
|
@@ -181,9 +206,10 @@ npx create-znode-plugin@latest my-theme --store D:\znode\my-store --plugins-dir
|
|
|
181
206
|
| --- | --- |
|
|
182
207
|
| `npm error 404 … create` | You typed `npx create znode-plugin`: use `npx create-znode-plugin@latest` or `npm create znode-plugin@latest` |
|
|
183
208
|
| No store question | Not a terminal (scripts, CI, some IDE consoles): pass `--store`. Or an old cached version: keep `@latest` |
|
|
184
|
-
| `… has no tsconfig.base.json` | You gave a subfolder (`apps/webstore`) or the plugin
|
|
209
|
+
| `… has no tsconfig.base.json` | You gave a subfolder (`apps/webstore`) or the runtime-plugin-store: give the store repo's root |
|
|
185
210
|
| `… exists and is not empty` | Choose another name, or empty that folder |
|
|
186
|
-
| `
|
|
211
|
+
| `no plugin store found` | `npx znode create-store` in the theme (one next to it), or point `znode.local.json` at the existing one |
|
|
212
|
+
| `warning: the webstore loads … not this folder` | The webstore reads another folder: set its `RUNTIME_PLUGINS_DIR` to the runtime-plugin-store (and restart it), or the theme's `znode.local.json` to the webstore's folder |
|
|
187
213
|
| Preview link returns 404 | The webstore is not in development mode, or the theme is not deployed yet (`npm run dev`) |
|
|
188
|
-
| `installed …` but no change in the store | The theme went to another plugin
|
|
214
|
+
| `installed …` but no change in the store | The theme went to another runtime-plugin-store than the running webstore reads: compare `znode.local.json` with the webstore's `RUNTIME_PLUGINS_DIR` (`apps/webstore/.env.local` or `.env`), then reload |
|
|
189
215
|
| `@znode/...` imports are red in the editor | Run `npm run link-store -- <store repo>` |
|
package/index.mjs
CHANGED
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
// create-znode-plugin: a new Znode runtime theme project, the way create-next-app makes a Next.js app.
|
|
3
3
|
//
|
|
4
4
|
// npm create znode-plugin@latest <name> (asks for the store to connect)
|
|
5
|
-
// npm create znode-plugin@latest <name> -- [--store <store repo>] [--plugins-dir <store
|
|
5
|
+
// npm create znode-plugin@latest <name> -- [--store <store repo>] [--plugins-dir <runtime-plugin-store> | new]
|
|
6
6
|
// [--publisher <name>] [--registry <url>] [--no-install]
|
|
7
7
|
//
|
|
8
8
|
// It copies the template (template/theme), fills in the names, installs the dependencies (znode-plugin, react, next
|
|
9
|
-
// for their types),
|
|
9
|
+
// for their types), links the store's types (--store), and connects the runtime-plugin-store: the folder the webstore
|
|
10
|
+
// loads (RUNTIME_PLUGINS_DIR), one per webstore and shared by its themes, found or created next to the theme.
|
|
10
11
|
|
|
11
12
|
import fs from "node:fs";
|
|
12
13
|
import path from "node:path";
|
|
@@ -82,15 +83,45 @@ function storePluginsDir(storeRepo) {
|
|
|
82
83
|
return null;
|
|
83
84
|
}
|
|
84
85
|
|
|
86
|
+
// The runtime-plugin-store: the folder the webstore loads themes from (its RUNTIME_PLUGINS_DIR, with plugins.json),
|
|
87
|
+
// one per webstore and shared by all its themes. npm run dev / deploy build straight into it (no dist in the theme).
|
|
88
|
+
const PLUGIN_STORE = "runtime-plugin-store";
|
|
89
|
+
const isPluginStore = (dir) => fs.existsSync(path.join(path.resolve(dir), "plugins.json"));
|
|
90
|
+
|
|
91
|
+
// an existing runtime-plugin-store in this folder or a parent folder (the customer's other themes made one)
|
|
92
|
+
function findPluginStore(from) {
|
|
93
|
+
for (let dir = path.resolve(from); ; dir = path.dirname(dir)) {
|
|
94
|
+
if (isPluginStore(path.join(dir, PLUGIN_STORE))) return path.join(dir, PLUGIN_STORE);
|
|
95
|
+
if (path.dirname(dir) === dir) return null;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// an empty runtime-plugin-store; its own .gitignore keeps it out of git (it is build output, like .next)
|
|
100
|
+
function createPluginStore(dir) {
|
|
101
|
+
const folder = path.resolve(dir);
|
|
102
|
+
fs.mkdirSync(folder, { recursive: true });
|
|
103
|
+
if (!isPluginStore(folder)) fs.writeFileSync(path.join(folder, "plugins.json"), JSON.stringify({ plugins: [] }, null, 2) + "\n");
|
|
104
|
+
if (!fs.existsSync(path.join(folder, ".gitignore"))) fs.writeFileSync(path.join(folder, ".gitignore"), "# build output the webstore loads (RUNTIME_PLUGINS_DIR): not for git\n*\n");
|
|
105
|
+
return folder;
|
|
106
|
+
}
|
|
107
|
+
|
|
85
108
|
async function main() {
|
|
86
109
|
const options = parseArgs(process.argv.slice(2));
|
|
87
110
|
if (options.kind && options.kind !== "theme") fail(`--kind ${options.kind}: only "theme" projects for now`);
|
|
88
111
|
// questions only when someone can answer them (a terminal); in scripts and CI the flags decide
|
|
89
112
|
const interactive = Boolean(process.stdin.isTTY && process.stdout.isTTY);
|
|
113
|
+
// one line reader for the whole run, so answers typed (or piped) ahead are kept for the next question
|
|
90
114
|
let prompt = null;
|
|
115
|
+
let lines = null;
|
|
91
116
|
const ask = async (question) => {
|
|
92
|
-
prompt
|
|
93
|
-
|
|
117
|
+
if (!prompt) {
|
|
118
|
+
prompt = readline.createInterface({ input: process.stdin });
|
|
119
|
+
lines = prompt[Symbol.asyncIterator]();
|
|
120
|
+
}
|
|
121
|
+
process.stdout.write(question);
|
|
122
|
+
const { value, done } = await lines.next();
|
|
123
|
+
if (done) fail("no answer (input closed)");
|
|
124
|
+
return value.trim();
|
|
94
125
|
};
|
|
95
126
|
|
|
96
127
|
if (!options.name && interactive) options.name = await ask("Project name (lowercase letters, digits, dashes): ");
|
|
@@ -102,29 +133,87 @@ async function main() {
|
|
|
102
133
|
if (options.store && !isStoreRepo(options.store)) fail(`--store ${options.store}: no tsconfig.base.json there (pass the store repo's folder)`);
|
|
103
134
|
if (!options.store && interactive) {
|
|
104
135
|
const suggested = process.env.ZNODE_STORE_DIR || "";
|
|
136
|
+
console.log("Connect your Znode webstore (recommended: npm run dev needs it)");
|
|
105
137
|
for (;;) {
|
|
106
|
-
const answer = (await ask(`
|
|
138
|
+
const answer = (await ask(`Webstore folder, the repo root that has tsconfig.base.json${suggested ? ` [${suggested}]` : " (e.g. D:\\znode\\webstore)"}: `)) || suggested;
|
|
107
139
|
if (!answer) break;
|
|
108
140
|
if (isStoreRepo(answer)) {
|
|
109
141
|
options.store = answer;
|
|
110
142
|
break;
|
|
111
143
|
}
|
|
112
|
-
console.log(` ${path.resolve(answer)} has no tsconfig.base.json
|
|
144
|
+
console.log(` ${path.resolve(answer)} has no tsconfig.base.json. Enter the webstore repo's root folder (or leave empty to skip).`);
|
|
113
145
|
}
|
|
146
|
+
if (!options.store) console.log(" Skipped: npm run dev cannot deploy until you connect it (npm run link-store -- <webstore repo>).");
|
|
114
147
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
148
|
+
// the runtime-plugin-store, in this order: --plugins-dir (a path, or "new" for one next to the theme); the webstore's
|
|
149
|
+
// own RUNTIME_PLUGINS_DIR (the folder it really loads); one the customer's other themes made (this folder or a parent);
|
|
150
|
+
// else asked: an existing one's path, or Enter to create one next to the theme
|
|
151
|
+
const besideTheme = path.join(path.dirname(target), PLUGIN_STORE);
|
|
152
|
+
const webstoreDir = options.store ? storePluginsDir(options.store) : null;
|
|
153
|
+
let createStore = false;
|
|
154
|
+
if (options.pluginsDir === "new") {
|
|
155
|
+
options.pluginsDir = besideTheme;
|
|
156
|
+
createStore = true;
|
|
157
|
+
} else if (options.pluginsDir) {
|
|
158
|
+
createStore = !isPluginStore(options.pluginsDir);
|
|
159
|
+
} else if (webstoreDir) {
|
|
160
|
+
options.pluginsDir = webstoreDir;
|
|
161
|
+
createStore = !isPluginStore(webstoreDir);
|
|
162
|
+
} else {
|
|
163
|
+
const found = findPluginStore(path.dirname(target));
|
|
164
|
+
if (found && !interactive) options.pluginsDir = found;
|
|
165
|
+
else if (interactive) {
|
|
166
|
+
if (found) console.log(`Found a runtime-plugin-store (the folder the webstore loads themes from): ${found}`);
|
|
167
|
+
for (;;) {
|
|
168
|
+
const answer = await ask(
|
|
169
|
+
found
|
|
170
|
+
? `Use it? Enter to use it, or type another runtime-plugin-store's path: `
|
|
171
|
+
: `Do you already have a runtime-plugin-store (the folder the webstore loads themes from, with plugins.json)?\n Enter its path, or press Enter to create one next to this theme [${besideTheme}]: `
|
|
172
|
+
);
|
|
173
|
+
if (!answer) {
|
|
174
|
+
options.pluginsDir = found || besideTheme;
|
|
175
|
+
createStore = !found;
|
|
176
|
+
break;
|
|
177
|
+
}
|
|
178
|
+
if (isPluginStore(answer)) {
|
|
179
|
+
options.pluginsDir = answer;
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
182
|
+
if (fs.existsSync(answer) && fs.statSync(answer).isDirectory()) {
|
|
183
|
+
const yes = await ask(` ${path.resolve(answer)} has no plugins.json. Make it a runtime-plugin-store? [Y/n] `);
|
|
184
|
+
if (!/^n/i.test(yes)) {
|
|
185
|
+
options.pluginsDir = answer;
|
|
186
|
+
createStore = true;
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
} else console.log(` ${path.resolve(answer)} does not exist. Enter an existing folder, or leave empty to create one next to the theme.`);
|
|
190
|
+
}
|
|
191
|
+
} else {
|
|
192
|
+
// scripts and CI with nothing to go on: one next to the theme, as a first theme gets
|
|
193
|
+
options.pluginsDir = besideTheme;
|
|
194
|
+
createStore = true;
|
|
195
|
+
}
|
|
118
196
|
}
|
|
119
197
|
prompt?.close();
|
|
120
|
-
|
|
198
|
+
options.pluginsDir = path.resolve(options.pluginsDir);
|
|
199
|
+
if (createStore) createPluginStore(options.pluginsDir);
|
|
200
|
+
if (options.store) console.log(`Store: ${path.resolve(options.store)}`);
|
|
201
|
+
console.log(`runtime-plugin-store: ${options.pluginsDir}${createStore ? " (created)" : ""}`);
|
|
202
|
+
// the webstore loads one folder: say so when it is not (yet) this one
|
|
203
|
+
if (options.store && webstoreDir !== options.pluginsDir) {
|
|
204
|
+
console.log(
|
|
205
|
+
webstoreDir
|
|
206
|
+
? ` warning: the webstore loads ${webstoreDir} (RUNTIME_PLUGINS_DIR), not this folder: change one of them, or the theme will not show`
|
|
207
|
+
: ` the webstore does not load it yet: add RUNTIME_PLUGINS_DIR=${options.pluginsDir} to ${path.join(path.resolve(options.store), "apps", "webstore", ".env.local")} and restart it`
|
|
208
|
+
);
|
|
209
|
+
} else if (!options.store) console.log(` the webstore loads it with RUNTIME_PLUGINS_DIR=${options.pluginsDir} (in apps/webstore/.env.local)`);
|
|
121
210
|
|
|
122
211
|
const values = { NAME: options.name, PASCAL: pascal(options.name), LABEL: label(options.name), PUBLISHER: options.publisher || `${label(options.name)} team` };
|
|
123
212
|
fs.mkdirSync(target, { recursive: true });
|
|
124
213
|
copyTemplate(path.join(HERE, "template", "theme"), target, values);
|
|
125
214
|
// this machine's links, both git-ignored: no store types yet (npm run link-store), and the store's plugin folder
|
|
126
215
|
fs.writeFileSync(path.join(target, "tsconfig.store.json"), JSON.stringify({ extends: "znode-plugin/tsconfig.json" }, null, 2) + "\n");
|
|
127
|
-
|
|
216
|
+
fs.writeFileSync(path.join(target, "znode.local.json"), JSON.stringify({ pluginsDir: options.pluginsDir }, null, 2) + "\n");
|
|
128
217
|
if (options.registry) fs.writeFileSync(path.join(target, ".npmrc"), `registry=${options.registry}\n`);
|
|
129
218
|
console.log(`Created ${values.LABEL} in ${target}`);
|
|
130
219
|
|
|
@@ -137,9 +226,9 @@ async function main() {
|
|
|
137
226
|
const cd = path.relative(process.cwd(), target) || ".";
|
|
138
227
|
console.log(`
|
|
139
228
|
Next:
|
|
140
|
-
cd ${cd}${options.install ? "" : "\n npm install"}${options.store ? "" : "\n npm run link-store -- <store repo> (the store's real types)"}
|
|
141
|
-
npm run dev (
|
|
142
|
-
Then enable the theme for your stores in
|
|
229
|
+
cd ${cd}${options.install ? "" : "\n npm install"}${options.store ? "" : "\n npm run link-store -- <store repo> (the store's real types)"}
|
|
230
|
+
npm run dev (builds straight into the runtime-plugin-store, and again on every save)
|
|
231
|
+
Then enable the theme for your stores in ${path.join(options.pluginsDir, "plugins.json")}, and open /${options.name}-welcome.`);
|
|
143
232
|
}
|
|
144
233
|
|
|
145
234
|
main();
|
package/package.json
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-znode-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Create a Znode runtime theme project: npm create znode-plugin@latest <name>.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"type": "module",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/azharuddin-mulla-amla/znode-plugin-npm-registry.git",
|
|
10
|
+
"directory": "packages/create-znode-plugin"
|
|
11
|
+
},
|
|
7
12
|
"bin": {
|
|
8
13
|
"create-znode-plugin": "index.mjs"
|
|
9
14
|
},
|
package/template/theme/README.md
CHANGED
|
@@ -7,16 +7,19 @@ for the stores it is enabled for: no fork of the store, no webstore rebuild.
|
|
|
7
7
|
|
|
8
8
|
| Command | What it does |
|
|
9
9
|
| --- | --- |
|
|
10
|
-
| `npm run dev` | Build
|
|
11
|
-
| `npm run
|
|
10
|
+
| `npm run dev` | Build straight into the runtime-plugin-store now, then again on every save; refresh the store page to see it |
|
|
11
|
+
| `npm run deploy` | Build and install into the runtime-plugin-store once |
|
|
12
|
+
| `npm run build` | Type-check against the store and compile, to see that it builds (nothing kept; `-- --out <dir>` keeps a copy) |
|
|
12
13
|
| `npm run check` | The marketplace review: metadata, permissions against the code, sizes |
|
|
13
|
-
| `npm run pack` |
|
|
14
|
-
| `npm run deploy` | Pack and install into the store's plugin folder |
|
|
14
|
+
| `npm run pack` | Zip it into `releases/__NAME__-<version>.zpkg.zip`, for another environment (int, qa, an admin upload) |
|
|
15
15
|
| `npm run link-store -- <store repo>` | Use the store's real types (writes `tsconfig.store.json`) |
|
|
16
16
|
|
|
17
|
-
The store
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
**The runtime-plugin-store** is the folder the webstore loads themes from (its `RUNTIME_PLUGINS_DIR`, with
|
|
18
|
+
`plugins.json`): one per webstore, shared by all its themes, usually next to them. This theme finds it through
|
|
19
|
+
`znode.local.json` (`{ "pluginsDir": "…" }`, git-ignored), else the `RUNTIME_PLUGINS_DIR` environment variable, else a
|
|
20
|
+
`runtime-plugin-store` folder next to the theme or in a parent folder (`npx znode create-store` makes one). Builds go
|
|
21
|
+
straight into it: the theme folder keeps no `dist/` or `.build/`. After the first deploy, enable the theme for your
|
|
22
|
+
stores in its `plugins.json` (`"enabled": true`, `"stores": ["<store code>"]`).
|
|
20
23
|
|
|
21
24
|
## Where each customization goes
|
|
22
25
|
|
package/template/theme/gitignore
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
node_modules/
|
|
2
|
-
|
|
2
|
+
# npm run pack's zips (for another environment); npm run dev / deploy build straight into the runtime-plugin-store
|
|
3
3
|
releases/
|
|
4
|
+
# folders older SDK versions built into: no longer made
|
|
5
|
+
dist/
|
|
4
6
|
.build/
|
|
5
|
-
# this machine's links: the store repo's types and the store
|
|
7
|
+
# this machine's links: the store repo's types and the runtime-plugin-store
|
|
6
8
|
tsconfig.store.json
|
|
7
9
|
znode.local.json
|