@histoire/plugin-quasar 0.0.0-stage → 1.0.0-beta.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/LICENSE +21 -0
- package/README.md +24 -2
- package/dist/config/from-cli.d.ts +43 -0
- package/dist/config/from-cli.js +31 -0
- package/dist/config/load.d.ts +13 -0
- package/dist/config/load.js +96 -0
- package/dist/config/normalize.d.ts +14 -0
- package/dist/config/normalize.js +53 -0
- package/dist/config/process.d.ts +16 -0
- package/dist/config/process.js +128 -0
- package/dist/config/quasar-cli.d.ts +31 -0
- package/dist/config/quasar-cli.js +74 -0
- package/dist/config/resolve.d.ts +14 -0
- package/dist/config/resolve.js +29 -0
- package/dist/config/setup-code.d.ts +6 -0
- package/dist/config/setup-code.js +69 -0
- package/dist/config/types.d.ts +80 -0
- package/dist/config/types.js +1 -0
- package/dist/config/utils.d.ts +12 -0
- package/dist/config/utils.js +20 -0
- package/dist/config/vite.d.ts +7 -0
- package/dist/config/vite.js +39 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +28 -0
- package/dist/runtime/setup.d.ts +50 -0
- package/dist/runtime/setup.js +57 -0
- package/package.json +85 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Guillaume Chau
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Histoire + Quasar CLI
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Integrates [Quasar CLI](https://quasar.dev/start/quasar-cli) projects using `@quasar/app-vite`: it reads `quasar.config` (App Extensions included), loads Quasar styles and `framework` options, installs the project store and runs client boot files.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
pnpm add -D @histoire/plugin-vue @histoire/plugin-quasar
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Add the plugins in `histoire.config.ts`:
|
|
10
|
+
|
|
11
|
+
```js
|
|
12
|
+
import { HstQuasar } from '@histoire/plugin-quasar'
|
|
13
|
+
import { HstVue } from '@histoire/plugin-vue'
|
|
14
|
+
import { defineConfig } from 'histoire'
|
|
15
|
+
|
|
16
|
+
export default defineConfig({
|
|
17
|
+
storyMatch: ['src/**/*.story.vue'],
|
|
18
|
+
plugins: [
|
|
19
|
+
HstVue(),
|
|
20
|
+
HstQuasar(),
|
|
21
|
+
],
|
|
22
|
+
})
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
[Documentation](https://histoire.dev/guide/vue3/getting-started.html#quasar-cli)
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { QuasarAssetEntry, ResolvedQuasarConfig } from './types.js';
|
|
2
|
+
/** Subset of Quasar CLI's normalized `quasarConf` used by Histoire. */
|
|
3
|
+
export interface QuasarCliConfig {
|
|
4
|
+
/** Quasar CLI context; only the project folder is used. */
|
|
5
|
+
ctx: {
|
|
6
|
+
appPaths: {
|
|
7
|
+
appDir: string;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
/** Normalized boot entries (`@/boot/...` or package paths). */
|
|
11
|
+
boot: Exclude<QuasarAssetEntry, string | false | null | undefined>[];
|
|
12
|
+
/** Normalized stylesheet entries. */
|
|
13
|
+
css: Exclude<QuasarAssetEntry, string | false | null | undefined>[];
|
|
14
|
+
/** `@quasar/extras` asset names. */
|
|
15
|
+
extras: string[];
|
|
16
|
+
/** Animation names, `'all'` already expanded. */
|
|
17
|
+
animations: string[];
|
|
18
|
+
/** Normalized framework options (spinners added to components, lang/iconSet as paths). */
|
|
19
|
+
framework: Omit<ResolvedQuasarConfig['framework'], 'lang' | 'iconSet'> & {
|
|
20
|
+
lang?: string;
|
|
21
|
+
iconSet?: string;
|
|
22
|
+
cssAddon?: boolean;
|
|
23
|
+
};
|
|
24
|
+
/** Project-relative source file paths. */
|
|
25
|
+
sourceFiles: {
|
|
26
|
+
store: string;
|
|
27
|
+
router: string;
|
|
28
|
+
};
|
|
29
|
+
/** Values Quasar CLI computed from the project files. */
|
|
30
|
+
metaConf: {
|
|
31
|
+
hasStore: boolean;
|
|
32
|
+
css: {
|
|
33
|
+
quasarSrcExt: 'css' | 'sass';
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Map Quasar CLI's own normalized config (App Extension hooks applied) to
|
|
39
|
+
* setup-ready values. Quasar already resolved paths, spinners and animations.
|
|
40
|
+
*/
|
|
41
|
+
export declare function fromQuasarCliConfig(conf: QuasarCliConfig, { exists }: {
|
|
42
|
+
exists: (path: string) => boolean;
|
|
43
|
+
}): ResolvedQuasarConfig;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { resolveScript } from './normalize.js';
|
|
2
|
+
/** Client asset paths of normalized Quasar CLI entries. */
|
|
3
|
+
function clientPaths(entries) {
|
|
4
|
+
return entries.filter(entry => entry.client !== false).map(entry => entry.path);
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Map Quasar CLI's own normalized config (App Extension hooks applied) to
|
|
8
|
+
* setup-ready values. Quasar already resolved paths, spinners and animations.
|
|
9
|
+
*/
|
|
10
|
+
export function fromQuasarCliConfig(conf, { exists }) {
|
|
11
|
+
const { appDir } = conf.ctx.appPaths;
|
|
12
|
+
const { framework } = conf;
|
|
13
|
+
return {
|
|
14
|
+
boot: clientPaths(conf.boot),
|
|
15
|
+
css: clientPaths(conf.css),
|
|
16
|
+
extras: conf.extras,
|
|
17
|
+
animations: conf.animations,
|
|
18
|
+
cssAddon: Boolean(framework.cssAddon),
|
|
19
|
+
quasarSrcExt: conf.metaConf.css.quasarSrcExt,
|
|
20
|
+
framework: {
|
|
21
|
+
config: framework.config,
|
|
22
|
+
components: framework.components,
|
|
23
|
+
directives: framework.directives,
|
|
24
|
+
plugins: framework.plugins,
|
|
25
|
+
lang: framework.lang,
|
|
26
|
+
iconSet: framework.iconSet,
|
|
27
|
+
},
|
|
28
|
+
storeFile: conf.metaConf.hasStore ? resolveScript(appDir, conf.sourceFiles.store, exists) : undefined,
|
|
29
|
+
hasRouter: Boolean(resolveScript(appDir, conf.sourceFiles.router, exists)),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { UserConfig } from 'vite';
|
|
2
|
+
import type { RawQuasarConfig } from './types.js';
|
|
3
|
+
/** Quasar config file in `root`; throws a regular error when missing. */
|
|
4
|
+
export declare function findQuasarConfigFile(root: string): string;
|
|
5
|
+
/** Quasar CLI's resolved SPA Vite config, from its public testing endpoint. */
|
|
6
|
+
export declare function loadQuasarViteConfig(root: string, dev: boolean): Promise<UserConfig>;
|
|
7
|
+
/** Every `@quasar/extras` animation name, resolved from the project. */
|
|
8
|
+
export declare function loadAllAnimations(root: string): string[];
|
|
9
|
+
/**
|
|
10
|
+
* Evaluate the user `quasar.config` file directly. Fallback when Quasar CLI's
|
|
11
|
+
* own loader is unavailable: App Extension hooks don't apply.
|
|
12
|
+
*/
|
|
13
|
+
export declare function loadQuasarConfig(root: string, dev: boolean): Promise<RawQuasarConfig>;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
|
+
import { runnerImport } from 'vite';
|
|
4
|
+
import { runInQuasarScope } from './process.js';
|
|
5
|
+
import { projectRequire } from './utils.js';
|
|
6
|
+
/** Config file names Quasar CLI looks for, in order. */
|
|
7
|
+
const configFiles = ['quasar.config.js', 'quasar.config.ts'];
|
|
8
|
+
/** Quasar config file in `root`; throws a regular error when missing. */
|
|
9
|
+
export function findQuasarConfigFile(root) {
|
|
10
|
+
const file = configFiles.map(name => join(root, name)).find(existsSync);
|
|
11
|
+
// Quasar CLI would walk up parent folders and could pick another project.
|
|
12
|
+
if (!file)
|
|
13
|
+
throw new Error(`No quasar.config.js or quasar.config.ts file found in ${root}`);
|
|
14
|
+
return file;
|
|
15
|
+
}
|
|
16
|
+
/** Quasar CLI context passed to the `quasar.config` function (SPA mode). */
|
|
17
|
+
function createQuasarContext(root, dev) {
|
|
18
|
+
const srcDir = join(root, 'src');
|
|
19
|
+
return {
|
|
20
|
+
dev,
|
|
21
|
+
prod: !dev,
|
|
22
|
+
mode: { spa: true },
|
|
23
|
+
modeName: 'spa',
|
|
24
|
+
target: {},
|
|
25
|
+
arch: {},
|
|
26
|
+
bundler: {},
|
|
27
|
+
debug: false,
|
|
28
|
+
// Public context members configs commonly use to build paths.
|
|
29
|
+
appPaths: {
|
|
30
|
+
appDir: root,
|
|
31
|
+
srcDir,
|
|
32
|
+
publicDir: join(root, 'public'),
|
|
33
|
+
resolve: {
|
|
34
|
+
app: (path) => join(root, path),
|
|
35
|
+
src: (path) => join(srcDir, path),
|
|
36
|
+
public: (path) => join(root, 'public', path),
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
logger: console,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/** Identifiers `__dirname`/`__filename` are defined to, declared per file by {@link cjsGlobalsPlugin}. */
|
|
43
|
+
const cjsGlobals = { __dirname: '__hst_quasar_dirname__', __filename: '__hst_quasar_filename__' };
|
|
44
|
+
/**
|
|
45
|
+
* Give each config module its own `__dirname`/`__filename`, like Quasar CLI's
|
|
46
|
+
* config bundler does (a plain `define` would give every file the root's).
|
|
47
|
+
*/
|
|
48
|
+
function cjsGlobalsPlugin() {
|
|
49
|
+
return {
|
|
50
|
+
name: 'histoire-plugin-quasar:cjs-globals',
|
|
51
|
+
/** Prefix files using `__dirname`/`__filename` with their own values. */
|
|
52
|
+
transform(code, id) {
|
|
53
|
+
if (!/\.[cm]?[jt]s$/.test(id))
|
|
54
|
+
return;
|
|
55
|
+
let prefix = '';
|
|
56
|
+
if (code.includes('__dirname'))
|
|
57
|
+
prefix += `const ${cjsGlobals.__dirname} = ${JSON.stringify(dirname(id))};\n`;
|
|
58
|
+
if (code.includes('__filename'))
|
|
59
|
+
prefix += `const ${cjsGlobals.__filename} = ${JSON.stringify(id)};\n`;
|
|
60
|
+
return prefix ? prefix + code : undefined;
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/** Quasar CLI's resolved SPA Vite config, from its public testing endpoint. */
|
|
65
|
+
export async function loadQuasarViteConfig(root, dev) {
|
|
66
|
+
const { getTestingConfig } = await import('@quasar/app-vite/testing');
|
|
67
|
+
return runInQuasarScope(root, () => getTestingConfig({ dev, prod: !dev, mode: 'spa' }));
|
|
68
|
+
}
|
|
69
|
+
/** Every `@quasar/extras` animation name, resolved from the project. */
|
|
70
|
+
export function loadAllAnimations(root) {
|
|
71
|
+
const require = projectRequire(root);
|
|
72
|
+
const list = require('@quasar/extras/animate/animate-list.common');
|
|
73
|
+
return [...list.generalAnimations, ...list.inAnimations, ...list.outAnimations];
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Evaluate the user `quasar.config` file directly. Fallback when Quasar CLI's
|
|
77
|
+
* own loader is unavailable: App Extension hooks don't apply.
|
|
78
|
+
*/
|
|
79
|
+
export async function loadQuasarConfig(root, dev) {
|
|
80
|
+
const file = findQuasarConfigFile(root);
|
|
81
|
+
// Same cwd as the Quasar CLI path for `process.cwd()`/`path.resolve` in the config.
|
|
82
|
+
return runInQuasarScope(root, async () => {
|
|
83
|
+
const { module } = await runnerImport(file, {
|
|
84
|
+
root,
|
|
85
|
+
configFile: false,
|
|
86
|
+
// Same alias and CommonJS globals Quasar CLI provides when bundling its config file.
|
|
87
|
+
resolve: { alias: { '#q-app': '@quasar/app-vite' } },
|
|
88
|
+
define: cjsGlobals,
|
|
89
|
+
plugins: [cjsGlobalsPlugin()],
|
|
90
|
+
});
|
|
91
|
+
const exported = module.default;
|
|
92
|
+
return typeof exported === 'function'
|
|
93
|
+
? await exported(createQuasarContext(root, dev))
|
|
94
|
+
: exported;
|
|
95
|
+
});
|
|
96
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { RawQuasarConfig, ResolvedQuasarConfig } from './types.js';
|
|
2
|
+
/** Options for {@link normalizeQuasarConfig}. */
|
|
3
|
+
export interface NormalizeOptions {
|
|
4
|
+
/** Quasar project root. */
|
|
5
|
+
root: string;
|
|
6
|
+
/** File existence check, injectable for tests. */
|
|
7
|
+
exists: (path: string) => boolean;
|
|
8
|
+
/** Every `@quasar/extras` animation name, for `animations: 'all'`. */
|
|
9
|
+
allAnimations: () => string[];
|
|
10
|
+
}
|
|
11
|
+
/** First existing file for a project path, with or without extension, as a POSIX path. */
|
|
12
|
+
export declare function resolveScript(root: string, file: string, exists: NormalizeOptions['exists']): string | undefined;
|
|
13
|
+
/** Turn a raw `quasar.config` result into setup-ready values. */
|
|
14
|
+
export declare function normalizeQuasarConfig(raw: RawQuasarConfig, { root, exists, allAnimations }: NormalizeOptions): ResolvedQuasarConfig;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import { getConfigSpinners, unique } from './utils.js';
|
|
3
|
+
/** Same lookup order as Quasar CLI's `resolveExtension`. */
|
|
4
|
+
const scriptExtensions = ['', '.js', '.ts', '.jsx', '.tsx'];
|
|
5
|
+
/**
|
|
6
|
+
* Resolve client asset paths the way Quasar CLI does: `~` prefix points to a
|
|
7
|
+
* package, other entries are relative to `src/<folder>`.
|
|
8
|
+
*/
|
|
9
|
+
function resolveAssets(entries = [], folder) {
|
|
10
|
+
const paths = entries
|
|
11
|
+
.filter(Boolean)
|
|
12
|
+
.map(entry => typeof entry === 'string' ? { path: entry } : entry)
|
|
13
|
+
.filter(entry => entry.path && entry.client !== false)
|
|
14
|
+
.map(entry => entry.path.startsWith('~') ? entry.path.slice(1) : `@/${folder}/${entry.path}`);
|
|
15
|
+
return unique(paths);
|
|
16
|
+
}
|
|
17
|
+
/** Quasar shorthand (`de`) or explicit path to a language pack / icon set module. */
|
|
18
|
+
function resolveQuasarModule(asset, type) {
|
|
19
|
+
if (!asset)
|
|
20
|
+
return undefined;
|
|
21
|
+
if (!asset.includes('/'))
|
|
22
|
+
return `quasar/${type}/${asset}.js`;
|
|
23
|
+
return /\.[cm]?[jt]s$/.test(asset) ? asset : `${asset}.js`;
|
|
24
|
+
}
|
|
25
|
+
/** First existing file for a project path, with or without extension, as a POSIX path. */
|
|
26
|
+
export function resolveScript(root, file, exists) {
|
|
27
|
+
return scriptExtensions.map(ext => join(root, file + ext)).find(exists)?.replace(/\\/g, '/');
|
|
28
|
+
}
|
|
29
|
+
/** Turn a raw `quasar.config` result into setup-ready values. */
|
|
30
|
+
export function normalizeQuasarConfig(raw, { root, exists, allAnimations }) {
|
|
31
|
+
const framework = raw.framework ?? {};
|
|
32
|
+
const config = framework.config ?? {};
|
|
33
|
+
const animations = raw.animations === 'all' ? allAnimations() : raw.animations ?? [];
|
|
34
|
+
const hasSassVariables = ['scss', 'sass'].some(ext => exists(join(root, `src/css/quasar.variables.${ext}`)));
|
|
35
|
+
return {
|
|
36
|
+
boot: resolveAssets(raw.boot, 'boot'),
|
|
37
|
+
css: resolveAssets(raw.css, 'css'),
|
|
38
|
+
extras: unique((raw.extras ?? []).filter(Boolean)),
|
|
39
|
+
animations: unique(animations.filter(Boolean)),
|
|
40
|
+
cssAddon: Boolean(framework.cssAddon),
|
|
41
|
+
quasarSrcExt: hasSassVariables ? 'sass' : 'css',
|
|
42
|
+
framework: {
|
|
43
|
+
config,
|
|
44
|
+
components: unique([...framework.components ?? [], ...getConfigSpinners(config).map(({ spinner }) => spinner)]),
|
|
45
|
+
directives: unique(framework.directives ?? []),
|
|
46
|
+
plugins: unique(framework.plugins ?? []),
|
|
47
|
+
lang: resolveQuasarModule(framework.lang, 'lang'),
|
|
48
|
+
iconSet: resolveQuasarModule(framework.iconSet, 'icon-set'),
|
|
49
|
+
},
|
|
50
|
+
storeFile: resolveScript(root, raw.sourceFiles?.store ?? 'src/stores/index', exists),
|
|
51
|
+
hasRouter: Boolean(resolveScript(root, raw.sourceFiles?.router ?? 'src/router/index', exists)),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Thrown in place of Quasar CLI's `process.exit`; Quasar may log it before exiting again. */
|
|
2
|
+
export declare class QuasarCliExitError extends Error {
|
|
3
|
+
/** @param code Exit code Quasar CLI requested. */
|
|
4
|
+
constructor(code?: number);
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Run Quasar CLI code as if Histoire had started in the project folder:
|
|
8
|
+
* `process.cwd()` (and `path.resolve`) returns `root` for code in this load,
|
|
9
|
+
* including the user config, App Extensions and Vite plugin factories.
|
|
10
|
+
* Relative `fs` paths still use the real cwd.
|
|
11
|
+
*
|
|
12
|
+
* Quasar progress output is dropped on success; warnings and errors are
|
|
13
|
+
* shown. On failure, everything is shown before the error, and Quasar's
|
|
14
|
+
* `process.exit` becomes a thrown {@link QuasarCliExitError}.
|
|
15
|
+
*/
|
|
16
|
+
export declare function runInQuasarScope<T>(root: string, fn: () => Promise<T>): Promise<T>;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/* eslint-disable no-console -- buffers Quasar CLI console output during its config load */
|
|
2
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
3
|
+
/** Thrown in place of Quasar CLI's `process.exit`; Quasar may log it before exiting again. */
|
|
4
|
+
export class QuasarCliExitError extends Error {
|
|
5
|
+
/** @param code Exit code Quasar CLI requested. */
|
|
6
|
+
constructor(code) {
|
|
7
|
+
super(`Quasar CLI failed (exit code ${code ?? 0}), see the messages above.`);
|
|
8
|
+
this.name = 'QuasarCliExitError';
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
/** Buffered methods, in replay order. */
|
|
12
|
+
const consoleMethods = ['log', 'info', 'warn', 'error'];
|
|
13
|
+
/** Quasar's `warning()`/`error()` loggers print with `console.log` and a WARNING/ERROR pill. */
|
|
14
|
+
const loggedProblemRE = /\s(?:WARNING|ERROR)\s/;
|
|
15
|
+
/** Current Quasar load, propagated through async continuations. */
|
|
16
|
+
const storage = new AsyncLocalStorage();
|
|
17
|
+
/** Installed patches while at least one load is in flight. */
|
|
18
|
+
let patches;
|
|
19
|
+
/** Scope of the running load, if code runs inside an active one. */
|
|
20
|
+
function activeScope() {
|
|
21
|
+
const scope = storage.getStore();
|
|
22
|
+
return scope?.active ? scope : undefined;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Patch process/console globals so they behave differently only for code
|
|
26
|
+
* running inside an active Quasar scope (async continuations included). Code
|
|
27
|
+
* outside keeps the original behavior, so Histoire never changes the process cwd.
|
|
28
|
+
*/
|
|
29
|
+
function installPatches() {
|
|
30
|
+
if (patches) {
|
|
31
|
+
patches.users++;
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const original = {
|
|
35
|
+
cwd: process.cwd,
|
|
36
|
+
exit: process.exit,
|
|
37
|
+
console: Object.fromEntries(consoleMethods.map(method => [method, console[method]])),
|
|
38
|
+
};
|
|
39
|
+
const wrappers = {
|
|
40
|
+
cwd: () => activeScope()?.root ?? original.cwd.call(process),
|
|
41
|
+
exit: ((code) => {
|
|
42
|
+
// Quasar CLI's `fatal()` exits on config, App Extension or `index.html`
|
|
43
|
+
// problems, which would kill Histoire's server.
|
|
44
|
+
if (activeScope())
|
|
45
|
+
throw new QuasarCliExitError(code);
|
|
46
|
+
return original.exit.call(process, code);
|
|
47
|
+
}),
|
|
48
|
+
console: Object.fromEntries(consoleMethods.map(method => [method, (...args) => {
|
|
49
|
+
const scope = activeScope();
|
|
50
|
+
if (scope)
|
|
51
|
+
scope.output.push({ method, args });
|
|
52
|
+
else
|
|
53
|
+
original.console[method](...args);
|
|
54
|
+
}])),
|
|
55
|
+
};
|
|
56
|
+
patches = { original, wrappers, users: 1 };
|
|
57
|
+
process.cwd = wrappers.cwd;
|
|
58
|
+
process.exit = wrappers.exit;
|
|
59
|
+
for (const method of consoleMethods)
|
|
60
|
+
console[method] = wrappers.console[method];
|
|
61
|
+
}
|
|
62
|
+
/** Restore the original globals once no load is in flight, unless replaced since. */
|
|
63
|
+
function uninstallPatches() {
|
|
64
|
+
if (!patches || --patches.users > 0)
|
|
65
|
+
return;
|
|
66
|
+
const { original, wrappers } = patches;
|
|
67
|
+
if (process.cwd === wrappers.cwd) {
|
|
68
|
+
process.cwd = original.cwd;
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
// A library loaded during the load (e.g. graceful-fs) may have wrapped
|
|
72
|
+
// `process.cwd` with a cache holding the project root; it clears that
|
|
73
|
+
// cache on `chdir`. Changing to the current folder moves nothing.
|
|
74
|
+
try {
|
|
75
|
+
process.chdir(original.cwd.call(process));
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
// `chdir` is unavailable in worker threads.
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (process.exit === wrappers.exit)
|
|
82
|
+
process.exit = original.exit;
|
|
83
|
+
for (const method of consoleMethods) {
|
|
84
|
+
if (console[method] === wrappers.console[method])
|
|
85
|
+
console[method] = original.console[method];
|
|
86
|
+
}
|
|
87
|
+
patches = undefined;
|
|
88
|
+
}
|
|
89
|
+
/** Whether buffered output is shown after a successful load. */
|
|
90
|
+
function isProblem({ method, args }) {
|
|
91
|
+
return method === 'warn' || method === 'error' || (typeof args[0] === 'string' && loggedProblemRE.test(args[0]));
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Run Quasar CLI code as if Histoire had started in the project folder:
|
|
95
|
+
* `process.cwd()` (and `path.resolve`) returns `root` for code in this load,
|
|
96
|
+
* including the user config, App Extensions and Vite plugin factories.
|
|
97
|
+
* Relative `fs` paths still use the real cwd.
|
|
98
|
+
*
|
|
99
|
+
* Quasar progress output is dropped on success; warnings and errors are
|
|
100
|
+
* shown. On failure, everything is shown before the error, and Quasar's
|
|
101
|
+
* `process.exit` becomes a thrown {@link QuasarCliExitError}.
|
|
102
|
+
*/
|
|
103
|
+
export async function runInQuasarScope(root, fn) {
|
|
104
|
+
const scope = { root, output: [], active: true };
|
|
105
|
+
installPatches();
|
|
106
|
+
const print = patches.original.console;
|
|
107
|
+
let failed = false;
|
|
108
|
+
try {
|
|
109
|
+
return await storage.run(scope, fn);
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
failed = true;
|
|
113
|
+
throw error;
|
|
114
|
+
}
|
|
115
|
+
finally {
|
|
116
|
+
scope.active = false;
|
|
117
|
+
for (const entry of scope.output) {
|
|
118
|
+
// The exit error is rethrown to the caller; Quasar logging it is noise.
|
|
119
|
+
if (entry.args.some(arg => arg instanceof QuasarCliExitError))
|
|
120
|
+
continue;
|
|
121
|
+
if (failed || isProblem(entry))
|
|
122
|
+
print[entry.method](...entry.args);
|
|
123
|
+
}
|
|
124
|
+
// Timers left by the load keep this scope alive: don't keep its output too.
|
|
125
|
+
scope.output.length = 0;
|
|
126
|
+
uninstallPatches();
|
|
127
|
+
}
|
|
128
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { UserConfig } from 'vite';
|
|
2
|
+
import type { QuasarCliConfig } from './from-cli.js';
|
|
3
|
+
/** Quasar CLI's normalized config and the SPA Vite config generated from it. */
|
|
4
|
+
export interface QuasarCliResult {
|
|
5
|
+
/** Normalized config, App Extension hooks applied; `undefined` if its shape changed. */
|
|
6
|
+
quasarConf?: QuasarCliConfig;
|
|
7
|
+
/** SPA Vite config generated from it. */
|
|
8
|
+
viteConfig: UserConfig;
|
|
9
|
+
}
|
|
10
|
+
/** Quasar CLI App Extension runner (subset). */
|
|
11
|
+
interface QuasarAppExt {
|
|
12
|
+
/** Runs `fn` for each App Extension registered for hook `name`. */
|
|
13
|
+
runAppExtensionHook: (name: string, fn: (hook: any) => Promise<void>) => Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Append a last `extendQuasarConf` step turning off Quasar dev server
|
|
17
|
+
* features: Histoire runs its own server, so Quasar must not generate an
|
|
18
|
+
* HTTPS certificate or plan to open a browser.
|
|
19
|
+
*/
|
|
20
|
+
export declare function disableDevServer(appExt: QuasarAppExt): void;
|
|
21
|
+
/** Whether Quasar CLI's normalized config still has the shape Histoire maps. */
|
|
22
|
+
export declare function isQuasarCliConfig(conf: any): conf is QuasarCliConfig;
|
|
23
|
+
/**
|
|
24
|
+
* Load the project config through Quasar CLI's own config loader, the same
|
|
25
|
+
* steps as its public `getTestingConfig` endpoint, so App Extension
|
|
26
|
+
* `extendQuasarConf` hooks apply to boot files, CSS and framework options too.
|
|
27
|
+
* These modules are internal: returns `undefined` when they can't be loaded,
|
|
28
|
+
* and no `quasarConf` when its shape changed. Config errors are thrown.
|
|
29
|
+
*/
|
|
30
|
+
export declare function loadQuasarCli(root: string, dev: boolean): Promise<QuasarCliResult | undefined>;
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { dirname, join } from 'node:path';
|
|
2
|
+
import { pathToFileURL } from 'node:url';
|
|
3
|
+
import { runInQuasarScope } from './process.js';
|
|
4
|
+
import { projectRequire } from './utils.js';
|
|
5
|
+
/**
|
|
6
|
+
* Append a last `extendQuasarConf` step turning off Quasar dev server
|
|
7
|
+
* features: Histoire runs its own server, so Quasar must not generate an
|
|
8
|
+
* HTTPS certificate or plan to open a browser.
|
|
9
|
+
*/
|
|
10
|
+
export function disableDevServer(appExt) {
|
|
11
|
+
const run = appExt.runAppExtensionHook.bind(appExt);
|
|
12
|
+
appExt.runAppExtensionHook = async (name, fn) => {
|
|
13
|
+
await run(name, fn);
|
|
14
|
+
if (name !== 'extendQuasarConf')
|
|
15
|
+
return;
|
|
16
|
+
await fn({
|
|
17
|
+
fn: (conf) => {
|
|
18
|
+
conf.devServer = { ...conf.devServer, https: false, open: false };
|
|
19
|
+
},
|
|
20
|
+
// Quasar only logs through `api.logger` around hooks; any method is a no-op.
|
|
21
|
+
api: { logger: new Proxy({}, { get: () => () => { } }) },
|
|
22
|
+
packageDir: '',
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/** Whether Quasar CLI's normalized config still has the shape Histoire maps. */
|
|
27
|
+
export function isQuasarCliConfig(conf) {
|
|
28
|
+
return typeof conf?.ctx?.appPaths?.appDir === 'string'
|
|
29
|
+
&& ['boot', 'css', 'extras', 'animations'].every(key => Array.isArray(conf[key]))
|
|
30
|
+
&& ['components', 'directives', 'plugins'].every(key => Array.isArray(conf.framework?.[key]))
|
|
31
|
+
&& typeof conf.sourceFiles?.store === 'string'
|
|
32
|
+
&& typeof conf.sourceFiles?.router === 'string'
|
|
33
|
+
&& typeof conf.metaConf?.hasStore === 'boolean'
|
|
34
|
+
&& typeof conf.metaConf?.css?.quasarSrcExt === 'string';
|
|
35
|
+
}
|
|
36
|
+
/** Import the project's own Quasar CLI internals; `undefined` if they moved. */
|
|
37
|
+
async function importQuasarCli(root) {
|
|
38
|
+
try {
|
|
39
|
+
// Project's own Quasar CLI, as App Extensions are resolved from it.
|
|
40
|
+
const cliDir = dirname(projectRequire(root).resolve('@quasar/app-vite/package.json'));
|
|
41
|
+
const load = (file) => import(pathToFileURL(join(cliDir, file)).href);
|
|
42
|
+
const [{ getCtx }, { QuasarConfigFile }, { quasarSpaConfig }] = await Promise.all([
|
|
43
|
+
load('lib/utils/get-ctx.js'),
|
|
44
|
+
load('lib/quasar-config-file.js'),
|
|
45
|
+
load('lib/modes/spa/spa-config.js'),
|
|
46
|
+
]);
|
|
47
|
+
if (typeof getCtx !== 'function' || typeof QuasarConfigFile !== 'function' || typeof quasarSpaConfig?.vite !== 'function')
|
|
48
|
+
return undefined;
|
|
49
|
+
return { getCtx, QuasarConfigFile, quasarSpaConfig };
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Load the project config through Quasar CLI's own config loader, the same
|
|
57
|
+
* steps as its public `getTestingConfig` endpoint, so App Extension
|
|
58
|
+
* `extendQuasarConf` hooks apply to boot files, CSS and framework options too.
|
|
59
|
+
* These modules are internal: returns `undefined` when they can't be loaded,
|
|
60
|
+
* and no `quasarConf` when its shape changed. Config errors are thrown.
|
|
61
|
+
*/
|
|
62
|
+
export async function loadQuasarCli(root, dev) {
|
|
63
|
+
const cli = await importQuasarCli(root);
|
|
64
|
+
if (!cli)
|
|
65
|
+
return undefined;
|
|
66
|
+
return runInQuasarScope(root, async () => {
|
|
67
|
+
const ctx = cli.getCtx({ mode: 'spa', dev, prod: !dev });
|
|
68
|
+
if (typeof ctx.appExt?.runAppExtensionHook === 'function')
|
|
69
|
+
disableDevServer(ctx.appExt);
|
|
70
|
+
const quasarConf = await new cli.QuasarConfigFile({ ctx }).read();
|
|
71
|
+
const viteConfig = await cli.quasarSpaConfig.vite(quasarConf);
|
|
72
|
+
return { quasarConf: isQuasarCliConfig(quasarConf) ? quasarConf : undefined, viteConfig };
|
|
73
|
+
});
|
|
74
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { UserConfig } from 'vite';
|
|
2
|
+
import type { ResolvedQuasarConfig } from './types.js';
|
|
3
|
+
/** Quasar project resolved for Histoire. */
|
|
4
|
+
export interface ResolvedQuasarProject {
|
|
5
|
+
/** Quasar CLI's SPA Vite config. */
|
|
6
|
+
viteConfig: UserConfig;
|
|
7
|
+
/** Setup-ready config. */
|
|
8
|
+
config: ResolvedQuasarConfig;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Resolve a Quasar CLI project. Prefers Quasar CLI's own config loader, which
|
|
12
|
+
* applies App Extensions; falls back to evaluating `quasar.config` directly.
|
|
13
|
+
*/
|
|
14
|
+
export declare function resolveQuasarProject(root: string, dev: boolean): Promise<ResolvedQuasarProject>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { fromQuasarCliConfig } from './from-cli.js';
|
|
3
|
+
import { findQuasarConfigFile, loadAllAnimations, loadQuasarConfig, loadQuasarViteConfig } from './load.js';
|
|
4
|
+
import { normalizeQuasarConfig } from './normalize.js';
|
|
5
|
+
import { loadQuasarCli } from './quasar-cli.js';
|
|
6
|
+
/**
|
|
7
|
+
* Resolve a Quasar CLI project. Prefers Quasar CLI's own config loader, which
|
|
8
|
+
* applies App Extensions; falls back to evaluating `quasar.config` directly.
|
|
9
|
+
*/
|
|
10
|
+
export async function resolveQuasarProject(root, dev) {
|
|
11
|
+
findQuasarConfigFile(root);
|
|
12
|
+
const cli = await loadQuasarCli(root, dev);
|
|
13
|
+
if (cli?.quasarConf) {
|
|
14
|
+
return {
|
|
15
|
+
viteConfig: cli.viteConfig,
|
|
16
|
+
config: fromQuasarCliConfig(cli.quasarConf, { exists: existsSync }),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
console.warn('[@histoire/plugin-quasar] Quasar CLI config loader unavailable: boot files, CSS and framework options added by App Extensions are not loaded.');
|
|
20
|
+
return {
|
|
21
|
+
// Keep Quasar CLI's Vite config when only its normalized config changed shape.
|
|
22
|
+
viteConfig: cli?.viteConfig ?? await loadQuasarViteConfig(root, dev),
|
|
23
|
+
config: normalizeQuasarConfig(await loadQuasarConfig(root, dev), {
|
|
24
|
+
root,
|
|
25
|
+
exists: existsSync,
|
|
26
|
+
allAnimations: () => loadAllAnimations(root),
|
|
27
|
+
}),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ResolvedQuasarConfig } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Generate the `setupCode` module installing Quasar like Quasar CLI's app
|
|
4
|
+
* entry does: styles, `app.use(Quasar)`, store, then client boot files.
|
|
5
|
+
*/
|
|
6
|
+
export declare function generateSetupCode(conf: ResolvedQuasarConfig): string;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { getConfigSpinners, unique } from './utils.js';
|
|
2
|
+
/** Module path of the runtime helper imported by generated setup code. */
|
|
3
|
+
const RUNTIME_ID = '@histoire/plugin-quasar/runtime';
|
|
4
|
+
/** Stylesheet imports in the same order as Quasar CLI's client entry. */
|
|
5
|
+
function styleImports(conf) {
|
|
6
|
+
return [
|
|
7
|
+
...conf.extras.map(asset => `@quasar/extras/${asset}/${asset}.css`),
|
|
8
|
+
...conf.animations.map(asset => `@quasar/extras/animate/${asset}.css`),
|
|
9
|
+
`quasar/dist/quasar.${conf.quasarSrcExt}`,
|
|
10
|
+
...conf.cssAddon ? ['quasar/src/css/flex-addon.sass'] : [],
|
|
11
|
+
...conf.css,
|
|
12
|
+
].map(path => `import ${JSON.stringify(path)}`);
|
|
13
|
+
}
|
|
14
|
+
/** `{ config, components, directives, plugins, lang, iconSet }` options source. */
|
|
15
|
+
function frameworkOptions(conf) {
|
|
16
|
+
const { framework } = conf;
|
|
17
|
+
const entries = [`config: ${JSON.stringify(framework.config)}`];
|
|
18
|
+
for (const type of ['components', 'directives', 'plugins']) {
|
|
19
|
+
if (framework[type].length)
|
|
20
|
+
entries.push(`${type}: { ${framework[type].join(', ')} }`);
|
|
21
|
+
}
|
|
22
|
+
if (framework.lang)
|
|
23
|
+
entries.push('lang');
|
|
24
|
+
if (framework.iconSet)
|
|
25
|
+
entries.push('iconSet');
|
|
26
|
+
return `{ ${entries.join(', ')} }`;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Generate the `setupCode` module installing Quasar like Quasar CLI's app
|
|
30
|
+
* entry does: styles, `app.use(Quasar)`, store, then client boot files.
|
|
31
|
+
*/
|
|
32
|
+
export function generateSetupCode(conf) {
|
|
33
|
+
const { framework } = conf;
|
|
34
|
+
// `Dark` is always imported: the runtime syncs it with Histoire's dark mode.
|
|
35
|
+
const quasarImports = unique(['Quasar', 'Dark', ...framework.components, ...framework.directives, ...framework.plugins]);
|
|
36
|
+
const imports = [
|
|
37
|
+
...styleImports(conf),
|
|
38
|
+
`import { ${quasarImports.join(', ')} } from 'quasar'`,
|
|
39
|
+
...framework.lang ? [`import lang from ${JSON.stringify(framework.lang)}`] : [],
|
|
40
|
+
...framework.iconSet ? [`import iconSet from ${JSON.stringify(framework.iconSet)}`] : [],
|
|
41
|
+
...conf.storeFile ? [`import createStore from ${JSON.stringify(conf.storeFile)}`] : [],
|
|
42
|
+
...conf.hasRouter ? [`import { createRouter, createMemoryHistory } from 'vue-router'`] : [],
|
|
43
|
+
`import { setupQuasarApp } from '${RUNTIME_ID}'`,
|
|
44
|
+
];
|
|
45
|
+
const bootFiles = conf.boot.map(path => `{ path: ${JSON.stringify(path)}, load: () => import(${JSON.stringify(path)}) }`);
|
|
46
|
+
// Spinners are component identifiers, not strings (Quasar CLI does the same).
|
|
47
|
+
const spinners = getConfigSpinners(framework.config)
|
|
48
|
+
.map(({ key, spinner }) => `options.config.${key}.spinner = ${spinner}`);
|
|
49
|
+
const options = [
|
|
50
|
+
'Quasar,',
|
|
51
|
+
'Dark,',
|
|
52
|
+
'options,',
|
|
53
|
+
...conf.storeFile ? ['createStore,'] : [],
|
|
54
|
+
// Memory history keeps router-aware boot files away from the sandbox URL.
|
|
55
|
+
...conf.hasRouter ? ['createRouter: () => createRouter({ history: createMemoryHistory(), routes: [] }),'] : [],
|
|
56
|
+
`bootFiles: [${bootFiles.join(', ')}],`,
|
|
57
|
+
];
|
|
58
|
+
return `${imports.join('\n')}
|
|
59
|
+
|
|
60
|
+
const options = ${frameworkOptions(conf)}
|
|
61
|
+
${spinners.join('\n')}
|
|
62
|
+
|
|
63
|
+
export async function setupVue3 (setupApi) {
|
|
64
|
+
await setupQuasarApp(setupApi, {
|
|
65
|
+
${options.join('\n ')}
|
|
66
|
+
})
|
|
67
|
+
}
|
|
68
|
+
`;
|
|
69
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/** Asset entry as written in `quasar.config` (`boot`, `css`). */
|
|
2
|
+
export type QuasarAssetEntry = string | false | null | undefined | {
|
|
3
|
+
/** Path relative to `src/<folder>`, or `~package/path`. */
|
|
4
|
+
path: string;
|
|
5
|
+
/** Set to `false` for server-only entries. */
|
|
6
|
+
client?: boolean;
|
|
7
|
+
/** Set to `false` for client-only entries. */
|
|
8
|
+
server?: boolean;
|
|
9
|
+
};
|
|
10
|
+
/** Subset of the user `quasar.config` result used by Histoire. */
|
|
11
|
+
export interface RawQuasarConfig {
|
|
12
|
+
/** Boot files, run in order. */
|
|
13
|
+
boot?: QuasarAssetEntry[];
|
|
14
|
+
/** Global stylesheets. */
|
|
15
|
+
css?: QuasarAssetEntry[];
|
|
16
|
+
/** `@quasar/extras` assets (fonts, icon sets). */
|
|
17
|
+
extras?: string[];
|
|
18
|
+
/** `@quasar/extras/animate` animations, or `'all'`. */
|
|
19
|
+
animations?: string[] | 'all';
|
|
20
|
+
/** Quasar framework options. */
|
|
21
|
+
framework?: {
|
|
22
|
+
/** Quasar config (brand colors, plugin defaults...). */
|
|
23
|
+
config?: Record<string, unknown>;
|
|
24
|
+
/** Components to register (when not auto-imported). */
|
|
25
|
+
components?: string[];
|
|
26
|
+
/** Directives to register. */
|
|
27
|
+
directives?: string[];
|
|
28
|
+
/** Quasar plugins (Notify, Dialog...). */
|
|
29
|
+
plugins?: string[];
|
|
30
|
+
/** Language pack name or path. */
|
|
31
|
+
lang?: string;
|
|
32
|
+
/** Icon set name or path. */
|
|
33
|
+
iconSet?: string;
|
|
34
|
+
/** Import the flex CSS addon. */
|
|
35
|
+
cssAddon?: boolean;
|
|
36
|
+
};
|
|
37
|
+
/** Overridden source file locations. */
|
|
38
|
+
sourceFiles?: {
|
|
39
|
+
/** Store factory path, without or with extension. */
|
|
40
|
+
store?: string;
|
|
41
|
+
/** Router factory path, without or with extension. */
|
|
42
|
+
router?: string;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/** Quasar framework options passed to `app.use(Quasar, ...)`. */
|
|
46
|
+
export interface ResolvedQuasarFramework {
|
|
47
|
+
/** Quasar config, serialized into the generated options. */
|
|
48
|
+
config: Record<string, unknown>;
|
|
49
|
+
/** Component names imported from `quasar`. */
|
|
50
|
+
components: string[];
|
|
51
|
+
/** Directive names imported from `quasar`. */
|
|
52
|
+
directives: string[];
|
|
53
|
+
/** Plugin names imported from `quasar`. */
|
|
54
|
+
plugins: string[];
|
|
55
|
+
/** Import path of the language pack. */
|
|
56
|
+
lang?: string;
|
|
57
|
+
/** Import path of the icon set. */
|
|
58
|
+
iconSet?: string;
|
|
59
|
+
}
|
|
60
|
+
/** `quasar.config` resolved to what the story app setup needs. */
|
|
61
|
+
export interface ResolvedQuasarConfig {
|
|
62
|
+
/** Client boot file import paths, in order. */
|
|
63
|
+
boot: string[];
|
|
64
|
+
/** Client stylesheet import paths, in order. */
|
|
65
|
+
css: string[];
|
|
66
|
+
/** `@quasar/extras` asset names. */
|
|
67
|
+
extras: string[];
|
|
68
|
+
/** `@quasar/extras/animate` animation names. */
|
|
69
|
+
animations: string[];
|
|
70
|
+
/** Import the flex CSS addon. */
|
|
71
|
+
cssAddon: boolean;
|
|
72
|
+
/** `sass` when the project customizes Quasar Sass variables. */
|
|
73
|
+
quasarSrcExt: 'css' | 'sass';
|
|
74
|
+
/** Options for `app.use(Quasar)`. */
|
|
75
|
+
framework: ResolvedQuasarFramework;
|
|
76
|
+
/** Absolute POSIX path of the store (Pinia) factory, if the project has one. */
|
|
77
|
+
storeFile?: string;
|
|
78
|
+
/** Project uses Vue Router; boot files then receive a router. */
|
|
79
|
+
hasRouter: boolean;
|
|
80
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Unique values, keeping first occurrence order. */
|
|
2
|
+
export declare function unique<T>(list: T[]): T[];
|
|
3
|
+
/** `framework.config` keys whose `spinner` may name a Quasar component. */
|
|
4
|
+
declare const spinnerConfigKeys: readonly ['loading', 'notify'];
|
|
5
|
+
/** Quasar component spinner names set in `framework.config`. */
|
|
6
|
+
export declare function getConfigSpinners(config: Record<string, any>): Array<{
|
|
7
|
+
key: typeof spinnerConfigKeys[number];
|
|
8
|
+
spinner: string;
|
|
9
|
+
}>;
|
|
10
|
+
/** `require` resolving packages from the Quasar project, like Quasar CLI does. */
|
|
11
|
+
export declare function projectRequire(root: string): NodeJS.Require;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
/** Unique values, keeping first occurrence order. */
|
|
4
|
+
export function unique(list) {
|
|
5
|
+
return [...new Set(list)];
|
|
6
|
+
}
|
|
7
|
+
/** Quasar components named in `framework.config` (e.g. a spinner) must be imported. */
|
|
8
|
+
const quasarComponentRE = /^Q[A-Z]/;
|
|
9
|
+
/** `framework.config` keys whose `spinner` may name a Quasar component. */
|
|
10
|
+
const spinnerConfigKeys = ['loading', 'notify'];
|
|
11
|
+
/** Quasar component spinner names set in `framework.config`. */
|
|
12
|
+
export function getConfigSpinners(config) {
|
|
13
|
+
return spinnerConfigKeys
|
|
14
|
+
.map(key => ({ key, spinner: config[key]?.spinner }))
|
|
15
|
+
.filter(({ spinner }) => typeof spinner === 'string' && quasarComponentRE.test(spinner));
|
|
16
|
+
}
|
|
17
|
+
/** `require` resolving packages from the Quasar project, like Quasar CLI does. */
|
|
18
|
+
export function projectRequire(root) {
|
|
19
|
+
return createRequire(join(root, 'package.json'));
|
|
20
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { UserConfig } from 'vite';
|
|
2
|
+
/**
|
|
3
|
+
* Keep the parts of Quasar CLI's resolved Vite config that compile the app
|
|
4
|
+
* (plugins, aliases, defines, CSS), and drop root/server/output/cache settings
|
|
5
|
+
* Histoire owns.
|
|
6
|
+
*/
|
|
7
|
+
export declare function toHistoireViteConfig(viteConfig: UserConfig): UserConfig;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/** Quasar CLI plugins that only make sense for its own dev server or build. */
|
|
2
|
+
const ignoredPlugins = [
|
|
3
|
+
'quasar:html',
|
|
4
|
+
'quasar:strip-filename-hashes',
|
|
5
|
+
// Type checking/linting belongs to the app's own dev server and CI.
|
|
6
|
+
'vite-plugin-checker',
|
|
7
|
+
];
|
|
8
|
+
/** Plugin name, for any (possibly falsy) plugin option. */
|
|
9
|
+
function pluginName(plugin) {
|
|
10
|
+
return plugin && typeof plugin === 'object' && 'name' in plugin ? plugin.name : undefined;
|
|
11
|
+
}
|
|
12
|
+
/** Flatten nested plugin arrays, dropping falsy entries and CLI-only plugins. */
|
|
13
|
+
function filterPlugins(plugins = []) {
|
|
14
|
+
return plugins.flat(Infinity).filter((plugin) => {
|
|
15
|
+
const name = pluginName(plugin);
|
|
16
|
+
return plugin && !ignoredPlugins.includes(name) && !/devtools|inspect/.test(name ?? '');
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Keep the parts of Quasar CLI's resolved Vite config that compile the app
|
|
21
|
+
* (plugins, aliases, defines, CSS), and drop root/server/output/cache settings
|
|
22
|
+
* Histoire owns.
|
|
23
|
+
*/
|
|
24
|
+
export function toHistoireViteConfig(viteConfig) {
|
|
25
|
+
const { optimizeDeps, build } = viteConfig;
|
|
26
|
+
// `entries` points to Quasar's index.html; Histoire scans its own entries.
|
|
27
|
+
const { entries: _entries, ...histoireOptimizeDeps } = optimizeDeps ?? {};
|
|
28
|
+
return {
|
|
29
|
+
publicDir: viteConfig.publicDir,
|
|
30
|
+
define: viteConfig.define,
|
|
31
|
+
resolve: viteConfig.resolve,
|
|
32
|
+
css: viteConfig.css,
|
|
33
|
+
// Vue JSX runtime selection, when the project enables JSX.
|
|
34
|
+
...'oxc' in viteConfig ? { oxc: viteConfig.oxc } : {},
|
|
35
|
+
build: { target: build?.target },
|
|
36
|
+
optimizeDeps: histoireOptimizeDeps,
|
|
37
|
+
plugins: filterPlugins(viteConfig.plugins),
|
|
38
|
+
};
|
|
39
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { resolveQuasarProject } from './config/resolve.js';
|
|
2
|
+
import { generateSetupCode } from './config/setup-code.js';
|
|
3
|
+
import { toHistoireViteConfig } from './config/vite.js';
|
|
4
|
+
/** Integrates a Quasar CLI (Vite) project: config, styles, plugins, boot files and App Extensions. */
|
|
5
|
+
export function HstQuasar() {
|
|
6
|
+
return {
|
|
7
|
+
name: '@histoire/plugin-quasar',
|
|
8
|
+
metadata: { displayName: 'Quasar', icon: 'logo-quasar', description: 'Quasar CLI integration', docsUrl: 'https://histoire.dev/guide/plugins/official.html', repoUrl: 'https://github.com/histoire-dev/histoire/tree/main/packages/histoire-plugin-quasar' },
|
|
9
|
+
/** Quasar project Vite config, setup code and collection inline deps. */
|
|
10
|
+
async defaultConfig(_config, mode, context) {
|
|
11
|
+
const { viteConfig, config } = await resolveQuasarProject(context?.root ?? process.cwd(), mode !== 'build');
|
|
12
|
+
const vite = toHistoireViteConfig(viteConfig);
|
|
13
|
+
return {
|
|
14
|
+
vite: {
|
|
15
|
+
...vite,
|
|
16
|
+
optimizeDeps: {
|
|
17
|
+
...vite.optimizeDeps,
|
|
18
|
+
// Runtime imported by generated setup code: serve it as is, like other Histoire plugins.
|
|
19
|
+
exclude: [...vite.optimizeDeps?.exclude ?? [], '@histoire/plugin-quasar'],
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
setupCode: [generateSetupCode(config)],
|
|
23
|
+
// `quasar` itself is inlined by @histoire/plugin-vue; extras ship CSS.
|
|
24
|
+
viteNodeInlineDeps: [/[/\\]node_modules[/\\]@quasar[/\\]extras[/\\]/],
|
|
25
|
+
};
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { Vue3StorySetupApi } from '@histoire/plugin-vue';
|
|
2
|
+
import type { App } from 'vue';
|
|
3
|
+
/** Parameters Quasar CLI passes to boot files (client side, SPA). */
|
|
4
|
+
export interface QuasarBootParams {
|
|
5
|
+
/** Story Vue app. */
|
|
6
|
+
app: App;
|
|
7
|
+
/** Router with memory history, never installed on the app. */
|
|
8
|
+
router: unknown;
|
|
9
|
+
/** Project store, if any. */
|
|
10
|
+
store: unknown;
|
|
11
|
+
/** Always `null`: stories render client side. */
|
|
12
|
+
ssrContext: null;
|
|
13
|
+
/** Router-facing URL. */
|
|
14
|
+
urlPath: string;
|
|
15
|
+
/** Public base path. */
|
|
16
|
+
publicPath: string;
|
|
17
|
+
/** Stops running the remaining boot files; never navigates. */
|
|
18
|
+
redirect: (url: unknown) => void;
|
|
19
|
+
}
|
|
20
|
+
/** Lazily imported client boot file. */
|
|
21
|
+
export interface QuasarBootFile {
|
|
22
|
+
/** Import path, for error messages. */
|
|
23
|
+
path: string;
|
|
24
|
+
/** Dynamic import of the boot module. */
|
|
25
|
+
load: () => Promise<{
|
|
26
|
+
default?: unknown;
|
|
27
|
+
}>;
|
|
28
|
+
}
|
|
29
|
+
/** Values generated from `quasar.config` by the Histoire plugin. */
|
|
30
|
+
export interface QuasarAppSetupOptions {
|
|
31
|
+
/** Quasar Vue plugin. */
|
|
32
|
+
Quasar: any;
|
|
33
|
+
/** Quasar Dark plugin, synced with Histoire's dark mode. */
|
|
34
|
+
Dark: {
|
|
35
|
+
set: (value: boolean | 'auto') => void;
|
|
36
|
+
};
|
|
37
|
+
/** Options for `app.use(Quasar, options)`. */
|
|
38
|
+
options: Record<string, unknown>;
|
|
39
|
+
/** Store factory or instance from `src/stores/index`. */
|
|
40
|
+
createStore?: unknown;
|
|
41
|
+
/** Router factory for boot files; never installed on the story app. */
|
|
42
|
+
createRouter?: () => unknown;
|
|
43
|
+
/** Client boot files, in order. */
|
|
44
|
+
bootFiles: QuasarBootFile[];
|
|
45
|
+
}
|
|
46
|
+
/** Part of the `@histoire/plugin-vue` setup API used here. */
|
|
47
|
+
type SetupApi = Pick<Vue3StorySetupApi, 'app' | 'onDarkChange'>;
|
|
48
|
+
/** Install Quasar, the project store and client boot files on one story app. */
|
|
49
|
+
export declare function setupQuasarApp(setupApi: SetupApi, setup: QuasarAppSetupOptions): Promise<void>;
|
|
50
|
+
export {};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/** Create the project store like Quasar CLI's app entry, exposing the router to Pinia stores. */
|
|
2
|
+
async function createProjectStore(app, createStore, router) {
|
|
3
|
+
const store = typeof createStore === 'function'
|
|
4
|
+
? await createStore({ ssrContext: null })
|
|
5
|
+
: createStore;
|
|
6
|
+
app.use(store);
|
|
7
|
+
// Quasar CLI makes `this.router` available in Pinia stores.
|
|
8
|
+
if (router && typeof store?.use === 'function') {
|
|
9
|
+
store.use(({ store: instance }) => {
|
|
10
|
+
instance.router = router;
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
return store;
|
|
14
|
+
}
|
|
15
|
+
/** Run client boot files in order; a redirect stops the chain like in Quasar CLI. */
|
|
16
|
+
async function runBootFiles(bootFiles, params) {
|
|
17
|
+
let redirected = false;
|
|
18
|
+
const bootParams = {
|
|
19
|
+
...params,
|
|
20
|
+
// Stories never navigate away from the sandbox.
|
|
21
|
+
redirect: () => {
|
|
22
|
+
redirected = true;
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
for (const bootFile of bootFiles) {
|
|
26
|
+
if (redirected)
|
|
27
|
+
return;
|
|
28
|
+
try {
|
|
29
|
+
const { default: boot } = await bootFile.load();
|
|
30
|
+
if (typeof boot === 'function')
|
|
31
|
+
await boot(bootParams);
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
throw new Error(`Quasar boot file "${bootFile.path}" failed: ${error?.message ?? error}`, { cause: error });
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/** Install Quasar, the project store and client boot files on one story app. */
|
|
39
|
+
export async function setupQuasarApp(setupApi, setup) {
|
|
40
|
+
// Peer dependency mismatches only warn; fail before touching the app.
|
|
41
|
+
if (typeof setupApi.onDarkChange !== 'function') {
|
|
42
|
+
throw new TypeError('@histoire/plugin-quasar needs onDarkChange from @histoire/plugin-vue. Update @histoire/plugin-vue to the same version as @histoire/plugin-quasar.');
|
|
43
|
+
}
|
|
44
|
+
const { app } = setupApi;
|
|
45
|
+
app.use(setup.Quasar, setup.options);
|
|
46
|
+
const router = setup.createRouter?.();
|
|
47
|
+
const store = setup.createStore ? await createProjectStore(app, setup.createStore, router) : undefined;
|
|
48
|
+
await runBootFiles(setup.bootFiles, {
|
|
49
|
+
app,
|
|
50
|
+
router,
|
|
51
|
+
store,
|
|
52
|
+
ssrContext: null,
|
|
53
|
+
urlPath: '/',
|
|
54
|
+
publicPath: import.meta.env?.BASE_URL ?? '/',
|
|
55
|
+
});
|
|
56
|
+
setupApi.onDarkChange(dark => setup.Dark.set(dark));
|
|
57
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,88 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@histoire/plugin-quasar",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "1.0.0-beta.2",
|
|
5
|
+
"description": "Histoire plugin to integrate with Quasar CLI (Vite) projects",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "Guillaume Chau"
|
|
8
|
+
},
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"repository": {
|
|
11
|
+
"url": "https://github.com/Akryum/histoire.git",
|
|
12
|
+
"type": "git",
|
|
13
|
+
"directory": "packages/histoire-plugin-quasar"
|
|
14
|
+
},
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"histoire-plugin"
|
|
20
|
+
],
|
|
21
|
+
"exports": {
|
|
22
|
+
".": "./dist/index.js",
|
|
23
|
+
"./runtime": "./dist/runtime/setup.js"
|
|
24
|
+
},
|
|
25
|
+
"main": "./dist/index.js",
|
|
26
|
+
"module": "./dist/index.js",
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"files": [
|
|
29
|
+
"dist"
|
|
30
|
+
],
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"@quasar/app-vite": "^3.0.0",
|
|
33
|
+
"quasar": "^2.16.0",
|
|
34
|
+
"vite": "^7.0.0 || ^8.0.0",
|
|
35
|
+
"@histoire/plugin-vue": "^1.0.0-beta.2",
|
|
36
|
+
"histoire": "^1.0.0-beta.2"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@quasar/app-vite": "^3.10.3",
|
|
40
|
+
"@types/node": "^22.10.1",
|
|
41
|
+
"@typescript/native": "npm:typescript@7.0.2",
|
|
42
|
+
"quasar": "^2.24.0",
|
|
43
|
+
"typescript": "npm:@typescript/typescript6@6.0.2",
|
|
44
|
+
"vite": "^8.3.5",
|
|
45
|
+
"vitest": "5.1.1",
|
|
46
|
+
"vue": "^3.5.26",
|
|
47
|
+
"@histoire/plugin-vue": "1.0.0-beta.2",
|
|
48
|
+
"histoire": "1.0.0-beta.2"
|
|
49
|
+
},
|
|
50
|
+
"histoire": {
|
|
51
|
+
"marketplace": {
|
|
52
|
+
"displayName": "Quasar",
|
|
53
|
+
"summary": "Load Quasar CLI configuration, styles, store and client boot files.",
|
|
54
|
+
"category": "frameworks",
|
|
55
|
+
"frameworks": [
|
|
56
|
+
"vue"
|
|
57
|
+
],
|
|
58
|
+
"monogram": "Qu",
|
|
59
|
+
"tint": "blue",
|
|
60
|
+
"adds": [],
|
|
61
|
+
"access": [
|
|
62
|
+
"filesystem"
|
|
63
|
+
],
|
|
64
|
+
"config": {
|
|
65
|
+
"import": "HstQuasar",
|
|
66
|
+
"options": []
|
|
67
|
+
},
|
|
68
|
+
"recommend": [
|
|
69
|
+
{
|
|
70
|
+
"dependency": "@quasar/app-vite",
|
|
71
|
+
"reason": "Quasar CLI detected"
|
|
72
|
+
}
|
|
73
|
+
],
|
|
74
|
+
"requires": {
|
|
75
|
+
"histoire": "^1.0.0-beta.1",
|
|
76
|
+
"@quasar/app-vite": "^3.0.0",
|
|
77
|
+
"quasar": "^2.16.0",
|
|
78
|
+
"vite": "^7.0.0 || ^8.0.0"
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
"scripts": {
|
|
83
|
+
"build": "rimraf dist && tsc -d -p tsconfig.build.json",
|
|
84
|
+
"watch": "tsc -d -w --sourceMap -p tsconfig.build.json",
|
|
85
|
+
"test": "vitest run",
|
|
86
|
+
"test:dev": "vitest"
|
|
87
|
+
}
|
|
6
88
|
}
|