create-deka-app 0.0.4 → 0.0.6

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/scaffold.js +57 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-deka-app",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "Scaffold a new deka app",
5
5
  "bin": {
6
6
  "create-deka-app": "./index.js"
package/src/scaffold.js CHANGED
@@ -29,6 +29,41 @@ function dekaBinPath(targetDir, platform) {
29
29
  return path.join(targetDir, 'node_modules', '.bin', platform === 'win32' ? 'deka.cmd' : 'deka')
30
30
  }
31
31
 
32
+ // `deka init`'s own "next steps" block always starts with a line beginning
33
+ // "[init]" (verified against the real binary: `[init] DekaScript app
34
+ // ready` followed by 1-2 indented command lines). Everything from that
35
+ // line onward is deka's suggestion for what to run next, and we always
36
+ // replace it with our own -- see printNextSteps below for why. Everything
37
+ // before it (the banner, the per-file `[create] ...` lines) is left
38
+ // intact so the user still sees the scaffold happen.
39
+ function stripDekaNextSteps(output) {
40
+ if (!output) return ''
41
+ const lines = String(output).split(/\r?\n/)
42
+ const cutIndex = lines.findIndex((line) => line.startsWith('[init]'))
43
+ return cutIndex === -1 ? String(output) : lines.slice(0, cutIndex).join('\n')
44
+ }
45
+
46
+ // deka init's own next-steps text always tells the user to run `deka dev`,
47
+ // and that command is correct as-is -- `deka` from this package is scoped
48
+ // to the project, so the copy installed into node_modules/.bin (and picked
49
+ // up via the project's package.json script) works with nothing beyond what
50
+ // the install step above already put on disk. We suppress deka's block
51
+ // (stripDekaNextSteps) only because it doesn't know it's being invoked
52
+ // from the parent directory here, so it can't tell the user they still
53
+ // need to `cd <dirName>` first -- not because its command is wrong. Our
54
+ // own block adds that missing `cd` and repeats `deka dev` verbatim,
55
+ // regardless of which package manager ran the install. (This reverts an
56
+ // earlier version of this function that substituted a package-manager
57
+ // idiom -- `npm run dev` / `pnpm dev` / etc. -- for `deka dev`, on the
58
+ // mistaken premise that a bare `deka dev` can't be run without a global
59
+ // install.)
60
+ function printNextSteps(log, dirName) {
61
+ log('')
62
+ log(' Next steps:')
63
+ log(` cd ${dirName}`)
64
+ log(' deka dev')
65
+ }
66
+
32
67
  export const RUNTIME_PACKAGE = '@dekaruntime/deka'
33
68
 
34
69
  // Builds the package.json this package writes into every scaffolded
@@ -168,17 +203,38 @@ export function createApp({
168
203
  )
169
204
  }
170
205
 
171
- const init = spawn(dekaBin, ['init'], { cwd: targetDir, stdio: 'inherit' })
206
+ // Invoked as `deka init <dirName>` from the *parent* directory -- the
207
+ // same shape as someone typing `deka init myapp` by hand -- rather than
208
+ // `deka init` with cwd already set to targetDir. deka init never
209
+ // overwrites a file that already exists (package.json, written above,
210
+ // survives untouched), and this shape is what makes deka's own output
211
+ // reference the right directory name if any of it leaks through.
212
+ const dirName = path.basename(targetDir)
213
+ const parentDir = path.dirname(targetDir)
214
+ const init = spawn(dekaBin, ['init', dirName], {
215
+ cwd: parentDir,
216
+ stdio: ['inherit', 'pipe', 'pipe'],
217
+ encoding: 'utf8',
218
+ })
172
219
 
173
220
  if (init.error) {
174
221
  throw new ScaffoldError(`Could not run "deka init" in ${targetDir}: ${init.error.message}`)
175
222
  }
176
223
  if (init.status !== 0) {
224
+ // Something went wrong -- show everything deka printed, unfiltered,
225
+ // so the real error is visible. Filtering only ever happens below, on
226
+ // the success path, where we know exactly what we're throwing away.
227
+ if (init.stdout) log(String(init.stdout))
228
+ if (init.stderr) log(String(init.stderr))
177
229
  throw new ScaffoldError(
178
230
  `"deka init" failed in ${targetDir} (exit code ${init.status}).`,
179
231
  init.status ?? 1
180
232
  )
181
233
  }
182
234
 
235
+ if (init.stdout) log(stripDekaNextSteps(init.stdout))
236
+ if (init.stderr) log(stripDekaNextSteps(init.stderr))
237
+ printNextSteps(log, dirName)
238
+
183
239
  return 0
184
240
  }