Skip to content

Commit 313ccd9

Browse files
committed
feat(core): make config & schema faculative
1 parent bd5965f commit 313ccd9

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

packages/smooth-core/src/config/index.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,24 @@ import { parsePlugins } from './plugins'
99

1010
const exists = promisify(fs.exists)
1111

12-
export async function getConfig({ dev }) {
13-
const configPath = 'smooth.config.js'
14-
const localCwd = cwd()
15-
const absConfigPath = path.resolve(localCwd, configPath)
16-
const configExists = await exists(absConfigPath)
12+
async function mergeLocalConfig(configPath, defaultConfig) {
13+
const configExists = await exists(configPath)
1714

1815
if (!configExists) {
19-
throw new Error(`Error: config not found "${configPath}"`)
16+
return defaultConfig
2017
}
2118

2219
// eslint-disable-next-line global-require, import/no-dynamic-require
23-
const getLocalConfig = babelRequire(absConfigPath)
20+
const localConfig = babelRequire(configPath)
21+
const config = merge(defaultConfig, localConfig)
22+
if (localConfig.webpack) config.webpack = localConfig.webpack
23+
if (localConfig.webpackDevMiddleware)
24+
config.webpackDevMiddleware = localConfig.webpackDevMiddleware
25+
return config
26+
}
27+
28+
export async function getConfig({ dev }) {
29+
const localCwd = cwd()
2430

2531
const defaultConfig = {
2632
env: process.env.NODE_ENV || 'development',
@@ -41,8 +47,11 @@ export async function getConfig({ dev }) {
4147
webpackDevMiddleware: x => x,
4248
}
4349

44-
const localConfig = getLocalConfig
45-
const config = merge({}, defaultConfig, localConfig)
50+
const config = await mergeLocalConfig(
51+
path.resolve(localCwd, 'smooth.config.js'),
52+
defaultConfig,
53+
)
54+
4655
config.webpackConfig = await getWebpackConfig({ config, dev })
4756
config.plugins = parsePlugins(config.plugins)
4857
return config

packages/smooth-core/src/graphql/schema/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import fs from 'fs'
12
import merge from 'merge-deep'
3+
import { promisify } from 'util'
24
import path from 'path'
35
import glob from 'tiny-glob'
46
import { concatenateTypeDefs, makeExecutableSchema } from 'graphql-tools'
@@ -9,6 +11,8 @@ import { addContentTypeDefinitions } from './contentType'
911
import { applyAsyncHook } from '../../plugin'
1012
import babelRequire from '../../babel/require'
1113

14+
const exists = promisify(fs.exists)
15+
1216
function sanitizeDefinition(options) {
1317
return {
1418
typeDefs: options.typeDefs || null,
@@ -28,6 +32,8 @@ function mergeSchemaDefinitions(definitions) {
2832
}
2933

3034
export async function getDefinitionModules({ config }) {
35+
const schemasExists = await exists(config.schemasPath)
36+
if (!schemasExists) return []
3137
const files = await glob('**/*.js', { cwd: config.schemasPath })
3238
const defs = files.map(relativePath => {
3339
const absolutePath = path.join(config.schemasPath, relativePath)

0 commit comments

Comments
 (0)