-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
16 changed files
with
306 additions
and
36 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env node | ||
process.env.NODE_ENV = process.env.NODE_ENV || 'development' | ||
|
||
const argv = require('./utils').getArgv() | ||
|
||
require('../dist/bootstrap-storybook').bootstrapStorybook(argv) |
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 |
---|---|---|
|
@@ -114,5 +114,5 @@ function getArgv() { | |
} | ||
|
||
module.exports = { | ||
getArgv | ||
getArgv, | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { BuildService } from '@types' | ||
|
||
import consola from 'consola' | ||
import rimraf from 'rimraf' | ||
import { resolve } from 'path' | ||
import { writeFileSync } from 'fs' | ||
import { getUserConfigSync } from 'src/utils' | ||
|
||
export function bootstrapStorybook(argv: BuildService.parsedArgs) { | ||
consola.info('clear cache') | ||
const rootDir = resolve(argv._[0] || '.') | ||
const storybookRootDir = resolve(argv._[0] || '.storybook') | ||
const storybookConfigPath = resolve(storybookRootDir, './storybook.build.config') | ||
|
||
rimraf.sync(storybookConfigPath) | ||
|
||
const config = getUserConfigSync('development', argv) | ||
|
||
delete config.webpack | ||
|
||
config.mode = process.env.NODE_ENV | ||
|
||
const template = `#!/usr/bin/env node | ||
const path = require('path') | ||
const rootDir = '${rootDir}' | ||
const resolve = function (p) { | ||
return path.resolve(rootDir, p) | ||
} | ||
const config = ${JSON.stringify(config, null, 2)} | ||
config.resolve = resolve | ||
module.exports = config | ||
` | ||
|
||
writeFileSync(storybookConfigPath, template, 'utf8') | ||
} |
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,4 +1,4 @@ | ||
import { getClientConfig } from './webpack.client.config' | ||
import { getClientConfig, getClientConfigSync } from './webpack.client.config' | ||
import { getServerConfig } from './webpack.server.config' | ||
|
||
export { getClientConfig, getServerConfig } | ||
export { getClientConfig, getServerConfig, getClientConfigSync } |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { ConfigOptions } from '@types' | ||
import { setWebpackSync } from 'src/utils' | ||
import consola from 'consola' | ||
|
||
/** | ||
* 使用现有的注入数据来解析用户的配置文件 | ||
* @param INJECT_CONTEXT 使用 yarn build-storybook 后, 生成的 .storybook/storybook.build.config | ||
* @param CONFIG 使用 yarn service:dev 后, 生成的 dist/xx/xx_config.js | ||
*/ | ||
export function resoveBuildConfig(INJECT_CONTEXT, CONFIG) { | ||
if (!INJECT_CONTEXT || !INJECT_CONTEXT.rootDir) { | ||
consola.fatal('[resoveBuildConfig] INJECT_CONTEXT is', INJECT_CONTEXT) | ||
process.exit(1) | ||
} | ||
if (!CONFIG) { | ||
consola.fatal('[resoveBuildConfig] CONFIG is', CONFIG) | ||
process.exit(1) | ||
} | ||
CONFIG = CONFIG.default(INJECT_CONTEXT) | ||
// console.log('--------------------------') | ||
// console.dir(INJECT_CONTEXT, { | ||
// depth: null | ||
// }) | ||
// console.log('--------------------------') | ||
// console.dir(CONFIG, { | ||
// depth: null | ||
// }) | ||
// console.log('--------------------------') | ||
const options: ConfigOptions.options = CONFIG | ||
options.rootDir = INJECT_CONTEXT.rootDir | ||
options.injectContext = INJECT_CONTEXT.injectContext | ||
setWebpackSync(options, INJECT_CONTEXT.mode) | ||
// console.log('--------------------------') | ||
// console.dir(options, { | ||
// depth: null | ||
// }) | ||
// console.log('--------------------------') | ||
return options | ||
} |
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.