-
-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
363d7ef
commit 1858637
Showing
22 changed files
with
232 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 25 additions & 25 deletions
50
programs/develop/commands/commands-lib/get-extension-config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,74 @@ | ||
import fs from 'fs' | ||
import path from 'path' | ||
import {Configuration} from 'webpack' | ||
import {FileConfig} from './config-types' | ||
import {DevOptions} from '../../commands/dev' | ||
import {BrowserConfig, FileConfig} from './config-types' | ||
import {DevOptions} from '../../commands/commands-lib/config-types' | ||
import * as messages from './messages' | ||
|
||
export function loadExtensionConfig(projectPath: string) { | ||
export async function loadCustomWebpackConfig(projectPath: string) { | ||
const userConfigPath = path.join(projectPath, 'extension.config.js') | ||
|
||
if (fs.existsSync(userConfigPath)) { | ||
if (isUsingExperimentalConfig(projectPath)) { | ||
const userConfig: FileConfig = require(userConfigPath) | ||
if (userConfig && userConfig != null) { | ||
if (userConfig && typeof userConfig!.config === 'function') { | ||
return userConfig!.config | ||
} | ||
if (await isUsingExperimentalConfig(projectPath)) { | ||
const userConfig: FileConfig = (await import(userConfigPath)).default | ||
if (userConfig && typeof userConfig.config === 'function') { | ||
return userConfig.config | ||
} | ||
} | ||
} | ||
|
||
return (config: Configuration) => config | ||
} | ||
|
||
export function loadCommandConfig( | ||
export async function loadCommandConfig( | ||
projectPath: string, | ||
command: 'dev' | 'build' | 'start' | 'preview' | ||
) { | ||
const userConfigPath = path.join(projectPath, 'extension.config.js') | ||
|
||
if (fs.existsSync(userConfigPath)) { | ||
if (isUsingExperimentalConfig(projectPath)) { | ||
const userConfig: any = require(userConfigPath) | ||
if (userConfig && userConfig != null) { | ||
return userConfig![command] | ||
if (await isUsingExperimentalConfig(projectPath)) { | ||
const userConfig: FileConfig = (await import(userConfigPath)).default | ||
if (userConfig) { | ||
// @ts-expect-error - TS doesn't know that command is a key of FileConfig['commands'] | ||
return userConfig[command] | ||
} | ||
} | ||
} | ||
|
||
return {} | ||
} | ||
|
||
export function loadBrowserConfig( | ||
export async function loadBrowserConfig( | ||
projectPath: string, | ||
browser: DevOptions['browser'] | ||
) { | ||
browser: DevOptions['browser'] = 'chrome' | ||
): Promise<BrowserConfig> { | ||
const userConfigPath = path.join(projectPath, 'extension.config.js') | ||
|
||
if (fs.existsSync(userConfigPath)) { | ||
if (isUsingExperimentalConfig(projectPath)) { | ||
const userConfig: any = require(userConfigPath) | ||
if (userConfig && userConfig.browsers != null) { | ||
return userConfig.browsers![browser] | ||
if (await isUsingExperimentalConfig(projectPath)) { | ||
const userConfig: FileConfig = (await import(userConfigPath)).default | ||
if (userConfig && userConfig.browser && userConfig.browser[browser]) { | ||
return userConfig.browser[browser] || {browser: 'chrome'} | ||
} | ||
} | ||
} | ||
|
||
return {} | ||
return { | ||
browser: 'chrome' | ||
} | ||
} | ||
|
||
let userMessageDelivered = false | ||
|
||
export function isUsingExperimentalConfig(projectPath: string) { | ||
export async function isUsingExperimentalConfig(projectPath: string) { | ||
const configPath = path.join(projectPath, 'extension.config.js') | ||
if (fs.existsSync(configPath)) { | ||
if (!userMessageDelivered) { | ||
console.log(messages.isUsingExperimentalConfig('extension.config.js')) | ||
userMessageDelivered = true | ||
} | ||
return true | ||
} else { | ||
return false | ||
} | ||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.