sandstone-cli 1.2.4 → 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.
- package/bun.lock +490 -0
- package/lib/commands/build.d.ts +20 -6
- package/lib/commands/build.js +617 -24
- package/lib/commands/create.js +26 -40
- package/lib/commands/dependency.js +22 -34
- package/lib/commands/index.d.ts +1 -1
- package/lib/commands/watch.d.ts +5 -15
- package/lib/commands/watch.js +261 -42
- package/lib/index.d.ts +0 -1
- package/lib/index.js +2 -3
- package/lib/shared.js +3 -2
- package/lib/ui/WatchUI.d.ts +9 -0
- package/lib/ui/WatchUI.js +183 -0
- package/lib/ui/logger.d.ts +20 -0
- package/lib/ui/logger.js +189 -0
- package/lib/ui/types.d.ts +26 -0
- package/lib/ui/types.js +1 -0
- package/lib/utils.d.ts +25 -16
- package/lib/utils.js +51 -35
- package/package.json +15 -8
- package/src/commands/build.ts +805 -49
- package/src/commands/create.ts +27 -45
- package/src/commands/dependency.ts +29 -47
- package/src/commands/index.ts +3 -3
- package/src/commands/watch.ts +320 -73
- package/src/create.ts +4 -4
- package/src/index.ts +7 -8
- package/src/shared.ts +3 -2
- package/src/ui/WatchUI.tsx +269 -0
- package/src/ui/logger.ts +210 -0
- package/src/ui/types.ts +32 -0
- package/src/utils.ts +87 -44
- package/tsconfig.json +5 -3
package/src/commands/create.ts
CHANGED
|
@@ -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
|
|
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
|
-
}))
|
|
41
|
+
})) === true ? 'library' : 'pack'
|
|
45
42
|
|
|
46
43
|
const sv = (v: string) => new SemVer(v)
|
|
47
44
|
|
|
48
|
-
const versions = [[sv('
|
|
49
|
-
|
|
50
|
-
const stableIndex = 0
|
|
45
|
+
const versions = [[sv('1.0.0-beta.1'), sv('2.0.0')]] as const
|
|
51
46
|
|
|
52
|
-
const
|
|
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:
|
|
70
|
-
})
|
|
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
|
|
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
|
-
|
|
84
|
-
})).projectType
|
|
73
|
+
}))
|
|
85
74
|
|
|
86
|
-
namespace = (await
|
|
87
|
-
name: 'namespace',
|
|
75
|
+
namespace = (await input({
|
|
88
76
|
message: 'Default namespace (can be changed later) >',
|
|
89
77
|
default: namespace,
|
|
90
|
-
|
|
91
|
-
})).namespace
|
|
78
|
+
}))
|
|
92
79
|
} else {
|
|
93
80
|
packName += '-testing'
|
|
94
81
|
namespace += '_test'
|
|
@@ -103,6 +90,10 @@ export async function createCommand(_project: string, opts: CreateOptions) {
|
|
|
103
90
|
} = {}
|
|
104
91
|
|
|
105
92
|
if (version[0].major === 1) {
|
|
93
|
+
if (opts.clientPath) {
|
|
94
|
+
saveOptions.clientPath = opts.clientPath
|
|
95
|
+
}
|
|
96
|
+
|
|
106
97
|
if (opts.root) {
|
|
107
98
|
saveOptions.root = true
|
|
108
99
|
} else if (opts.world) {
|
|
@@ -111,9 +102,7 @@ export async function createCommand(_project: string, opts: CreateOptions) {
|
|
|
111
102
|
saveOptions.serverPath = opts.serverPath
|
|
112
103
|
} else { // TODO: Add support for ssh
|
|
113
104
|
// User didn't specify a way to save the file. Ask them.
|
|
114
|
-
const
|
|
115
|
-
name: 'saveChoice',
|
|
116
|
-
type: 'list',
|
|
105
|
+
const saveChoice = await select<'root' | 'world' | 'server-path' | 'none'>({
|
|
117
106
|
message: 'Where do you want your pack(s) to be exported to (can be changed later)?',
|
|
118
107
|
choices: [{
|
|
119
108
|
name: 'In the root client (.minecraft/datapacks & .minecraft/resourcepacks) folder(s)',
|
|
@@ -139,19 +128,15 @@ export async function createCommand(_project: string, opts: CreateOptions) {
|
|
|
139
128
|
saveOptions.root = true
|
|
140
129
|
break
|
|
141
130
|
case 'world':
|
|
142
|
-
const
|
|
143
|
-
name: 'world',
|
|
131
|
+
const world = await select({
|
|
144
132
|
message: 'What world do you want to save the packs in? >',
|
|
145
|
-
|
|
146
|
-
choices: () => getWorldsList(saveOptions.clientPath),
|
|
133
|
+
choices: getWorldsList(saveOptions.clientPath),
|
|
147
134
|
})
|
|
148
135
|
saveOptions.world = world
|
|
149
136
|
break
|
|
150
137
|
case 'server-path':
|
|
151
|
-
const
|
|
152
|
-
name: 'serverPath',
|
|
138
|
+
const serverPath = await input({
|
|
153
139
|
message: 'Where is the server to save the packs in? Relative paths are accepted. >',
|
|
154
|
-
type: 'input',
|
|
155
140
|
})
|
|
156
141
|
|
|
157
142
|
saveOptions.serverPath = serverPath
|
|
@@ -159,34 +144,31 @@ export async function createCommand(_project: string, opts: CreateOptions) {
|
|
|
159
144
|
case 'none': break
|
|
160
145
|
}
|
|
161
146
|
}
|
|
162
|
-
if (opts.clientPath) {
|
|
163
|
-
saveOptions.clientPath = opts.clientPath
|
|
164
|
-
}
|
|
165
147
|
}
|
|
166
148
|
|
|
167
149
|
let packageManager = 'npm'
|
|
168
150
|
|
|
169
151
|
const yarn = hasYarn()
|
|
170
152
|
const pnpm = hasPnpm()
|
|
153
|
+
const bun = hasBun()
|
|
171
154
|
|
|
172
155
|
if (yarn || pnpm) {
|
|
173
156
|
const choices = ['npm']
|
|
174
157
|
|
|
175
158
|
if (yarn) choices.unshift('yarn')
|
|
176
159
|
if (pnpm) choices.unshift('pnpm')
|
|
160
|
+
if (bun) choices.unshift('bun')
|
|
177
161
|
|
|
178
|
-
packageManager = (await
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
choices: choices,
|
|
183
|
-
})).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
|
+
}))
|
|
184
166
|
}
|
|
185
167
|
|
|
186
168
|
fs.mkdirSync(projectPath)
|
|
187
169
|
|
|
188
170
|
// Create project & install dependencies
|
|
189
|
-
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}}.`)
|
|
190
172
|
|
|
191
173
|
const exec = (cmd: string) => child.execSync(cmd, { cwd: projectPath })
|
|
192
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
|
|
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
|
|
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
|
-
})
|
|
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
|
|
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
|
|
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
|
-
|
|
161
|
-
value: [option.id, true],
|
|
154
|
+
value: [option.id, true] as [string, true],
|
|
162
155
|
})),
|
|
163
|
-
})
|
|
164
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
196
|
+
console.log(`${library} doesn't exist! Searching...`)
|
|
207
197
|
|
|
208
|
-
|
|
209
|
-
|
|
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: './
|
|
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
|
|
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
|
-
})
|
|
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: './
|
|
319
|
-
configPath: './'
|
|
301
|
+
path: './',
|
|
320
302
|
})
|
|
321
303
|
} else {
|
|
322
304
|
console.log('No libraries to refresh')
|
package/src/commands/index.ts
CHANGED
|
@@ -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'
|