Skip to content

Commit

Permalink
fix(setup,update): build SDK tools if not included in tagged release
Browse files Browse the repository at this point in the history
  • Loading branch information
HipsterBrown committed Dec 28, 2024
1 parent c151255 commit f4a4a64
Show file tree
Hide file tree
Showing 6 changed files with 361 additions and 246 deletions.
11 changes: 5 additions & 6 deletions src/commands/scan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,19 @@ const command = buildCommand({
)
}

spinner.start('Scanning for devices...')

const hasPicotool = system.which('picotool') !== null

if (hasPicotool) {
try {
spinner.start('Found picotool, rebooting device before scanning')
await system.exec('picotool reboot -fa')
await sleep(1000)
spinner.stop()
} catch {}
}

spinner.start('Scanning for devices...')

const ports = await SerialPort.list()
const result: Array<
[output: Buffer, port: string] | [output: undefined, port: string]
Expand All @@ -50,10 +52,7 @@ const command = buildCommand({
.filter((port) => port.serialNumber !== undefined)
.map(async (port) => {
try {
if (
port.manufacturer?.includes('Raspberry Pi') === true &&
hasPicotool
) {
if (port.vendorId === '2e8a' && hasPicotool) {
const device = await findBySerialNumber(port.serialNumber ?? '')
const bus = String(device?.busNumber)
const address = String(device?.deviceAddress)
Expand Down
72 changes: 47 additions & 25 deletions src/toolbox/setup/linux.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os from 'os'
import { promisify } from 'util'
import { chmod } from 'fs'
import { filesystem, print, system } from 'gluegun'
import { filesystem, print, system, prompt } from 'gluegun'
import {
INSTALL_DIR,
INSTALL_PATH,
Expand Down Expand Up @@ -43,6 +43,7 @@ export default async function ({
'lin',
)

let buildTools = false
const spinner = print.spin()
spinner.start('Beginning setup...')

Expand Down Expand Up @@ -73,38 +74,59 @@ export default async function ({
if (release !== undefined && (branch === undefined || branch === null)) {
spinner.start('Getting latest Moddable-OpenSource/moddable release')
const remoteRelease = await fetchRelease(release)

if (remoteRelease.assets.length === 0) {
print.warning(
`Moddable release ${release} does not have any pre-built assets.`,
)
buildTools = await prompt.confirm(
'Would you like to continue setting up and build the SDK locally?',
true,
)

if (!buildTools) {
print.info(
'Please select another release version with pre-built assets: https://github.com/Moddable-OpenSource/moddable/releases',
)
process.exit(0)
}
}

await system.spawn(
`git clone ${sourceRepo} ${INSTALL_PATH} --depth 1 --branch ${remoteRelease.tag_name} --single-branch`,
)

filesystem.dir(BIN_PATH)
filesystem.dir(DEBUG_BIN_PATH)

const isArm = os.arch() === 'arm64'
const assetName = isArm
? 'moddable-tools-lin64arm.zip'
: 'moddable-tools-lin64.zip'
spinner.info('Downloading release tools')
await downloadReleaseTools({
writePath: BIN_PATH,
assetName,
release: remoteRelease,
})
const tools = filesystem.list(BIN_PATH) ?? []
await Promise.all(
tools.map(async (tool) => {
await chmodPromise(filesystem.resolve(BIN_PATH, tool), 0o751)
await filesystem.copyAsync(
filesystem.resolve(BIN_PATH, tool),
filesystem.resolve(DEBUG_BIN_PATH, tool),
)
}),
)
if (!buildTools) {
filesystem.dir(BIN_PATH)
filesystem.dir(DEBUG_BIN_PATH)

const isArm = os.arch() === 'arm64'
const assetName = isArm
? 'moddable-tools-lin64arm.zip'
: 'moddable-tools-lin64.zip'
spinner.info('Downloading release tools')
await downloadReleaseTools({
writePath: BIN_PATH,
assetName,
release: remoteRelease,
})
const tools = filesystem.list(BIN_PATH) ?? []
await Promise.all(
tools.map(async (tool) => {
await chmodPromise(filesystem.resolve(BIN_PATH, tool), 0o751)
await filesystem.copyAsync(
filesystem.resolve(BIN_PATH, tool),
filesystem.resolve(DEBUG_BIN_PATH, tool),
)
}),
)
}
} else {
spinner.start(`Cloning ${sourceRepo} repo`)
await system.spawn(
`git clone ${sourceRepo} ${INSTALL_PATH} --depth 1 --branch ${branch} --single-branch`,
)
buildTools = true
}
spinner.succeed()
}
Expand All @@ -117,7 +139,7 @@ export default async function ({
await upsert(EXPORTS_FILE_PATH, `export PATH="${BIN_PATH}:$PATH"`)

// 5. Build the Moddable command line tools, simulator, and debugger from the command line:
if (typeof branch === 'string') {
if (buildTools) {
spinner.start('Building platform tooling')
await system.exec('make', { cwd: BUILD_DIR, stdout: process.stdout })
spinner.succeed()
Expand Down
109 changes: 66 additions & 43 deletions src/toolbox/setup/mac.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { print, filesystem, system } from 'gluegun'
import { print, filesystem, system, prompt } from 'gluegun'
import os from 'os'
import { promisify } from 'util'
import { chmod } from 'fs'
Expand Down Expand Up @@ -56,6 +56,8 @@ export default async function ({
process.exit(1)
}

let buildTools = false

const spinner = print.spin()
spinner.start('Beginning setup...')

Expand All @@ -76,62 +78,83 @@ export default async function ({
if (release !== undefined && (branch === undefined || branch === null)) {
spinner.start('Getting latest Moddable-OpenSource/moddable release')
const remoteRelease = await fetchRelease(release)

if (remoteRelease.assets.length === 0) {
print.warning(
`Moddable release ${release} does not have any pre-built assets.`,
)
buildTools = await prompt.confirm(
'Would you like to continue setting up and build the SDK locally?',
true,
)

if (!buildTools) {
print.info(
'Please select another release version with pre-built assets: https://github.com/Moddable-OpenSource/moddable/releases',
)
process.exit(0)
}
}

await system.spawn(
`git clone ${sourceRepo} ${INSTALL_PATH} --depth 1 --branch ${remoteRelease.tag_name} --single-branch`,
)

filesystem.dir(BIN_PATH)
filesystem.dir(DEBUG_BIN_PATH)

spinner.info('Downloading release tools')
try {
const universalAssetName = `moddable-tools-macuniversal.zip`
await downloadReleaseTools({
writePath: BIN_PATH,
assetName: universalAssetName,
release: remoteRelease,
})
} catch (error: unknown) {
if (error instanceof MissingReleaseAssetError) {
const isArm = os.arch() === 'arm64'
const assetName = isArm
? 'moddable-tools-mac64arm.zip'
: 'moddable-tools-mac64.zip'
if (!buildTools) {
filesystem.dir(BIN_PATH)
filesystem.dir(DEBUG_BIN_PATH)

spinner.info('Downloading release tools')
try {
const universalAssetName = `moddable-tools-macuniversal.zip`
await downloadReleaseTools({
writePath: BIN_PATH,
assetName,
assetName: universalAssetName,
release: remoteRelease,
})
} else {
throw error as Error
}
}
const tools = filesystem.list(BIN_PATH) ?? []
await Promise.all(
tools.map(async (tool) => {
if (tool.endsWith('.app')) {
const mainPath = filesystem.resolve(
BIN_PATH,
tool,
'Contents',
'MacOS',
'main',
)
await chmodPromise(mainPath, 0o751)
} catch (error: unknown) {
if (error instanceof MissingReleaseAssetError) {
const isArm = os.arch() === 'arm64'
const assetName = isArm
? 'moddable-tools-mac64arm.zip'
: 'moddable-tools-mac64.zip'
await downloadReleaseTools({
writePath: BIN_PATH,
assetName,
release: remoteRelease,
})
} else {
await chmodPromise(filesystem.resolve(BIN_PATH, tool), 0o751)
throw error as Error
}
await filesystem.copyAsync(
filesystem.resolve(BIN_PATH, tool),
filesystem.resolve(DEBUG_BIN_PATH, tool),
)
}),
)
}
const tools = filesystem.list(BIN_PATH) ?? []
await Promise.all(
tools.map(async (tool) => {
if (tool.endsWith('.app')) {
const mainPath = filesystem.resolve(
BIN_PATH,
tool,
'Contents',
'MacOS',
'main',
)
await chmodPromise(mainPath, 0o751)
} else {
await chmodPromise(filesystem.resolve(BIN_PATH, tool), 0o751)
}
await filesystem.copyAsync(
filesystem.resolve(BIN_PATH, tool),
filesystem.resolve(DEBUG_BIN_PATH, tool),
)
}),
)
}
} else {
spinner.start(`Cloning ${sourceRepo} repo`)
await system.spawn(
`git clone ${sourceRepo} ${INSTALL_PATH} --depth 1 --branch ${branch} --single-branch`,
)
buildTools = true
}
spinner.succeed()
} catch (error) {
Expand All @@ -148,7 +171,7 @@ export default async function ({
await upsert(EXPORTS_FILE_PATH, `export PATH="${BIN_PATH}:$PATH"`)

// 3. cd into makefiles dir for platform, run `make`
if (branch !== undefined || branch !== null) {
if (buildTools) {
try {
spinner.start('Building platform tooling')
await system.exec('make', { cwd: BUILD_DIR, stdout: process.stdout })
Expand Down
63 changes: 42 additions & 21 deletions src/toolbox/setup/windows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ export default async function ({
spinner.fail(`Error setting up install directory: ${String(error)}`)
process.exit(1)
}
let buildTools = false

if (filesystem.exists(INSTALL_PATH) !== false) {
spinner.info('Moddable repo already installed')
Expand All @@ -220,39 +221,59 @@ export default async function ({
if (release !== undefined && (branch === undefined || branch === null)) {
spinner.start(`Getting latest Moddable-OpenSource/moddable release`)
const remoteRelease = await fetchRelease(release)

if (remoteRelease.assets.length === 0) {
print.warning(
`Moddable release ${release} does not have any pre-built assets.`,
)
buildTools = await prompt.confirm(
'Would you like to continue setting up and build the SDK locally?',
true,
)

if (!buildTools) {
print.info(
'Please select another release version with pre-built assets: https://github.com/Moddable-OpenSource/moddable/releases',
)
process.exit(0)
}
}

await system.spawn(
`git clone ${sourceRepo} ${INSTALL_PATH} --depth 1 --branch ${remoteRelease.tag_name} --single-branch`,
)

filesystem.dir(BIN_PATH)
filesystem.dir(DEBUG_BIN_PATH)
if (!buildTools) {
filesystem.dir(BIN_PATH)
filesystem.dir(DEBUG_BIN_PATH)

spinner.info('Downloading release tools')
spinner.info('Downloading release tools')

const assetName = `moddable-tools-win64.zip`
await downloadReleaseTools({
writePath: BIN_PATH,
assetName,
release: remoteRelease,
})
const assetName = `moddable-tools-win64.zip`
await downloadReleaseTools({
writePath: BIN_PATH,
assetName,
release: remoteRelease,
})

const tools = filesystem.list(BIN_PATH) ?? []
await Promise.all(
tools.map(async (tool) => {
await filesystem.copyAsync(
filesystem.resolve(BIN_PATH, tool),
filesystem.resolve(DEBUG_BIN_PATH, tool),
)
}),
)

spinner.succeed()
const tools = filesystem.list(BIN_PATH) ?? []
await Promise.all(
tools.map(async (tool) => {
await filesystem.copyAsync(
filesystem.resolve(BIN_PATH, tool),
filesystem.resolve(DEBUG_BIN_PATH, tool),
)
}),
)
}
} else {
spinner.start(`Cloning ${sourceRepo} repo`)
await system.spawn(
`git clone ${sourceRepo} ${INSTALL_PATH} --depth 1 --branch ${branch} --single-branch`,
)
buildTools = true
}
spinner.succeed()
} catch (error) {
spinner.fail(`Error cloning moddable repo: ${String(error)}`)
process.exit(1)
Expand All @@ -271,7 +292,7 @@ export default async function ({
}

// 3. build tools if needed
if (typeof branch === 'string') {
if (buildTools) {
try {
spinner.start(`Building Moddable SDK tools`)
await system.exec(`build.bat`, { cwd: BUILD_DIR, stdout: process.stdout })
Expand Down
Loading

0 comments on commit f4a4a64

Please sign in to comment.