Skip to content

Commit a609647

Browse files
committed
feat: fix shims structure and path errors
1 parent ce86571 commit a609647

13 files changed

Lines changed: 73 additions & 34 deletions

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@gwack/cli",
3-
"version": "0.2.0",
3+
"version": "0.2.1",
44
"private": false,
55
"description": "PHP Framework with vue intergration",
66
"type": "module",
@@ -48,7 +48,8 @@
4848
"bin",
4949
"src",
5050
"templates",
51-
"dist"
51+
"dist",
52+
"shims"
5253
],
5354
"engines": {
5455
"node": ">=18.0.0"

src/cli/create.js

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
import { mkdir, writeFile, copyFile } from 'fs/promises';
88
import { readFileSync, existsSync } from 'fs';
9-
import { join } from 'path';
9+
import { join, dirname } from 'path';
10+
import { fileURLToPath } from 'url';
1011
import chalk from 'chalk';
1112

1213
/**
@@ -81,8 +82,9 @@ export async function createCommand(name, options) {
8182
// Create basic files
8283
await createBasicFiles(projectPath);
8384

84-
console.log(chalk.green('✅ Project created successfully!'));
85-
console.log(chalk.gray('\n📦 Next steps:'));
85+
console.log(chalk.green('Project created successfully!'));
86+
console.log('\n');
87+
console.log(chalk.gray('\t Next steps:'));
8688
console.log(chalk.gray(` cd ${name}`));
8789
console.log(chalk.gray(' composer install'));
8890
console.log(chalk.gray(' npm install'));
@@ -96,49 +98,75 @@ export async function createCommand(name, options) {
9698
}
9799

98100
async function createBasicFiles(projectPath) {
101+
// Resolve root-level shims directory regardless of running from src or dist
102+
const here = dirname(fileURLToPath(import.meta.url));
103+
// here = .../dist/cli (when built) or .../src/cli (when dev)
104+
// package root is two levels up from dist/cli or src/cli
105+
const pkgRoot = join(here, '..', '..');
106+
const shimsDir = join(pkgRoot, 'shims');
107+
const nmShimsDir = join(process.cwd(), 'node_modules', '@gwack', 'cli', 'shims');
99108
// Create pages/index.vue from shim
100109
let indexPage;
101110
try {
102-
const shimPath = join(import.meta.dirname, '../shims/index-page.vue');
111+
let shimPath = join(shimsDir, 'index-page.vue.tmpl');
103112
if (existsSync(shimPath)) {
104113
indexPage = readFileSync(shimPath, 'utf8');
105114
} else {
106-
throw new Error('Shim not found');
115+
// fallback to node_modules installation path
116+
shimPath = join(nmShimsDir, 'index-page.vue.tmpl');
117+
if (existsSync(shimPath)) {
118+
indexPage = readFileSync(shimPath, 'utf8');
119+
} else {
120+
throw new Error('Shim not found');
121+
}
107122
}
108123
} catch (error) {
109124
console.error('Could not read index page shim');
110125
}
111-
112-
await writeFile(join(projectPath, 'pages/index.vue'), indexPage);
126+
if (typeof indexPage === 'string') {
127+
await writeFile(join(projectPath, 'pages/index.vue'), indexPage);
128+
}
113129

114130
// gwack.config.js
115131
let config;
116132
try {
117-
const shimPath = join(import.meta.dirname, '../shims/gwack.config.js');
133+
let shimPath = join(shimsDir, 'gwack.config.tmpl');
118134
if (existsSync(shimPath)) {
119135
config = readFileSync(shimPath, 'utf8');
120136
} else {
121-
throw new Error('Shim not found');
137+
shimPath = join(nmShimsDir, 'gwack.config.tmpl');
138+
if (existsSync(shimPath)) {
139+
config = readFileSync(shimPath, 'utf8');
140+
} else {
141+
throw new Error('Shim not found');
142+
}
122143
}
123144
} catch (error) {
124145
console.error('Could not read config shim');
125146
}
126-
127-
await writeFile(join(projectPath, 'gwack.config.js'), config);
147+
if (typeof config === 'string') {
148+
await writeFile(join(projectPath, 'gwack.config.js'), config);
149+
}
128150

129151
// index.html
130152
let html;
131153
try {
132-
const shimPath = join(import.meta.dirname, '../shims/index.html');
154+
let shimPath = join(shimsDir, 'index.html.tmpl');
133155
if (existsSync(shimPath)) {
134156
html = readFileSync(shimPath, 'utf8');
135157
} else {
136-
throw new Error('Shim not found');
158+
shimPath = join(nmShimsDir, 'index.html.tmpl');
159+
if (existsSync(shimPath)) {
160+
html = readFileSync(shimPath, 'utf8');
161+
} else {
162+
throw new Error('Shim not found');
163+
}
137164
}
138165
} catch (error) {
139166
console.error('Could not read HTML shim');
140167
return
141168
}
142-
143-
await writeFile(join(projectPath, 'index.html'), html);
169+
if (typeof html === 'string') {
170+
await writeFile(join(projectPath, 'index.html'), html);
171+
}
144172
}

src/config/vite.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ function getDefaultAutoImports() {
1212
return {
1313
imports: [
1414
'vue',
15-
'vue-router',
1615
{
17-
'@gwack/frontend': [
16+
'@gwack/js': [
1817
'usePage',
1918
'useFetch',
2019
'useAsyncData',

0 commit comments

Comments
 (0)