sandstone-cli 1.2.5 → 2.0.0

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.
@@ -5,8 +5,9 @@ import chalk from 'chalk-template'
5
5
  import util from 'util'
6
6
  import * as child from 'child_process'
7
7
  import { nanoid } from 'nanoid'
8
+ import { confirm, select, input } from '@inquirer/prompts'
8
9
 
9
- import { capitalize, getWorldsList, hasPnpm, hasYarn } from '../utils.js'
10
+ import { capitalize, getWorldsList, hasBun, hasPnpm, hasYarn } from '../utils.js'
10
11
 
11
12
  type CreateOptions = {
12
13
  // Flags
@@ -34,24 +35,16 @@ export async function createCommand(_project: string, opts: CreateOptions) {
34
35
  const projectPath = path.resolve(_project)
35
36
  const projectName = path.basename(projectPath)
36
37
 
37
- const inquirer = (await import("inquirer")).default
38
-
39
- const projectType = Boolean((await inquirer.prompt({
40
- name: 'projectType',
38
+ const projectType = (await confirm({
41
39
  message: 'Whether your project will be a library for use in other Sandstone projects >',
42
- type: 'confirm',
43
40
  default: false,
44
- })).projectType) === true ? 'library' : 'pack'
41
+ })) === true ? 'library' : 'pack'
45
42
 
46
43
  const sv = (v: string) => new SemVer(v)
47
44
 
48
- const versions = [[sv('0.13.6'), sv('0.5.4')], [sv('1.0.0-beta.0'), sv('1.1.11')]] as const
49
-
50
- const stableIndex = 0
45
+ const versions = [[sv('1.0.0-beta.1'), sv('2.0.0')]] as const
51
46
 
52
- const { version } = await inquirer.prompt({
53
- name: 'version',
54
- type: 'list',
47
+ const version = await select({
55
48
  message: 'Which version of Sandstone do you want to use? These are the only supported versions for new projects.',
56
49
  choices: versions.map((v) => {
57
50
  const { prerelease, major, minor } = v[0]
@@ -66,29 +59,23 @@ export async function createCommand(_project: string, opts: CreateOptions) {
66
59
  short: v[0].toString(),
67
60
  }
68
61
  }),
69
- default: stableIndex,
70
- }) as {
71
- version: typeof versions[any]
72
- }
62
+ default: versions[0],
63
+ })
73
64
 
74
65
  let packName = projectName
75
66
 
76
67
  let namespace = projectName.replace(RegExp(/ /g), '_')
77
68
 
78
69
  if (projectType === 'pack') {
79
- packName = (await inquirer.prompt({
80
- name: 'projectType',
70
+ packName = (await input({
81
71
  message: 'Name of your output pack(s) (can be changed later) >',
82
72
  default: projectName,
83
- type: 'input',
84
- })).projectType
73
+ }))
85
74
 
86
- namespace = (await inquirer.prompt({
87
- name: 'namespace',
75
+ namespace = (await input({
88
76
  message: 'Default namespace (can be changed later) >',
89
77
  default: namespace,
90
- type: 'input',
91
- })).namespace
78
+ }))
92
79
  } else {
93
80
  packName += '-testing'
94
81
  namespace += '_test'
@@ -115,9 +102,7 @@ export async function createCommand(_project: string, opts: CreateOptions) {
115
102
  saveOptions.serverPath = opts.serverPath
116
103
  } else { // TODO: Add support for ssh
117
104
  // User didn't specify a way to save the file. Ask them.
118
- const { saveChoice }: { saveChoice: 'root' | 'world' | 'server-path' | 'none' } = await inquirer.prompt({
119
- name: 'saveChoice',
120
- type: 'list',
105
+ const saveChoice = await select<'root' | 'world' | 'server-path' | 'none'>({
121
106
  message: 'Where do you want your pack(s) to be exported to (can be changed later)?',
122
107
  choices: [{
123
108
  name: 'In the root client (.minecraft/datapacks & .minecraft/resourcepacks) folder(s)',
@@ -143,19 +128,15 @@ export async function createCommand(_project: string, opts: CreateOptions) {
143
128
  saveOptions.root = true
144
129
  break
145
130
  case 'world':
146
- const { world }: { world: string } = await inquirer.prompt({
147
- name: 'world',
131
+ const world = await select({
148
132
  message: 'What world do you want to save the packs in? >',
149
- type: 'list',
150
- choices: () => getWorldsList(saveOptions.clientPath),
133
+ choices: getWorldsList(saveOptions.clientPath),
151
134
  })
152
135
  saveOptions.world = world
153
136
  break
154
137
  case 'server-path':
155
- const { serverPath }: { serverPath: string } = await inquirer.prompt({
156
- name: 'serverPath',
138
+ const serverPath = await input({
157
139
  message: 'Where is the server to save the packs in? Relative paths are accepted. >',
158
- type: 'input',
159
140
  })
160
141
 
161
142
  saveOptions.serverPath = serverPath
@@ -169,25 +150,25 @@ export async function createCommand(_project: string, opts: CreateOptions) {
169
150
 
170
151
  const yarn = hasYarn()
171
152
  const pnpm = hasPnpm()
153
+ const bun = hasBun()
172
154
 
173
155
  if (yarn || pnpm) {
174
156
  const choices = ['npm']
175
157
 
176
158
  if (yarn) choices.unshift('yarn')
177
159
  if (pnpm) choices.unshift('pnpm')
160
+ if (bun) choices.unshift('bun')
178
161
 
179
- packageManager = (await inquirer.prompt({
180
- name: 'packageManager',
181
- message: 'What package manager do you want to use? >',
182
- type: 'list',
183
- choices: choices,
184
- })).packageManager
162
+ packageManager = (await select({
163
+ message: 'What package manager do you want to use? (For now you have to use Bun) >',
164
+ choices: choices
165
+ }))
185
166
  }
186
167
 
187
168
  fs.mkdirSync(projectPath)
188
169
 
189
170
  // Create project & install dependencies
190
- console.log(chalk`Installing {rgb(229,193,0) sandstone@${version[0]}}, {rgb(229,193,0) sandstone-cli@${version[1]}} and {cyan typescript} using {cyan ${packageManager}}.`)
171
+ console.log(chalk`Installing {rgb(229, 193, 0) sandstone@${version[0]}}, {rgb(229, 193, 0) sandstone-cli@${version[1]}} and {cyan typescript} using {cyan ${packageManager}}.`)
191
172
 
192
173
  const exec = (cmd: string) => child.execSync(cmd, { cwd: projectPath })
193
174
 
@@ -2,7 +2,7 @@ import fs from 'fs-extra'
2
2
  import path from 'path'
3
3
  import { exec } from 'child_process'
4
4
  import { buildCommand } from './build.js'
5
- import inquirer from 'inquirer'
5
+ import { checkbox } from '@inquirer/prompts'
6
6
 
7
7
  const _fetch = import('node-fetch')
8
8
 
@@ -23,17 +23,13 @@ export async function installNativeCommand(_libraries: string[]) {
23
23
  const manifest = await (await fetch('https://raw.githubusercontent.com/sandstone-mc/sandstone-libraries/main/manifest.json')).json() as LibraryManifest
24
24
 
25
25
  const search = async () => {
26
- const { selected } = await inquirer.prompt({
27
- name: 'selected',
28
- type: 'checkbox',
26
+ const selected = await checkbox({
29
27
  message: 'Which libraries to add?',
30
28
  choices: manifest.libraries.map((library) => ({
31
29
  name: library.name,
32
30
  value: library.package,
33
31
  })),
34
- }) as {
35
- selected: string[]
36
- }
32
+ })
37
33
 
38
34
  if (selected && selected.length !== 0) {
39
35
  libraries.push(...selected.map((lib) => [lib, true] as [string, boolean]))
@@ -124,7 +120,7 @@ export async function installVanillaCommand(_libraries: string[]) {
124
120
  description: data.display.description,
125
121
  }
126
122
 
127
- if (manifest && !manifest[id] && !manifest[meta.rawId]) {
123
+ if (!manifest || !(manifest[id] || manifest[meta.rawId])) {
128
124
 
129
125
  if (option.name.length > optionColumn[0]) optionColumn[0] = option.name.length
130
126
 
@@ -151,24 +147,19 @@ export async function installVanillaCommand(_libraries: string[]) {
151
147
  if (options.length === 0) {
152
148
  console.log('No results found!')
153
149
  } else {
154
- const { selected } = await inquirer.prompt({
155
- name: 'selected',
156
- type: 'checkbox',
150
+ const selected = await checkbox({
157
151
  message: 'Which libraries to add?',
158
152
  choices: options.map((option) => ({
159
153
  name: `${option.name}${space(0, option.name)}by ${option.owner}${space(1, option.owner)}${option.downloads} downloads${space(2, option.downloads)}${option.description}`,
160
- short: `${option.name} - by ${option.owner} - ${option.downloads} downloads - ${option.description}`,
161
- value: [option.id, true],
154
+ value: [option.id, true] as [string, true],
162
155
  })),
163
- }) as {
164
- selected: [string, true][]
165
- }
166
-
156
+ })
157
+
167
158
  if (selected && selected.length !== 0) {
168
159
  libraries.push(...selected)
169
-
160
+
170
161
  count += selected.length
171
-
162
+
172
163
  return true
173
164
  }
174
165
  }
@@ -180,34 +171,32 @@ export async function installVanillaCommand(_libraries: string[]) {
180
171
  }
181
172
 
182
173
  if (count > 0) {
183
-
184
174
  let adding: [string, string][] | false = false
185
175
 
186
176
  for await (const [library, searched] of libraries) {
187
177
  const version = library.includes('@') ? library.split('@')[1] : 'latest'
188
178
 
179
+ if (searched) {
180
+ if (!adding) adding = []
181
+ adding.push([library, version])
182
+ }
189
183
  if (!manifest || !(manifest[library] || manifest[library] === version)) {
190
- if (searched) {
184
+ let exists = false
185
+ try {
186
+ /* @ts-ignore */
187
+ exists = (await (await fetch(`${base}/packs/${library}/meta`)).json()).statusCode !== 404
188
+ } catch (e) {}
189
+
190
+ if (exists) {
191
191
  if (!adding) adding = []
192
192
  adding.push([library, version])
193
193
  } else {
194
- let exists = false
195
- try {
196
- /* @ts-ignore */
197
- exists = (await (await fetch(`${base}/packs/${library}/meta`)).json()).statusCode !== 404
198
- } catch (e) {}
199
-
200
- if (exists) {
201
- if (!adding) adding = []
202
- adding.push([library, version])
203
- } else {
204
- count--
194
+ count--
205
195
 
206
- console.log(`${library} doesn't exist! Searching...`)
196
+ console.log(`${library} doesn't exist! Searching...`)
207
197
 
208
- if (await search(library)) {
209
- if (!adding) adding = []
210
- }
198
+ if (await search(library)) {
199
+ if (!adding) adding = []
211
200
  }
212
201
  }
213
202
  } else {
@@ -216,14 +205,12 @@ export async function installVanillaCommand(_libraries: string[]) {
216
205
  }
217
206
  if (adding) {
218
207
  await buildCommand({
219
- path: './src',
220
- configPath: './',
208
+ path: './',
221
209
  dependencies: adding
222
210
  })
223
211
  }
224
212
  }
225
213
 
226
- console.log
227
214
  console.log(`${count} libraries added`)
228
215
  }
229
216
 
@@ -247,17 +234,13 @@ export async function uninstallVanillaCommand(_libraries: string[]) {
247
234
 
248
235
  if (manifest) {
249
236
  if (count === 0) {
250
- const { selected } = await inquirer.prompt({
251
- name: 'selected',
252
- type: 'checkbox',
237
+ const selected = await checkbox({
253
238
  message: 'Which libraries to remove?',
254
239
  choices: Object.entries(manifest).map(([name]) => ({
255
240
  short: name,
256
241
  value: name,
257
242
  })),
258
- }) as {
259
- selected: string[]
260
- }
243
+ })
261
244
 
262
245
  if (selected && selected.length !== 0) {
263
246
  count = selected.length
@@ -315,8 +298,7 @@ export async function refreshCommand() {
315
298
  await fs.writeFile(lockFilePath, '{}')
316
299
 
317
300
  await buildCommand({
318
- path: './src',
319
- configPath: './'
301
+ path: './',
320
302
  })
321
303
  } else {
322
304
  console.log('No libraries to refresh')
@@ -1,4 +1,4 @@
1
- export { buildCommand } from './build.js';
2
- export { createCommand } from './create.js';
1
+ export { buildCommand } from './build.js'
2
+ export { createCommand } from './create.js'
3
3
  export { installNativeCommand, installVanillaCommand, uninstallVanillaCommand, refreshCommand } from './dependency.js'
4
- export { watchCommand } from './watch.js';
4
+ export { watchCommand, type WatchOptions } from './watch.js'