histoire 0.17.2 → 0.17.4

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/dist/node/bin.js CHANGED
@@ -11,6 +11,7 @@ program.version(version);
11
11
  program.command('dev')
12
12
  .describe('open the stories in your browser for development')
13
13
  .option('-p, --port <port>', 'Listening port of the server')
14
+ .option('-c, --config <file>', `[string] use specified config file`)
14
15
  .option('--open', 'Open in your default browser')
15
16
  .action(async (options) => {
16
17
  const { devCommand } = await import('./commands/dev.js');
@@ -18,9 +19,10 @@ program.command('dev')
18
19
  });
19
20
  program.command('build')
20
21
  .describe('build the histoire final app you can deploy')
21
- .action(async () => {
22
+ .option('-c, --config <file>', `[string] use specified config file`)
23
+ .action(async (options) => {
22
24
  const { buildCommand } = await import('./commands/build.js');
23
- return buildCommand();
25
+ return buildCommand(options);
24
26
  });
25
27
  program.command('preview')
26
28
  .describe('preview the built directory')
@@ -1 +1,4 @@
1
- export declare function buildCommand(): Promise<void>;
1
+ export interface BuildOptions {
2
+ config?: string;
3
+ }
4
+ export declare function buildCommand(options: BuildOptions): Promise<void>;
@@ -1,7 +1,8 @@
1
1
  import { build } from '../build.js';
2
2
  import { createContext } from '../context.js';
3
- export async function buildCommand() {
3
+ export async function buildCommand(options) {
4
4
  const ctx = await createContext({
5
+ configFile: options.config,
5
6
  mode: 'build',
6
7
  });
7
8
  await build(ctx);
@@ -1,5 +1,6 @@
1
1
  export interface DevOptions {
2
2
  port: number;
3
3
  open?: boolean;
4
+ config?: string;
4
5
  }
5
6
  export declare function devCommand(options: DevOptions): Promise<void>;
@@ -7,6 +7,7 @@ export async function devCommand(options) {
7
7
  let stop;
8
8
  async function start() {
9
9
  const ctx = await createContext({
10
+ configFile: options.config,
10
11
  mode: 'dev',
11
12
  });
12
13
  const { server, viteConfigFile, close } = await createServer(ctx, {
@@ -38,7 +39,7 @@ export async function devCommand(options) {
38
39
  }
39
40
  }
40
41
  stop = await start();
41
- const configFile = await resolveConfigFile();
42
+ const configFile = await resolveConfigFile(undefined, options.config);
42
43
  if (configFile) {
43
44
  const watcher = chokidar.watch(configFile, {
44
45
  ignoreInitial: true,
@@ -2,7 +2,7 @@ import type { HistoireConfig, ConfigMode } from '@histoire/shared';
2
2
  import type { Context } from './context.js';
3
3
  export declare function getDefaultConfig(): HistoireConfig;
4
4
  export declare const configFileNames: string[];
5
- export declare function resolveConfigFile(cwd?: string): string;
5
+ export declare function resolveConfigFile(cwd?: string, configFile?: string): string;
6
6
  export declare function loadConfigFile(configFile: string): Promise<Partial<HistoireConfig>>;
7
7
  export declare const mergeBuildConfig: <Source extends {
8
8
  [x: string]: any;
@@ -22,7 +22,7 @@ export declare const mergeConfig: <Source extends {
22
22
  [x: number]: any;
23
23
  [x: symbol]: any;
24
24
  } | (number | boolean | any[] | Record<never, any>))[]>(source: Source, ...defaults: Defaults) => import("defu").Defu<Source, Defaults>;
25
- export declare function resolveConfig(cwd: string, mode: ConfigMode): Promise<HistoireConfig>;
25
+ export declare function resolveConfig(cwd: string, mode: ConfigMode, configFile: string): Promise<HistoireConfig>;
26
26
  export declare function processConfig(ctx: Context): Promise<void>;
27
27
  export declare function defineConfig(config: Partial<HistoireConfig>): Partial<HistoireConfig>;
28
28
  declare module 'vite' {
@@ -139,8 +139,14 @@ export const configFileNames = [
139
139
  '.histoire.ts',
140
140
  '.histoire.js',
141
141
  ];
142
- export function resolveConfigFile(cwd = process.cwd()) {
143
- return findUp(cwd, configFileNames);
142
+ export function resolveConfigFile(cwd = process.cwd(), configFile) {
143
+ if (configFile) {
144
+ // explicit config path is always resolved from cwd
145
+ return path.resolve(configFile);
146
+ }
147
+ else {
148
+ return findUp(cwd, configFileNames);
149
+ }
144
150
  }
145
151
  export async function loadConfigFile(configFile) {
146
152
  try {
@@ -219,11 +225,11 @@ export const mergeConfig = createDefu((obj, key, value) => {
219
225
  return true;
220
226
  }
221
227
  });
222
- export async function resolveConfig(cwd = process.cwd(), mode) {
228
+ export async function resolveConfig(cwd = process.cwd(), mode, configFile) {
223
229
  let result;
224
- const configFile = resolveConfigFile(cwd);
225
- if (configFile) {
226
- result = await loadConfigFile(configFile);
230
+ const resolvedConfigFile = resolveConfigFile(cwd, configFile);
231
+ if (resolvedConfigFile) {
232
+ result = await loadConfigFile(resolvedConfigFile);
227
233
  }
228
234
  const viteConfig = await resolveViteConfig({}, 'serve');
229
235
  const viteHistoireConfig = (viteConfig.histoire ?? {});
@@ -12,5 +12,6 @@ export interface Context {
12
12
  }
13
13
  export interface CreateContextOptions {
14
14
  mode: Context['mode'];
15
+ configFile?: string;
15
16
  }
16
17
  export declare function createContext(options: CreateContextOptions): Promise<Context>;
@@ -2,7 +2,7 @@ import { resolveConfig as resolveViteConfig } from 'vite';
2
2
  import { processConfig, resolveConfig } from './config.js';
3
3
  import { mergeHistoireViteConfig } from './vite.js';
4
4
  export async function createContext(options) {
5
- const config = await resolveConfig(process.cwd(), options.mode);
5
+ const config = await resolveConfig(process.cwd(), options.mode, options.configFile);
6
6
  const command = options.mode === 'dev' ? 'serve' : 'build';
7
7
  const viteConfig = await resolveViteConfig({}, command);
8
8
  const supportPlugins = config.plugins.map(p => p.supportPlugin).filter(Boolean);
@@ -1,5 +1,5 @@
1
- /// <reference types="node" />
2
1
  import chokidar from 'chokidar';
2
+ import path from 'pathe';
3
3
  import fs from 'fs-extra';
4
4
  import type { Plugin, PluginApiBase, PluginApiDev, PluginApiBuild, ChangeViteConfigCallback, BuildEndCallback, PreviewStoryCallback, ModuleLoader, ServerStory, PluginApiDevEvent, HistoireConfig } from '@histoire/shared';
5
5
  import type { Context } from './context.js';
@@ -10,7 +10,7 @@ export declare class BasePluginApi implements PluginApiBase {
10
10
  colors: import("picocolors/types.js").Colors & {
11
11
  createColors: (enabled?: boolean) => import("picocolors/types.js").Colors;
12
12
  };
13
- path: Omit<import("path").PlatformPath, "win32" | "posix">;
13
+ path: typeof path;
14
14
  fs: typeof fs;
15
15
  constructor(ctx: Context, plugin: Plugin, moduleLoader: ModuleLoader);
16
16
  get pluginTempDir(): string;
@@ -1,12 +1,8 @@
1
1
  import path from 'pathe';
2
2
  import fs from 'node:fs';
3
3
  export function findUp(cwd = process.cwd(), fileNames) {
4
- let { root } = path.parse(cwd);
4
+ const { root } = path.parse(cwd);
5
5
  let dir = cwd;
6
- // Fix for windows, waiting for pathe to fix this: https://github.com/unjs/pathe/issues/5
7
- if (root === '' && dir[1] === ':') {
8
- root = dir.substring(0, 2);
9
- }
10
6
  while (dir !== root) {
11
7
  for (const fileName of fileNames) {
12
8
  const searchPath = path.join(dir, fileName);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "histoire",
3
- "version": "0.17.2",
3
+ "version": "0.17.4",
4
4
  "description": "A fast story book powered by Vite",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -58,16 +58,16 @@
58
58
  "markdown-it-emoji": "^2.0.2",
59
59
  "micromatch": "^4.0.5",
60
60
  "mrmime": "^1.0.1",
61
- "pathe": "^0.2.0",
61
+ "pathe": "^1.1.1",
62
62
  "picocolors": "^1.0.0",
63
63
  "sade": "^1.8.1",
64
64
  "shiki-es": "^0.2.0",
65
65
  "sirv": "^2.0.3",
66
66
  "vite-node": "^0.34.1",
67
- "@histoire/app": "^0.17.0",
68
- "@histoire/controls": "^0.17.0",
69
- "@histoire/vendors": "^0.17.0",
70
- "@histoire/shared": "^0.17.0"
67
+ "@histoire/controls": "^0.17.4",
68
+ "@histoire/app": "^0.17.4",
69
+ "@histoire/shared": "^0.17.4",
70
+ "@histoire/vendors": "^0.17.4"
71
71
  },
72
72
  "peerDependencies": {
73
73
  "vite": "^2.9.0 || ^3.0.0 || ^4.0.0"
@@ -78,9 +78,9 @@
78
78
  "@types/micromatch": "^4.0.2",
79
79
  "@types/node": "^17.0.45",
80
80
  "esbuild": "^0.18.20",
81
- "rollup": "^3.28.0",
81
+ "rollup": "^3.29.4",
82
82
  "typescript": "^4.9.5",
83
- "vite": "^4.4.9",
83
+ "vite": "^4.5.0",
84
84
  "vitest": "^0.34.1"
85
85
  },
86
86
  "scripts": {
package/src/node/bin.ts CHANGED
@@ -16,6 +16,7 @@ program.version(version)
16
16
  program.command('dev')
17
17
  .describe('open the stories in your browser for development')
18
18
  .option('-p, --port <port>', 'Listening port of the server')
19
+ .option('-c, --config <file>', `[string] use specified config file`)
19
20
  .option('--open', 'Open in your default browser')
20
21
  .action(async (options) => {
21
22
  const { devCommand } = await import('./commands/dev.js')
@@ -24,9 +25,10 @@ program.command('dev')
24
25
 
25
26
  program.command('build')
26
27
  .describe('build the histoire final app you can deploy')
27
- .action(async () => {
28
+ .option('-c, --config <file>', `[string] use specified config file`)
29
+ .action(async (options) => {
28
30
  const { buildCommand } = await import('./commands/build.js')
29
- return buildCommand()
31
+ return buildCommand(options)
30
32
  })
31
33
 
32
34
  program.command('preview')
@@ -1,8 +1,13 @@
1
1
  import { build } from '../build.js'
2
2
  import { createContext } from '../context.js'
3
3
 
4
- export async function buildCommand () {
4
+ export interface BuildOptions {
5
+ config?: string
6
+ }
7
+
8
+ export async function buildCommand (options: BuildOptions) {
5
9
  const ctx = await createContext({
10
+ configFile: options.config,
6
11
  mode: 'build',
7
12
  })
8
13
  await build(ctx)
@@ -7,6 +7,7 @@ import { createServer } from '../server.js'
7
7
  export interface DevOptions {
8
8
  port: number
9
9
  open?: boolean
10
+ config?: string
10
11
  }
11
12
 
12
13
  export async function devCommand (options: DevOptions) {
@@ -14,6 +15,7 @@ export async function devCommand (options: DevOptions) {
14
15
 
15
16
  async function start () {
16
17
  const ctx = await createContext({
18
+ configFile: options.config,
17
19
  mode: 'dev',
18
20
  })
19
21
  const { server, viteConfigFile, close } = await createServer(ctx, {
@@ -50,7 +52,7 @@ export async function devCommand (options: DevOptions) {
50
52
 
51
53
  stop = await start()
52
54
 
53
- const configFile = await resolveConfigFile()
55
+ const configFile = await resolveConfigFile(undefined, options.config)
54
56
  if (configFile) {
55
57
  const watcher = chokidar.watch(configFile, {
56
58
  ignoreInitial: true,
@@ -154,8 +154,13 @@ export const configFileNames = [
154
154
  '.histoire.js',
155
155
  ]
156
156
 
157
- export function resolveConfigFile (cwd: string = process.cwd()): string {
158
- return findUp(cwd, configFileNames)
157
+ export function resolveConfigFile (cwd: string = process.cwd(), configFile?: string): string {
158
+ if (configFile) {
159
+ // explicit config path is always resolved from cwd
160
+ return path.resolve(configFile)
161
+ } else {
162
+ return findUp(cwd, configFileNames)
163
+ }
159
164
  }
160
165
 
161
166
  export async function loadConfigFile (configFile: string): Promise<Partial<HistoireConfig>> {
@@ -244,11 +249,11 @@ export const mergeConfig = createDefu((obj: any, key, value) => {
244
249
  }
245
250
  })
246
251
 
247
- export async function resolveConfig (cwd: string = process.cwd(), mode: ConfigMode): Promise<HistoireConfig> {
252
+ export async function resolveConfig (cwd: string = process.cwd(), mode: ConfigMode, configFile: string): Promise<HistoireConfig> {
248
253
  let result: Partial<HistoireConfig>
249
- const configFile = resolveConfigFile(cwd)
250
- if (configFile) {
251
- result = await loadConfigFile(configFile)
254
+ const resolvedConfigFile = resolveConfigFile(cwd, configFile)
255
+ if (resolvedConfigFile) {
256
+ result = await loadConfigFile(resolvedConfigFile)
252
257
  }
253
258
  const viteConfig = await resolveViteConfig({}, 'serve')
254
259
  const viteHistoireConfig = (viteConfig.histoire ?? {}) as HistoireConfig
@@ -23,10 +23,11 @@ export interface Context {
23
23
 
24
24
  export interface CreateContextOptions {
25
25
  mode: Context['mode']
26
+ configFile?: string
26
27
  }
27
28
 
28
29
  export async function createContext (options: CreateContextOptions): Promise<Context> {
29
- const config = await resolveConfig(process.cwd(), options.mode)
30
+ const config = await resolveConfig(process.cwd(), options.mode, options.configFile)
30
31
  const command = options.mode === 'dev' ? 'serve' : 'build'
31
32
  const viteConfig = await resolveViteConfig({}, command)
32
33
 
@@ -2,14 +2,9 @@ import path from 'pathe'
2
2
  import fs from 'node:fs'
3
3
 
4
4
  export function findUp (cwd: string = process.cwd(), fileNames: string[]): string {
5
- let { root } = path.parse(cwd)
5
+ const { root } = path.parse(cwd)
6
6
  let dir = cwd
7
7
 
8
- // Fix for windows, waiting for pathe to fix this: https://github.com/unjs/pathe/issues/5
9
- if (root === '' && dir[1] === ':') {
10
- root = dir.substring(0, 2)
11
- }
12
-
13
8
  while (dir !== root) {
14
9
  for (const fileName of fileNames) {
15
10
  const searchPath = path.join(dir, fileName)