orionplace-nuxt 0.1.1 → 0.1.2
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 +12 -5
- package/bin/orionplace-nuxt.mjs +8 -4
- package/package.json +1 -1
- package/src/module.mjs +2 -0
- package/src/project-readme.mjs +14 -4
- package/src/setup.mjs +17 -5
package/README.md
CHANGED
|
@@ -66,8 +66,8 @@ npx orionplace-nuxt set backend your-project.orionplace.app
|
|
|
66
66
|
npx orionplace-nuxt add frontend shop.example.com
|
|
67
67
|
npx orionplace-nuxt add frontend www.shop.example.com
|
|
68
68
|
npx orionplace-nuxt remove frontend www.shop.example.com
|
|
69
|
-
npx orionplace-nuxt set
|
|
70
|
-
npx orionplace-nuxt
|
|
69
|
+
npx orionplace-nuxt set mimic shop.example.com
|
|
70
|
+
npx orionplace-nuxt help
|
|
71
71
|
```
|
|
72
72
|
|
|
73
73
|
Either domain command can run first. Both settings are needed for a usable mapping.
|
|
@@ -77,6 +77,8 @@ After setup, these npm script aliases are also available:
|
|
|
77
77
|
npm run orionplace:backend -- your-project.orionplace.app
|
|
78
78
|
npm run orionplace:add-frontend -- shop.example.com
|
|
79
79
|
npm run orionplace:remove-frontend -- www.shop.example.com
|
|
80
|
+
npm run orionplace:mimic -- shop.example.com
|
|
81
|
+
npm run orionplace:help
|
|
80
82
|
```
|
|
81
83
|
|
|
82
84
|
`npm set` belongs to npm's own configuration system; use the commands above.
|
|
@@ -109,9 +111,14 @@ Each frontend gets its own `sitemaps/<domain>.cfg`. `add frontend` preserves oth
|
|
|
109
111
|
domains and can be repeated safely. `set backend` updates every CLI-managed mapping
|
|
110
112
|
to the new personal API; it refuses to overwrite a manually edited mapping.
|
|
111
113
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
114
|
+
A new project starts with `MIMIC_FRONT_DOMAIN=""` in `.env`. Setting a backend
|
|
115
|
+
alone leaves it empty. The first added frontend becomes MIMIC; further additions
|
|
116
|
+
preserve that choice. `set mimic <domain>` selects an already-added frontend and
|
|
117
|
+
updates MIMIC without changing any domain mappings. Unknown domains are rejected;
|
|
118
|
+
add them with `add frontend` first.
|
|
119
|
+
|
|
120
|
+
`help`, `--help`, and `-h` display commands without writing files. The legacy
|
|
121
|
+
`set frontend <domain>` shortcut remains supported: it adds and selects a domain.
|
|
115
122
|
|
|
116
123
|
`remove frontend <domain>` removes that domain from the list and deletes only its
|
|
117
124
|
unchanged generated `.cfg`. Removing the MIMIC domain selects the first remaining
|
package/bin/orionplace-nuxt.mjs
CHANGED
|
@@ -6,22 +6,26 @@ import { createInterface } from 'node:readline/promises';
|
|
|
6
6
|
|
|
7
7
|
const help = `Orionplace Nuxt setup
|
|
8
8
|
|
|
9
|
+
npx orionplace-nuxt help
|
|
9
10
|
npx orionplace-nuxt init [directory]
|
|
10
11
|
npx orionplace-nuxt set backend <personal-backend.orionplace.app>
|
|
11
12
|
npx orionplace-nuxt add frontend <shop.example.com>
|
|
12
13
|
npx orionplace-nuxt remove frontend <shop.example.com>
|
|
14
|
+
npx orionplace-nuxt set mimic <existing-frontend.example.com>
|
|
13
15
|
npx orionplace-nuxt set frontend <shop.example.com>
|
|
14
16
|
|
|
15
17
|
Options: --cwd <directory> --dry-run --help --version
|
|
16
18
|
|
|
17
19
|
Set backend or add frontend also initializes the integration; either can come first.
|
|
18
|
-
|
|
20
|
+
MIMIC starts empty. The first added frontend sets it; later additions preserve it.
|
|
21
|
+
Set mimic selects an existing frontend without changing any domain mappings.
|
|
22
|
+
Set frontend is the legacy shortcut to add and select a frontend.
|
|
19
23
|
Set backend updates every managed frontend mapping. Remove frontend deletes only that mapping.
|
|
20
24
|
After creating a new project, run npm install and npm run dev in that directory.
|
|
21
25
|
Documentation and editable server source are generated in orionplace/.`;
|
|
22
26
|
try {
|
|
23
27
|
const argv = process.argv.slice(2);
|
|
24
|
-
if (!argv.length || argv.includes('--help') || argv.includes('-h')) {
|
|
28
|
+
if (!argv.length || argv[0] === 'help' || argv.includes('--help') || argv.includes('-h')) {
|
|
25
29
|
console.log(help);
|
|
26
30
|
} else if (argv.includes('--version')) {
|
|
27
31
|
console.log(JSON.parse(await readFile(new URL('../package.json', import.meta.url), 'utf8')).version);
|
|
@@ -41,12 +45,12 @@ try {
|
|
|
41
45
|
let result;
|
|
42
46
|
if (command === 'init' && positional.length <= 2) {
|
|
43
47
|
result = await setupProject({ cwd: target ? resolve(cwd, target) : cwd, dryRun });
|
|
44
|
-
} else if (((command === 'set' && ['backend', 'frontend'].includes(target)) ||
|
|
48
|
+
} else if (((command === 'set' && ['backend', 'frontend', 'mimic'].includes(target)) ||
|
|
45
49
|
(['add', 'remove'].includes(command) && target === 'frontend')) && positional.length <= 3) {
|
|
46
50
|
let value = positional[2];
|
|
47
51
|
if (!value && process.stdin.isTTY) {
|
|
48
52
|
const prompt = createInterface({ input: process.stdin, output: process.stdout });
|
|
49
|
-
try { value = await prompt.question(`${target === 'backend' ? 'Personal backend API' : 'Public frontend domain'}: `); }
|
|
53
|
+
try { value = await prompt.question(`${target === 'backend' ? 'Personal backend API' : target === 'mimic' ? 'Existing frontend to use for MIMIC' : 'Public frontend domain'}: `); }
|
|
50
54
|
finally { prompt.close(); }
|
|
51
55
|
}
|
|
52
56
|
if (!value) throw new Error(`Provide the ${target} domain. See --help.`);
|
package/package.json
CHANGED
package/src/module.mjs
CHANGED
|
@@ -29,6 +29,8 @@ export default defineNuxtModule({
|
|
|
29
29
|
// Do not inherit page caching for authenticated API requests.
|
|
30
30
|
routes['/api/**'] = { ...routes['/api/**'], cache: false, swr: false,
|
|
31
31
|
headers: { ...routes['/api/**']?.headers, 'cache-control': 'no-store' } };
|
|
32
|
+
// MIMIC defaults to empty. The CLI sets .env on the first "add frontend"
|
|
33
|
+
// or an explicit "set mimic"; never infer it from the domain-file directory.
|
|
32
34
|
// Values stay private to the server. MIMIC_FRONT_DOMAIN is also read at runtime.
|
|
33
35
|
nuxt.options.runtimeConfig.mimicFrontDomain ??= '';
|
|
34
36
|
nuxt.options.runtimeConfig.mimicFrontDomain = process.env.MIMIC_FRONT_DOMAIN
|
package/src/project-readme.mjs
CHANGED
|
@@ -10,7 +10,7 @@ You can change that backend domain in your account, then update this project.
|
|
|
10
10
|
## Current setup
|
|
11
11
|
|
|
12
12
|
- Frontend domains: ${settings.frontends?.length ? settings.frontends.map(domain => '\`' + domain + '\`').join(', ') : 'not configured yet'}
|
|
13
|
-
- Local MIMIC domain: \`${settings.frontend || '
|
|
13
|
+
- Local MIMIC domain: \`${settings.frontend || 'empty'}\`
|
|
14
14
|
- Personal API: \`${settings.backend || 'not configured yet'}\`
|
|
15
15
|
|
|
16
16
|
Set or change these values from the project root:
|
|
@@ -26,9 +26,19 @@ Set the backend or add a frontend first; either order works. Each frontend has i
|
|
|
26
26
|
own \`sitemaps/<domain>.cfg\` mapping to your personal API. Adding a domain again
|
|
27
27
|
is safe. Changing the backend updates every CLI-managed frontend mapping.
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
MIMIC is empty in a new project: \`MIMIC_FRONT_DOMAIN=""\`. Setting the backend
|
|
30
|
+
alone leaves it empty. The first added frontend sets MIMIC; adding more domains
|
|
31
|
+
preserves that choice.
|
|
32
|
+
|
|
33
|
+
Use \`npx orionplace-nuxt set mimic <domain>\` to select an already-added frontend
|
|
34
|
+
for localhost. It changes MIMIC without editing domain mappings. Add an unknown
|
|
35
|
+
domain with \`add frontend\` first. The legacy \`set frontend\` shortcut still
|
|
36
|
+
adds and selects a frontend.
|
|
37
|
+
|
|
38
|
+
\`\`\`bash
|
|
39
|
+
npx orionplace-nuxt help
|
|
40
|
+
npx orionplace-nuxt set mimic ${frontend}
|
|
41
|
+
\`\`\`
|
|
32
42
|
|
|
33
43
|
Removing a frontend deletes only its unchanged generated \`.cfg\` file. If it was
|
|
34
44
|
the selected MIMIC domain, the first remaining domain takes its place. Removing
|
package/src/setup.mjs
CHANGED
|
@@ -58,11 +58,11 @@ function updateEnvironment(source, domain) {
|
|
|
58
58
|
|
|
59
59
|
export async function setupProject({ cwd = process.cwd(), action = 'set', field, value, dryRun = false } = {}) {
|
|
60
60
|
if (!['set', 'add', 'remove'].includes(action) || (action !== 'set' && field !== 'frontend')) {
|
|
61
|
-
throw new Error('Use set backend, add frontend, remove frontend, or set frontend.');
|
|
61
|
+
throw new Error('Use set backend, add frontend, remove frontend, set mimic, or set frontend.');
|
|
62
62
|
}
|
|
63
63
|
const root = resolve(cwd);
|
|
64
|
-
const setting = field === 'backend' ? backendUrl(value) :
|
|
65
|
-
if (field && !setting) throw new Error('Choose backend or
|
|
64
|
+
const setting = field === 'backend' ? backendUrl(value) : ['frontend', 'mimic'].includes(field) ? frontendDomain(value) : null;
|
|
65
|
+
if (field && !setting) throw new Error('Choose backend, frontend, or mimic.');
|
|
66
66
|
const names = ['package.json', 'nuxt.config.ts', 'nuxt.config.js', 'nuxt.config.mjs', 'orionplace/settings.json', 'orionplace/.generated.json', '.env', '.gitignore'];
|
|
67
67
|
const current = {};
|
|
68
68
|
for (const name of names) current[name] = await read(await safePath(root, name));
|
|
@@ -98,6 +98,12 @@ export async function setupProject({ cwd = process.cwd(), action = 'set', field,
|
|
|
98
98
|
settings.frontends = [...new Set(frontends.map(frontendDomain))];
|
|
99
99
|
if (settings.frontend && !settings.frontends.includes(settings.frontend)) settings.frontends.unshift(settings.frontend);
|
|
100
100
|
if (field === 'backend') settings.backend = setting;
|
|
101
|
+
if (field === 'mimic') {
|
|
102
|
+
if (!settings.frontends.includes(setting)) {
|
|
103
|
+
throw new Error(`Add this frontend before selecting it for MIMIC: ${setting}`);
|
|
104
|
+
}
|
|
105
|
+
settings.frontend = setting;
|
|
106
|
+
}
|
|
101
107
|
if (field === 'frontend') {
|
|
102
108
|
if (action === 'remove') {
|
|
103
109
|
if (!settings.frontends.includes(setting)) throw new Error(`Frontend is not managed by this project: ${setting}`);
|
|
@@ -143,6 +149,8 @@ export async function setupProject({ cwd = process.cwd(), action = 'set', field,
|
|
|
143
149
|
pkg.scripts['orionplace:frontend'] ||= 'orionplace-nuxt set frontend';
|
|
144
150
|
pkg.scripts['orionplace:add-frontend'] ||= 'orionplace-nuxt add frontend';
|
|
145
151
|
pkg.scripts['orionplace:remove-frontend'] ||= 'orionplace-nuxt remove frontend';
|
|
152
|
+
pkg.scripts['orionplace:mimic'] ||= 'orionplace-nuxt set mimic';
|
|
153
|
+
pkg.scripts['orionplace:help'] ||= 'orionplace-nuxt help';
|
|
146
154
|
pkg.dependencies ||= {};
|
|
147
155
|
pkg.dependencies['orionplace-nuxt'] ||= dependencies['orionplace-nuxt'] || `^${metadata.version}`;
|
|
148
156
|
if (isNewNuxt) {
|
|
@@ -158,9 +166,13 @@ export async function setupProject({ cwd = process.cwd(), action = 'set', field,
|
|
|
158
166
|
if (isNewNuxt && !(await read(await safePath(root, 'app/app.vue')))) {
|
|
159
167
|
await plan('app/app.vue', '<template>\n <main>\n <h1>Your marketplace</h1>\n <p>Domain setup and API instructions are in orionplace/README.md.</p>\n </main>\n</template>\n', { managed: true });
|
|
160
168
|
}
|
|
161
|
-
|
|
169
|
+
// A new project starts explicitly empty; keep a pre-existing manual setting on init.
|
|
170
|
+
const hasMimicSetting = /^\s*(?:export\s+)?MIMIC_FRONT_DOMAIN\s*=/m.test(current['.env'] || '');
|
|
171
|
+
if (settings.frontend || oldFrontend || !hasMimicSetting) {
|
|
172
|
+
await plan('.env', updateEnvironment(current['.env'], settings.frontend || ''));
|
|
173
|
+
}
|
|
162
174
|
if (settings.backend) {
|
|
163
|
-
const mappings = action === 'remove' ? []
|
|
175
|
+
const mappings = action === 'remove' || field === 'mimic' ? []
|
|
164
176
|
: field === 'frontend' ? [setting] : settings.frontends;
|
|
165
177
|
for (const domain of mappings) {
|
|
166
178
|
await plan(`sitemaps/${domain}.cfg`, settings.backend + '\n', { managed: true });
|