2018-03-18 23:41:14 +00:00
|
|
|
import path from 'path'
|
|
|
|
import fs from 'fs'
|
2018-09-18 14:26:41 +00:00
|
|
|
import klawSync from 'klaw-sync'
|
2018-03-27 22:28:17 +00:00
|
|
|
|
2018-03-19 07:22:35 +00:00
|
|
|
import _getPort from 'get-port'
|
2018-09-18 14:26:41 +00:00
|
|
|
import { defaultsDeep, find } from 'lodash'
|
2018-03-27 22:28:17 +00:00
|
|
|
import _rp from 'request-promise-native'
|
2018-10-17 21:28:25 +00:00
|
|
|
import corePkg from '../../packages/core/package.json'
|
|
|
|
|
|
|
|
import * as _Utils from '../../packages/common/src/index'
|
|
|
|
|
|
|
|
export { Nuxt } from '../../packages/core/src/index'
|
|
|
|
export { Builder, Generator } from '../../packages/builder/src/index'
|
2018-03-27 22:28:17 +00:00
|
|
|
|
|
|
|
export const rp = _rp
|
|
|
|
export const getPort = _getPort
|
2018-10-17 21:28:25 +00:00
|
|
|
export const version = corePkg.version
|
2018-03-18 23:41:14 +00:00
|
|
|
|
2018-10-17 21:28:25 +00:00
|
|
|
export const Utils = _Utils
|
|
|
|
export const Options = _Utils.Options
|
2018-03-27 22:28:17 +00:00
|
|
|
|
2018-08-17 20:25:23 +00:00
|
|
|
export const loadFixture = async function (fixture, overrides) {
|
2018-08-09 22:08:42 +00:00
|
|
|
const rootDir = path.resolve(__dirname, '..', 'fixtures', fixture)
|
2018-03-18 23:41:14 +00:00
|
|
|
const configFile = path.resolve(rootDir, 'nuxt.config.js')
|
|
|
|
|
2018-08-17 20:25:23 +00:00
|
|
|
const config = fs.existsSync(configFile) ? (await import(`../fixtures/${fixture}/nuxt.config`)).default : {}
|
2018-03-18 23:41:14 +00:00
|
|
|
|
|
|
|
config.rootDir = rootDir
|
|
|
|
config.dev = false
|
|
|
|
|
2018-03-19 04:21:04 +00:00
|
|
|
return defaultsDeep({}, overrides, config)
|
2018-03-18 23:41:14 +00:00
|
|
|
}
|
2018-06-06 12:31:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Prepare an object to pass to the createSportsSelectionView function
|
|
|
|
* @param {Function} condition return true to stop the waiting
|
|
|
|
* @param {Number} duration seconds totally wait
|
|
|
|
* @param {Number} interval milliseconds interval to check the condition
|
|
|
|
*
|
|
|
|
* @returns {Boolean} true: timeout, false: condition becomes true within total time
|
|
|
|
*/
|
|
|
|
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) {
|
|
|
|
await Utils.waitFor(interval)
|
|
|
|
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) {
|
|
|
|
// only return files that didn't exist before building
|
|
|
|
// and files that have been changed
|
|
|
|
options.filter = (item) => {
|
|
|
|
const foundItem = find(pathsBefore, (itemBefore) => {
|
|
|
|
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)
|
|
|
|
}
|