mirror of
https://github.com/ThatGuySam/doesitarm.git
synced 2026-05-18 06:44:46 -07:00
Move download and indexing to it’s own file
This commit is contained in:
parent
8a5a64c9cc
commit
e1c1cdddfd
2 changed files with 95 additions and 54 deletions
94
helpers/stork/executable.js
Normal file
94
helpers/stork/executable.js
Normal file
|
|
@ -0,0 +1,94 @@
|
||||||
|
import fs from 'fs-extra'
|
||||||
|
import execa from 'execa'
|
||||||
|
|
||||||
|
import { isDarwin } from '~/helpers/environment.js'
|
||||||
|
import {
|
||||||
|
storkVersion,
|
||||||
|
storkExecutableName,
|
||||||
|
storkExecutablePath,
|
||||||
|
storkTomlPath,
|
||||||
|
storkIndexPath
|
||||||
|
} from '~/helpers/stork/config.js'
|
||||||
|
|
||||||
|
// https://stork-search.net/docs/install
|
||||||
|
const execDownloadUrls = {
|
||||||
|
darwin: `https://files.stork-search.net/releases/v${ storkVersion }/stork-macos-10-15`,
|
||||||
|
default: `https://files.stork-search.net/releases/v${ storkVersion }/stork-ubuntu-20-04`
|
||||||
|
// default: `https://files.stork-search.net/releases/v${ storkVersion }/stork-amazon-linux`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if a file is executable
|
||||||
|
// https://stackoverflow.com/a/69897809/1397641
|
||||||
|
async function isExecutable ( path ) {
|
||||||
|
const stats = await fs.stat( path )
|
||||||
|
const isExecutable = !!(stats.mode & fs.constants.S_IXUSR)
|
||||||
|
|
||||||
|
return isExecutable
|
||||||
|
}
|
||||||
|
|
||||||
|
// 👩💻 Bash Download example - https://github.com/jmooring/hugo-stork/blob/main/build.sh
|
||||||
|
export async function downloadStorkExecutable () {
|
||||||
|
const envKey = isDarwin() ? 'darwin' : 'default'
|
||||||
|
|
||||||
|
const execDownloadUrl = execDownloadUrls[ envKey ]
|
||||||
|
|
||||||
|
// console.log( 'execDownloadUrl', execDownloadUrl )
|
||||||
|
|
||||||
|
// Delete any existing executable
|
||||||
|
// so we don't get write errors
|
||||||
|
// or false positives from preexisting executable files
|
||||||
|
await fs.remove( storkExecutablePath )
|
||||||
|
|
||||||
|
// Download the binary
|
||||||
|
await execa( `curl`, [
|
||||||
|
execDownloadUrl,
|
||||||
|
|
||||||
|
// Set filename
|
||||||
|
'-o',
|
||||||
|
storkExecutableName
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
|
// Set the downloaded binary as executable
|
||||||
|
await fs.chmod( storkExecutablePath, '755' )
|
||||||
|
// Check that our downloaded binary is executable
|
||||||
|
|
||||||
|
|
||||||
|
// console.log( 'isExecutable', isExecutable )
|
||||||
|
if ( !isExecutable( storkExecutablePath ) ) throw new Error( `Downloaded binary at ${ storkExecutablePath } is not executable.` )
|
||||||
|
|
||||||
|
|
||||||
|
// Check Stork version
|
||||||
|
// so we know our binary is working
|
||||||
|
const { stdout } = await execa( storkExecutablePath, [
|
||||||
|
'--version'
|
||||||
|
])
|
||||||
|
|
||||||
|
console.log( 'Stork Version', stdout )
|
||||||
|
if ( !stdout.includes( storkVersion ) ) throw new Error( 'Stork --version command failed.' )
|
||||||
|
|
||||||
|
return stdout
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export async function buildIndex () {
|
||||||
|
|
||||||
|
if ( !isExecutable( storkExecutablePath ) ) throw new Error( `Binary at ${ storkExecutablePath } is not executable.` )
|
||||||
|
|
||||||
|
// Check Stork version
|
||||||
|
// so we know our binary is working
|
||||||
|
const { stdout } = await execa( storkExecutablePath, [
|
||||||
|
'build',
|
||||||
|
|
||||||
|
'--input',
|
||||||
|
storkTomlPath,
|
||||||
|
|
||||||
|
'--output',
|
||||||
|
storkIndexPath
|
||||||
|
])
|
||||||
|
|
||||||
|
console.log( 'Stork Build', stdout )
|
||||||
|
if ( !stdout.includes( storkVersion ) ) throw new Error( 'Stork --version command failed.' )
|
||||||
|
|
||||||
|
return stdout
|
||||||
|
}
|
||||||
|
|
@ -4,70 +4,17 @@ import has from 'just-has'
|
||||||
import TOML from '@iarna/toml'
|
import TOML from '@iarna/toml'
|
||||||
|
|
||||||
|
|
||||||
import { isDarwin } from '~/helpers/environment.js'
|
|
||||||
import {
|
import {
|
||||||
isNonEmptyString,
|
isNonEmptyString,
|
||||||
isNonEmptyArray
|
isNonEmptyArray
|
||||||
} from '~/helpers/check-types.js'
|
} from '~/helpers/check-types.js'
|
||||||
import {
|
import {
|
||||||
storkVersion,
|
|
||||||
storkExecutableName,
|
|
||||||
storkExecutablePath,
|
|
||||||
storkTomlPath,
|
storkTomlPath,
|
||||||
} from '~/helpers/stork/config.js'
|
} from '~/helpers/stork/config.js'
|
||||||
|
import { downloadStorkExecutable } from '~/helpers/stork/executable.js'
|
||||||
|
|
||||||
|
|
||||||
// https://stork-search.net/docs/install
|
|
||||||
const execDownloadUrls = {
|
|
||||||
darwin: `https://files.stork-search.net/releases/v${ storkVersion }/stork-macos-10-15`,
|
|
||||||
default: `https://files.stork-search.net/releases/v${ storkVersion }/stork-ubuntu-20-04`
|
|
||||||
// default: `https://files.stork-search.net/releases/v${ storkVersion }/stork-amazon-linux`
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function downloadStorkExecutable () {
|
|
||||||
const envKey = isDarwin() ? 'darwin' : 'default'
|
|
||||||
|
|
||||||
const execDownloadUrl = execDownloadUrls[ envKey ]
|
|
||||||
|
|
||||||
// console.log( 'execDownloadUrl', execDownloadUrl )
|
|
||||||
|
|
||||||
// Delete any existing executable
|
|
||||||
// so we don't get write errors
|
|
||||||
// or false positives from preexisting executable files
|
|
||||||
await fs.remove( storkExecutablePath )
|
|
||||||
|
|
||||||
// Download the binary
|
|
||||||
await execa( `curl`, [
|
|
||||||
execDownloadUrl,
|
|
||||||
|
|
||||||
// Set filename
|
|
||||||
'-o',
|
|
||||||
storkExecutableName
|
|
||||||
])
|
|
||||||
|
|
||||||
|
|
||||||
// Set the downloaded binary as executable
|
|
||||||
await fs.chmod( storkExecutablePath, '755' )
|
|
||||||
// Check that our downloaded binary is executable
|
|
||||||
// https://stackoverflow.com/a/69897809/1397641
|
|
||||||
const stats = await fs.stat( storkExecutablePath )
|
|
||||||
const isExecutable = !!(stats.mode & fs.constants.S_IXUSR)
|
|
||||||
|
|
||||||
// console.log( 'isExecutable', isExecutable )
|
|
||||||
if ( !isExecutable ) throw new Error( 'Downloaded binary is not executable.' )
|
|
||||||
|
|
||||||
|
|
||||||
// Check Stork version
|
|
||||||
// so we know our binary is working
|
|
||||||
const { stdout } = await execa( storkExecutablePath, [
|
|
||||||
'--version'
|
|
||||||
])
|
|
||||||
|
|
||||||
console.log( 'Stork Version', stdout )
|
|
||||||
if ( !stdout.includes( storkVersion ) ) throw new Error( 'Stork --version command failed.' )
|
|
||||||
|
|
||||||
return stdout
|
|
||||||
}
|
|
||||||
|
|
||||||
function makeIndexContentsFromListing ( listing ) {
|
function makeIndexContentsFromListing ( listing ) {
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue