mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-05 06:21:15 +08:00
Merge pull request #4485 from storybooks/angular-exclude-stories-issue4481
Exclude story files from angular app build
This commit is contained in:
commit
13876e77b9
@ -1,8 +1,15 @@
|
||||
import mergeDirs from 'merge-dirs';
|
||||
import path from 'path';
|
||||
import { getVersions, getPackageJson, writePackageJson, installBabel } from '../../lib/helpers';
|
||||
import {
|
||||
getVersions,
|
||||
getPackageJson,
|
||||
writePackageJson,
|
||||
installBabel,
|
||||
getAngularAppTsConfigJson,
|
||||
writeAngularAppTsConfig,
|
||||
} from '../../lib/helpers';
|
||||
|
||||
export default async npmOptions => {
|
||||
async function addDependencies(npmOptions) {
|
||||
const [
|
||||
storybookVersion,
|
||||
notesVersion,
|
||||
@ -17,7 +24,6 @@ export default async npmOptions => {
|
||||
'@storybook/addon-links',
|
||||
'@storybook/addons'
|
||||
);
|
||||
mergeDirs(path.resolve(__dirname, 'template'), '.', 'overwrite');
|
||||
|
||||
const packageJson = getPackageJson();
|
||||
|
||||
@ -35,4 +41,27 @@ export default async npmOptions => {
|
||||
packageJson.scripts['build-storybook'] = 'build-storybook';
|
||||
|
||||
writePackageJson(packageJson);
|
||||
}
|
||||
|
||||
function editAngularAppTsConfig() {
|
||||
const tsConfigJson = getAngularAppTsConfigJson();
|
||||
const glob = '**/*.stories.ts';
|
||||
if (!tsConfigJson) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { exclude = [] } = tsConfigJson;
|
||||
if (exclude.includes(glob)) {
|
||||
return;
|
||||
}
|
||||
|
||||
tsConfigJson.exclude = [...exclude, glob];
|
||||
writeAngularAppTsConfig(tsConfigJson);
|
||||
}
|
||||
|
||||
export default async npmOptions => {
|
||||
mergeDirs(path.resolve(__dirname, 'template'), '.', 'overwrite');
|
||||
|
||||
await addDependencies(npmOptions);
|
||||
editAngularAppTsConfig();
|
||||
};
|
||||
|
@ -62,6 +62,46 @@ export function getBowerJson() {
|
||||
return JSON.parse(jsonContent);
|
||||
}
|
||||
|
||||
export function getAngularJson() {
|
||||
const angularJsonPath = path.resolve('angular.json');
|
||||
if (!fs.existsSync(angularJsonPath)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const jsonContent = fs.readFileSync(angularJsonPath, 'utf8');
|
||||
return JSON.parse(jsonContent);
|
||||
}
|
||||
|
||||
export function getAngularAppTsConfigPath() {
|
||||
const angularJson = getAngularJson();
|
||||
const { defaultProject } = angularJson;
|
||||
const tsConfigPath = angularJson.projects[defaultProject].architect.build.options.tsConfig;
|
||||
|
||||
if (!tsConfigPath || !fs.existsSync(path.resolve(tsConfigPath))) {
|
||||
return false;
|
||||
}
|
||||
return tsConfigPath;
|
||||
}
|
||||
|
||||
export function getAngularAppTsConfigJson() {
|
||||
const tsConfigPath = getAngularAppTsConfigPath();
|
||||
|
||||
if (!tsConfigPath || !fs.existsSync(path.resolve(tsConfigPath))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const jsonContent = fs.readFileSync(tsConfigPath, 'utf8');
|
||||
return JSON.parse(jsonContent);
|
||||
}
|
||||
|
||||
export function writeAngularAppTsConfig(tsConfigJson) {
|
||||
const content = `${JSON.stringify(tsConfigJson, null, 2)}\n`;
|
||||
const tsConfigPath = getAngularAppTsConfigPath();
|
||||
if (tsConfigPath) {
|
||||
fs.writeFileSync(path.resolve(tsConfigPath), content, 'utf8');
|
||||
}
|
||||
}
|
||||
|
||||
export function writePackageJson(packageJson) {
|
||||
const content = `${JSON.stringify(packageJson, null, 2)}\n`;
|
||||
const packageJsonPath = path.resolve('package.json');
|
||||
|
Loading…
x
Reference in New Issue
Block a user