2018-10-24 13:53:34 +00:00
|
|
|
import klawSync from 'klaw-sync'
|
2018-10-30 20:42:53 +00:00
|
|
|
import { waitFor } from '../../packages/common'
|
|
|
|
|
|
|
|
export { getNuxtConfig } from '../../packages/config'
|
2018-10-24 13:53:34 +00:00
|
|
|
export { default as getPort } from 'get-port'
|
|
|
|
export { default as rp } from 'request-promise-native'
|
2018-03-18 23:41:14 +00:00
|
|
|
|
2018-10-24 13:53:34 +00:00
|
|
|
export * from './nuxt'
|
2018-06-06 12:31:43 +00:00
|
|
|
|
2018-10-24 13:53:34 +00:00
|
|
|
// Pauses execution for a determined amount of time (`duration`)
|
|
|
|
// until `condition` is met. Also allows specifying the `interval`
|
|
|
|
// at which the condition is checked during the waiting period.
|
2018-06-06 12:31:43 +00:00
|
|
|
export const waitUntil = async function waitUntil(condition, duration = 20, interval = 250) {
|
|
|
|
let iterator = 0
|
|
|
|
const steps = Math.floor(duration * 1000 / interval)
|
|
|
|
|
|
|
|
while (!condition() && iterator < steps) {
|
2018-10-24 13:53:34 +00:00
|
|
|
await waitFor(interval)
|
2018-06-06 12:31:43 +00:00
|
|
|
iterator++
|
|
|
|
}
|
|
|
|
|
|
|
|
if (iterator === steps) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
2018-09-18 14:26:41 +00:00
|
|
|
|
|
|
|
export const listPaths = function listPaths(dir, pathsBefore = [], options = {}) {
|
|
|
|
if (Array.isArray(pathsBefore) && pathsBefore.length) {
|
2018-10-24 13:53:34 +00:00
|
|
|
// Only return files that didn't exist before building
|
2018-09-18 14:26:41 +00:00
|
|
|
// and files that have been changed
|
|
|
|
options.filter = (item) => {
|
2018-10-24 13:53:34 +00:00
|
|
|
const foundItem = pathsBefore.find((itemBefore) => {
|
2018-09-18 14:26:41 +00:00
|
|
|
return item.path === itemBefore.path
|
|
|
|
})
|
|
|
|
return typeof foundItem === 'undefined' ||
|
|
|
|
item.stats.mtimeMs !== foundItem.stats.mtimeMs
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return klawSync(dir, options)
|
|
|
|
}
|
|
|
|
|
|
|
|
export const equalOrStartsWith = function equalOrStartsWith(string1, string2) {
|
|
|
|
return string1 === string2 || string2.startsWith(string1)
|
|
|
|
}
|