feat: 🎸 add --clean flag to Storybook CLI

This commit is contained in:
streamich 2019-12-10 15:26:46 +01:00
parent a29a4476f4
commit 35e143d28d
2 changed files with 47 additions and 4 deletions

View file

@ -0,0 +1,31 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { ToolingLog } from '@kbn/dev-utils';
import { join } from 'path';
import del from 'del';
export const clean = async ({ log, rootDir }: { log: ToolingLog; rootDir: string }) => {
log.info('Cleaning Storybook build folder');
const dir = join(rootDir, 'built_assets', 'storybook');
log.info('Deleting folder:', dir);
await del([join(dir, '*')]);
await del([dir]);
};

View file

@ -20,6 +20,7 @@
import { join } from 'path';
import { run, createFlagError } from '@kbn/dev-utils';
import { storybookAliases } from './aliases';
import { clean } from './commands/clean';
const rootDir = join(__dirname, '..', '..', '..');
@ -30,6 +31,15 @@ run(
_: [alias],
} = flags;
if (flags.verbose) {
log.info('Flags:', flags);
}
if (flags.clean) {
await clean({ log, rootDir });
return;
}
if (!alias) {
throw createFlagError('missing alias');
}
@ -58,10 +68,12 @@ run(
Add your alias in src/dev/storybook/aliases.ts
`,
flags: {
boolean: ['fix'],
default: {
fix: false,
},
default: {},
string: [],
boolean: ['clean'],
help: `
--clean Clean Storybook build folder.
`,
},
}
);