Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
spinner.stop()
toolbox.print.error(`${error}\n`)
spinner.start()
},
})
// Catch keyboard interrupt: close watcher and exit process
process.on('SIGINT', () => {
watcher.close()
process.exit()
})
try {
await watcher.watch()
} catch (e) {
toolbox.print.error(`${e.message}`)
}
}
}
const createCompiler = (manifest, { ipfs, outputDir, outputFormat, skipMigrations }) => {
// Parse the IPFS URL
let url
try {
url = ipfs ? new URL(ipfs) : undefined
} catch (e) {
toolbox.print.error(`Invalid IPFS URL: ${ipfs}
The IPFS URL must be of the following format: http(s)://host[:port]/[path]`)
return null
}
// Connect to the IPFS node (if a node address was provided)
ipfs = ipfs
? ipfsHttpClient({
protocol: url.protocol.replace(/[:]+$/, ''),
host: url.hostname,
port: url.port,
'api-path': url.pathname.replace(/\/$/, '') + '/api/v0/',
})
: undefined
return new Compiler({
ipfs,
beforeEach(() => {
fail = jest.fn()
stop = jest.fn()
succeed = jest.fn()
const spinner = {
fail,
stop,
succeed,
}
solidarityExtension(context)
context.print = {
spin: jest.fn(() => spinner),
error: jest.fn(),
}
context.strings = strings
context.system = {
run: jest.fn().mockResolvedValue(true),
spawn: jest.fn().mockReturnValue(
Promise.resolve({
stdout: 'you did it!',
status: 0,
})
),
}
})
const step = (spinner, subject, text) => {
if (text) {
spinner.stopAndPersist({
text: toolbox.print.colors.muted(`${subject} ${text}`),
})
} else {
spinner.stopAndPersist({ text: toolbox.print.colors.muted(subject) })
}
spinner.start()
return spinner
}
})
}
let subgraph = await this.loadSubgraph()
let compiledSubgraph = await this.compileSubgraph(subgraph)
let localSubgraph = await this.writeSubgraphToOutputDirectory(compiledSubgraph)
if (this.ipfs !== undefined) {
let ipfsHash = await this.uploadSubgraphToIPFS(localSubgraph)
this.completed(ipfsHash)
return ipfsHash
} else {
this.completed(path.join(this.options.outputDir, 'subgraph.yaml'))
return true
}
} catch (e) {
toolbox.print.error(e)
return false
}
}
onReady: () => (spinner = toolbox.print.spin('Watching subgraph files')),
onTrigger: async changedFile => {
completed(ipfsHashOrPath) {
toolbox.print.info('')
toolbox.print.success(`Build completed: ${chalk.blue(ipfsHashOrPath)}`)
toolbox.print.info('')
}
)
} else if (process.platform === 'darwin') {
toolbox.print.warning(
`Could not get access token from macOS Keychain: ${e.message}`,
)
} else if (process.platform === 'linux') {
toolbox.print.warning(
`Could not get access token from libsecret ` +
`(usually gnome-keyring or ksecretservice): ${e.message}`,
)
} else {
toolbox.print.warning(
`Could not get access token from OS secret storage service: ${e.message}`,
)
}
toolbox.print.info(`Continuing without an access token\n`)
}
}
}
const withSpinner = async (text, errorText, warningText, f) => {
let spinner = toolbox.print.spin(text)
try {
let result = await f(spinner)
if (typeof result === 'object') {
let hasWarning = Object.keys(result).indexOf('warning') >= 0
let hasResult = Object.keys(result).indexOf('result') >= 0
if (hasWarning && hasResult) {
if (result.warning !== null) {
spinner.warn(`${warningText}: ${result.warning}`)
}
spinner.succeed(text)
return result.result
} else {
spinner.succeed(text)
return result
}
} else {
const createJsonRpcClient = url => {
let params = {
host: url.hostname,
port: url.port,
path: url.pathname,
}
if (url.protocol === 'https:') {
return jayson.Client.https(params)
} else if (url.protocol === 'http:') {
return jayson.Client.http(params)
} else {
toolbox.print.error(
`Unsupported protocol: ${url.protocol.substring(0, url.protocol.length - 1)}`
)
toolbox.print.error(
'The Graph Node URL must be of the following format: http(s)://host[:port]/[path]'
)
return null
}
}