(
state,
callback = async config => {
if (state.debug) {
console.log('getConfig():')
console.log(state)
}
return config
}
)
| 20 | |
| 21 | // Retrieves the static.config.js from the current project directory |
| 22 | export default function getConfig( |
| 23 | state, |
| 24 | callback = async config => { |
| 25 | if (state.debug) { |
| 26 | console.log('getConfig():') |
| 27 | console.log(state) |
| 28 | } |
| 29 | return config |
| 30 | } |
| 31 | ) { |
| 32 | const configPath = |
| 33 | state.configPath || |
| 34 | state.packageConfig.config || |
| 35 | DEFAULT_PATH_FOR_STATIC_CONFIG |
| 36 | |
| 37 | state = { |
| 38 | ...state, |
| 39 | originalConfig: configPath, |
| 40 | } |
| 41 | |
| 42 | const resolvedPath = nodePath.resolve(configPath) |
| 43 | |
| 44 | const noConfig = |
| 45 | configPath === DEFAULT_PATH_FOR_STATIC_CONFIG && !resolvedPath |
| 46 | |
| 47 | if (noConfig) { |
| 48 | // last |
| 49 | state = buildConfig(state, defaultConfig) |
| 50 | return callback(state).catch(console.error) |
| 51 | } |
| 52 | |
| 53 | state = buildConfigFromPath(state, resolvedPath || configPath) |
| 54 | |
| 55 | if (state.stage === 'dev') { |
| 56 | chokidar |
| 57 | .watch(resolvedPath, { |
| 58 | ignoreInitial: true, |
| 59 | }) |
| 60 | .on('all', async () => { |
| 61 | console.log('') |
| 62 | console.log(`Updating static.config.js`) |
| 63 | state = buildConfigFromPath(state, resolvedPath) |
| 64 | callback(state).catch(console.error) |
| 65 | }) |
| 66 | } |
| 67 | |
| 68 | return callback(state).catch(console.error) |
| 69 | } |
| 70 | |
| 71 | function buildConfigFromPath(state, configPath) { |
| 72 | delete require.cache[configPath] |
no test coverage detected
searching dependent graphs…