@andersundsehr/storybook-typo3 0.1.17 → 0.1.19
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.
@@ -0,0 +1,55 @@
|
|
1
|
+
import { glob } from 'node:fs/promises';
|
2
|
+
import { basename } from 'node:path';
|
3
|
+
async function isFeatureEnabled(name, options) {
|
4
|
+
const envs = await options.presets.apply('env');
|
5
|
+
return ['true', '1'].includes(envs[name] || process.env[name] || '0');
|
6
|
+
}
|
7
|
+
export async function viteFinal(config, options) {
|
8
|
+
if (await isFeatureEnabled('STORYBOOK_TYPO3_WATCH_ONLY_STORIES', options)) {
|
9
|
+
config = await watchOnlyStoriesConfig(config, options);
|
10
|
+
}
|
11
|
+
config = addAllowedHosts(config);
|
12
|
+
return config;
|
13
|
+
}
|
14
|
+
async function watchOnlyStoriesConfig(config, options) {
|
15
|
+
const colorYellow = '\x1b[33m';
|
16
|
+
const colorReset = '\x1b[0m';
|
17
|
+
console.log(colorYellow + '@andersundsehr/storybook-typo3:' + colorReset + ' STORYBOOK_TYPO3_WATCH_ONLY_STORIES enabled, only watching stories files');
|
18
|
+
const defaultGlobPattern = '/**/*.@(mdx|stories.@(mdx|js|jsx|mjs|ts|tsx))';
|
19
|
+
const storiesGlob = await options.presets.apply('stories');
|
20
|
+
const storiesFiles = [];
|
21
|
+
for (let globs of storiesGlob) {
|
22
|
+
if (typeof globs !== 'string') {
|
23
|
+
globs = globs.directory + (globs.files || defaultGlobPattern);
|
24
|
+
}
|
25
|
+
for await (const entry of glob(globs)) {
|
26
|
+
storiesFiles.push(entry);
|
27
|
+
}
|
28
|
+
}
|
29
|
+
const alwaysWatch = ['.env'];
|
30
|
+
config.server = config.server || {};
|
31
|
+
config.server.watch = config.server.watch || {};
|
32
|
+
config.server.watch.ignored = (file) => {
|
33
|
+
const filename = basename(file);
|
34
|
+
if (alwaysWatch.includes(filename)) {
|
35
|
+
return false; // always watch these files
|
36
|
+
}
|
37
|
+
if (!filename.includes('.')) {
|
38
|
+
return false; // ignore directories
|
39
|
+
}
|
40
|
+
if (!storiesFiles.includes(file)) {
|
41
|
+
return true;
|
42
|
+
}
|
43
|
+
return false;
|
44
|
+
};
|
45
|
+
return config;
|
46
|
+
}
|
47
|
+
function addAllowedHosts(config) {
|
48
|
+
var _a;
|
49
|
+
config.server = config.server || {};
|
50
|
+
if (process.env.IS_DDEV_PROJECT && config.server.allowedHosts !== true) {
|
51
|
+
(_a = config.server).allowedHosts ?? (_a.allowedHosts = []);
|
52
|
+
config.server.allowedHosts.push('.ddev.site');
|
53
|
+
}
|
54
|
+
return config;
|
55
|
+
}
|
package/dist/preset.d.ts
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
import type { PresetProperty } from 'storybook/internal/types';
|
2
|
-
import
|
2
|
+
import { viteFinal } from './functions/viteFinal.ts';
|
3
3
|
export declare const addons: string[];
|
4
4
|
/**
|
5
5
|
* We want storybook to not use your local vite config.
|
6
6
|
* As that is not really needed, and can cause issues or break storybook.
|
7
7
|
*/
|
8
|
-
export
|
8
|
+
export { viteFinal };
|
9
9
|
export declare const core: PresetProperty<'core'>;
|
10
10
|
export declare const previewAnnotations: PresetProperty<'previewAnnotations'>;
|
11
11
|
export declare const tags: string[];
|
package/dist/preset.js
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
import { dirname, join } from 'node:path';
|
2
2
|
import { createRequire } from 'module';
|
3
|
-
import {
|
4
|
-
import { basename } from 'node:path';
|
3
|
+
import { viteFinal } from "./functions/viteFinal.js";
|
5
4
|
const require = createRequire(import.meta.url);
|
6
5
|
function getAbsolutePath(value) {
|
7
6
|
return dirname(require.resolve(join(value, 'package.json')));
|
@@ -11,46 +10,15 @@ export const addons = ['@storybook/addon-docs', '@storybook/addon-a11y'];
|
|
11
10
|
* We want storybook to not use your local vite config.
|
12
11
|
* As that is not really needed, and can cause issues or break storybook.
|
13
12
|
*/
|
14
|
-
export
|
15
|
-
const envs = await options.presets.apply('env');
|
16
|
-
const watchOnlyStoriesActive = ['true', '1'].includes(envs.STORYBOOK_TYPO3_WATCH_ONLY_STORIES);
|
17
|
-
if (!watchOnlyStoriesActive) {
|
18
|
-
return config; // do not change anything if we are not in watch only mode
|
19
|
-
}
|
20
|
-
const colorYellow = '\x1b[33m';
|
21
|
-
const colorReset = '\x1b[0m';
|
22
|
-
console.log(colorYellow + '@andersundsehr/storybook-typo3:' + colorReset + ' STORYBOOK_TYPO3_WATCH_ONLY_STORIES enabled, only watching stories files');
|
23
|
-
const defaultGlobPattern = '/**/*.@(mdx|stories.@(mdx|js|jsx|mjs|ts|tsx))';
|
24
|
-
const storiesGlob = await options.presets.apply('stories');
|
25
|
-
const storiesFiles = [];
|
26
|
-
for (let globs of storiesGlob) {
|
27
|
-
if (typeof globs !== 'string') {
|
28
|
-
globs = globs.directory + (globs.files || defaultGlobPattern);
|
29
|
-
}
|
30
|
-
for await (const entry of glob(globs)) {
|
31
|
-
storiesFiles.push(entry);
|
32
|
-
}
|
33
|
-
}
|
34
|
-
const alwaysWatch = ['.env'];
|
35
|
-
config.server = config.server || {};
|
36
|
-
config.server.watch = config.server.watch || {};
|
37
|
-
config.server.watch.ignored = (file) => {
|
38
|
-
const filename = basename(file);
|
39
|
-
if (alwaysWatch.includes(filename)) {
|
40
|
-
return false; // always watch these files
|
41
|
-
}
|
42
|
-
if (!filename.includes('.')) {
|
43
|
-
return false; // ignore directories
|
44
|
-
}
|
45
|
-
if (!storiesFiles.includes(file)) {
|
46
|
-
return true;
|
47
|
-
}
|
48
|
-
return false;
|
49
|
-
};
|
50
|
-
return config;
|
51
|
-
};
|
13
|
+
export { viteFinal };
|
52
14
|
export const core = {
|
53
|
-
builder:
|
15
|
+
builder: {
|
16
|
+
name: '@storybook/builder-vite',
|
17
|
+
options: {
|
18
|
+
// to overwrite the user's vite.config.js
|
19
|
+
viteConfigPath: require.resolve('./empty-vite.config'),
|
20
|
+
},
|
21
|
+
},
|
54
22
|
renderer: getAbsolutePath('@storybook/server'),
|
55
23
|
disableTelemetry: true,
|
56
24
|
};
|
package/package.json
CHANGED