@vylos/cli 0.4.0 → 0.4.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vylos/cli",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/DevOpsBenjamin/Vylos"
@@ -17,7 +17,7 @@
17
17
  "tailwindcss": "^4.0.0",
18
18
  "@tailwindcss/vite": "^4.0.0",
19
19
  "tsx": "^4.19.2",
20
- "@vylos/core": "0.4.0"
20
+ "@vylos/core": "0.4.2"
21
21
  },
22
22
  "devDependencies": {
23
23
  "typescript": "^5.7.2"
@@ -5,12 +5,17 @@ import { viteSingleFile } from 'vite-plugin-singlefile';
5
5
  import { resolve } from 'path';
6
6
  import { vylosProjectPlugin } from '../vite/projectPlugin';
7
7
  import { vylosI18nPlugin } from '../vite/i18nPlugin';
8
+ import { resolveGameAlias } from '../utils/resolveGameAlias';
8
9
 
9
10
  export async function build(projectRoot: string, base?: string) {
10
11
  console.log(`\n Vylos building...\n Project: ${projectRoot}\n`);
11
12
 
12
13
  const outDir = resolve(projectRoot, 'dist');
13
14
 
15
+ const alias: Record<string, string> = { '@project': projectRoot };
16
+ const gamePlugin = resolveGameAlias(projectRoot);
17
+ if (gamePlugin) alias['@game'] = gamePlugin;
18
+
14
19
  await viteBuild({
15
20
  root: projectRoot,
16
21
  base: base ?? '/',
@@ -22,9 +27,7 @@ export async function build(projectRoot: string, base?: string) {
22
27
  viteSingleFile(),
23
28
  ],
24
29
  resolve: {
25
- alias: {
26
- '@project': projectRoot,
27
- },
30
+ alias,
28
31
  },
29
32
  build: {
30
33
  outDir,
@@ -1,7 +1,9 @@
1
1
  import { resolve, dirname } from 'path';
2
- import { existsSync, mkdirSync, cpSync, readFileSync, writeFileSync } from 'fs';
2
+ import { existsSync, mkdirSync, cpSync, readFileSync, writeFileSync, renameSync } from 'fs';
3
3
  import { fileURLToPath } from 'url';
4
4
 
5
+ const TEMPLATE_PLUGIN_NAME = 'my-vylos-game';
6
+
5
7
  export async function create(name: string, targetDir?: string) {
6
8
  const dest = resolve(targetDir ?? process.cwd(), name);
7
9
 
@@ -24,6 +26,13 @@ export async function create(name: string, targetDir?: string) {
24
26
  mkdirSync(dest, { recursive: true });
25
27
  cpSync(templateDir, dest, { recursive: true });
26
28
 
29
+ // Rename plugins/my-vylos-game → plugins/<name>
30
+ const oldPluginDir = resolve(dest, 'plugins', TEMPLATE_PLUGIN_NAME);
31
+ const newPluginDir = resolve(dest, 'plugins', name);
32
+ if (existsSync(oldPluginDir)) {
33
+ renameSync(oldPluginDir, newPluginDir);
34
+ }
35
+
27
36
  // Replace project name in package.json
28
37
  const pkgPath = resolve(dest, 'package.json');
29
38
  if (existsSync(pkgPath)) {
@@ -31,6 +40,13 @@ export async function create(name: string, targetDir?: string) {
31
40
  writeFileSync(pkgPath, pkg.replace('"my-vylos-game"', `"${name}"`));
32
41
  }
33
42
 
43
+ // Update @game alias in tsconfig.json to point to the renamed plugin
44
+ const tsconfigPath = resolve(dest, 'tsconfig.json');
45
+ if (existsSync(tsconfigPath)) {
46
+ const tsconfig = readFileSync(tsconfigPath, 'utf-8');
47
+ writeFileSync(tsconfigPath, tsconfig.replaceAll(TEMPLATE_PLUGIN_NAME, name));
48
+ }
49
+
34
50
  console.log(` Project created at: ${dest}`);
35
51
  console.log(`\n Next steps:`);
36
52
  console.log(` cd ${name}`);
@@ -5,10 +5,15 @@ import { resolve } from 'path';
5
5
  import { vylosProjectPlugin } from '../vite/projectPlugin';
6
6
  import { vylosI18nPlugin } from '../vite/i18nPlugin';
7
7
  import { vylosEditorApiPlugin } from '../vite/editorApiPlugin';
8
+ import { resolveGameAlias } from '../utils/resolveGameAlias';
8
9
 
9
10
  export async function dev(projectRoot: string) {
10
11
  console.log(`\n Vylos dev server starting...\n Project: ${projectRoot}\n`);
11
12
 
13
+ const alias: Record<string, string> = { '@project': projectRoot };
14
+ const gamePlugin = resolveGameAlias(projectRoot);
15
+ if (gamePlugin) alias['@game'] = gamePlugin;
16
+
12
17
  const server = await createServer({
13
18
  root: projectRoot,
14
19
  plugins: [
@@ -19,9 +24,7 @@ export async function dev(projectRoot: string) {
19
24
  vylosEditorApiPlugin(),
20
25
  ],
21
26
  resolve: {
22
- alias: {
23
- '@project': projectRoot,
24
- },
27
+ alias,
25
28
  dedupe: ['vue', 'pinia'],
26
29
  },
27
30
  optimizeDeps: {
@@ -0,0 +1,17 @@
1
+ import { resolve } from 'path';
2
+ import { existsSync, readdirSync, statSync } from 'fs';
3
+
4
+ /**
5
+ * Scans `plugins/` for the first subdirectory and returns its absolute path.
6
+ * Returns null if no plugins directory or no subdirectory exists.
7
+ */
8
+ export function resolveGameAlias(projectRoot: string): string | null {
9
+ const pluginsDir = resolve(projectRoot, 'plugins');
10
+ if (!existsSync(pluginsDir)) return null;
11
+
12
+ const dirs = readdirSync(pluginsDir).filter(f =>
13
+ statSync(resolve(pluginsDir, f)).isDirectory(),
14
+ );
15
+
16
+ return dirs.length > 0 ? resolve(pluginsDir, dirs[0]) : null;
17
+ }
@@ -1,5 +1,5 @@
1
1
  import type { VylosAction } from '@vylos/core';
2
- import type { GameState } from '../../state';
2
+ import type { GameState } from '@game';
3
3
 
4
4
  const wait: VylosAction<GameState> = {
5
5
  id: 'wait',
@@ -1,6 +1,6 @@
1
1
  import type { VylosEvent, VylosAPI } from '@vylos/core';
2
- import type { GameState } from '../../state';
3
- import { narrator } from '../../characters';
2
+ import type { GameState } from '@game';
3
+ import { narrator } from '@game';
4
4
 
5
5
  const intro: VylosEvent<GameState> = {
6
6
  id: 'intro',
package/templates/main.ts CHANGED
@@ -16,7 +16,7 @@ import {
16
16
  type VylosCharacter,
17
17
  } from '@vylos/core';
18
18
  import config from './vylos.config';
19
- import { useGameStore } from './state';
19
+ import { useGameStore } from '@game';
20
20
 
21
21
  // Locations
22
22
  import home from './locations/home/location';
@@ -2,37 +2,37 @@ import { defineStore } from 'pinia';
2
2
  import { ref } from 'vue';
3
3
  import type { VylosGameState } from '@vylos/core';
4
4
  import { deepMerge } from '@vylos/core';
5
- import { type Player, createDefaultPlayer } from './player';
5
+ import { type Player, createPlayer } from './player';
6
6
 
7
7
  /** Your game state — extends VylosGameState with your own fields */
8
8
  export interface GameState extends VylosGameState {
9
9
  player: Player;
10
10
  }
11
11
 
12
- export function createDefaultState(): GameState {
12
+ export function createState(): GameState {
13
13
  return {
14
14
  locationId: '',
15
15
  gameTime: 8,
16
16
  flags: {},
17
17
  counters: {},
18
- player: createDefaultPlayer(),
18
+ player: createPlayer(),
19
19
  inventories: {},
20
20
  };
21
21
  }
22
22
 
23
23
  export const useGameStore = defineStore('gameState', () => {
24
- const state = ref<GameState>(createDefaultState());
24
+ const state = ref<GameState>(createState());
25
25
 
26
26
  function getState(): GameState {
27
27
  return state.value;
28
28
  }
29
29
 
30
30
  function setState(newState: Partial<GameState>) {
31
- state.value = deepMerge(createDefaultState(), newState) as GameState;
31
+ state.value = deepMerge(createState(), newState) as GameState;
32
32
  }
33
33
 
34
34
  function $reset() {
35
- state.value = createDefaultState();
35
+ state.value = createState();
36
36
  }
37
37
 
38
38
  return { state, getState, setState, $reset };
@@ -0,0 +1,3 @@
1
+ export * from './gameState';
2
+ export * from './characters';
3
+ export * from './player';
@@ -6,7 +6,7 @@ export interface Player extends Character {
6
6
  // gold: number;
7
7
  }
8
8
 
9
- export function createDefaultPlayer(): Player {
9
+ export function createPlayer(): Player {
10
10
  return {
11
11
  id: 'player',
12
12
  name: 'Player',
@@ -13,7 +13,11 @@
13
13
  "jsx": "preserve",
14
14
  "experimentalDecorators": true,
15
15
  "emitDecoratorMetadata": true,
16
- "baseUrl": "."
16
+ "baseUrl": ".",
17
+ "paths": {
18
+ "@game": ["./plugins/my-vylos-game"],
19
+ "@game/*": ["./plugins/my-vylos-game/*"]
20
+ }
17
21
  },
18
22
  "include": ["./**/*.ts", "./**/*.vue", "./env.d.ts"],
19
23
  "exclude": ["node_modules", "dist"]