mirror of
https://github.com/storybookjs/storybook.git
synced 2025-03-16 05:03:11 +08:00
Using babel-typescript instead of tsc
This commit is contained in:
parent
2fc1518e85
commit
1a5fa4b177
@ -1,6 +1,7 @@
|
||||
module.exports = {
|
||||
presets: [
|
||||
['@babel/preset-env', { shippedProposals: true, useBuiltIns: 'usage' }],
|
||||
'@babel/preset-typescript',
|
||||
'@babel/preset-react',
|
||||
'@babel/preset-flow',
|
||||
],
|
||||
|
@ -55,9 +55,11 @@
|
||||
"@babel/core": "^7.2.2",
|
||||
"@babel/plugin-proposal-class-properties": "^7.2.3",
|
||||
"@babel/plugin-proposal-export-default-from": "^7.2.0",
|
||||
"@babel/plugin-proposal-object-rest-spread": "^7.2.0",
|
||||
"@babel/preset-env": "^7.2.0",
|
||||
"@babel/preset-flow": "^7.0.0",
|
||||
"@babel/preset-react": "^7.0.0",
|
||||
"@babel/preset-typescript": "^7.1.0",
|
||||
"@emotion/snapshot-serializer": "^0.8.2",
|
||||
"@types/jest": "^23.3.9",
|
||||
"@types/node": "^10.12.17",
|
||||
|
@ -6,11 +6,28 @@ const shell = require('shelljs');
|
||||
function getCommand(watch) {
|
||||
const babel = path.join(__dirname, '..', 'node_modules', '.bin', 'babel');
|
||||
|
||||
const ignore = [
|
||||
'**/__mocks__/',
|
||||
'**/tests/',
|
||||
'**/__tests__/',
|
||||
'**/*.test.js',
|
||||
'**/*.test.ts',
|
||||
'**/stories/',
|
||||
'**/*.story.js',
|
||||
'**/*.story.ts',
|
||||
'**/*.stories.js',
|
||||
'**/*.stories.ts',
|
||||
'**/__snapshots__',
|
||||
'**/*.d.ts',
|
||||
];
|
||||
|
||||
const args = [
|
||||
'--ignore **/__mocks__/,**/tests/*,**/__tests__/,**/**.test.js,**/stories/,**/**.story.js,**/**.stories.js,**/__snapshots__',
|
||||
'./src --out-dir ./dist',
|
||||
'--copy-files',
|
||||
'./src',
|
||||
'--out-dir ./dist',
|
||||
`--config-file ${path.resolve(__dirname, '../.babelrc.js')}`,
|
||||
`--extensions ".js,.jsx,.ts,.tsx"`,
|
||||
`--copy-files`,
|
||||
`--ignore "${ignore.join('","')}"`,
|
||||
];
|
||||
|
||||
if (watch) {
|
||||
|
@ -6,7 +6,7 @@ const shell = require('shelljs');
|
||||
function getCommand(watch) {
|
||||
const tsc = path.join(__dirname, '..', 'node_modules', '.bin', 'tsc');
|
||||
|
||||
const args = ['--outDir ./dist', '-d true', '--listEmittedFiles true'];
|
||||
const args = ['--outDir ./dist', '--emitDeclarationOnly', '--listEmittedFiles true'];
|
||||
|
||||
if (watch) {
|
||||
args.push('-w');
|
||||
@ -25,7 +25,7 @@ function handleExit(code, errorCallback) {
|
||||
}
|
||||
}
|
||||
|
||||
function tscfy(options = {}) {
|
||||
function generateTSDefinitionFiles(options = {}) {
|
||||
const { watch = false, silent = true, errorCallback } = options;
|
||||
const tsConfigFile = 'tsconfig.json';
|
||||
|
||||
@ -49,5 +49,5 @@ function tscfy(options = {}) {
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
tscfy,
|
||||
generateTSDefinitionFiles,
|
||||
};
|
||||
|
@ -4,7 +4,7 @@ const shell = require('shelljs');
|
||||
const chalk = require('chalk');
|
||||
const log = require('npmlog');
|
||||
const { babelify } = require('./compile-js');
|
||||
const { tscfy } = require('./compile-ts');
|
||||
const { generateTSDefinitionFiles } = require('./compile-ts');
|
||||
|
||||
function getPackageJson() {
|
||||
const modulePath = path.resolve('./');
|
||||
@ -17,15 +17,15 @@ function removeDist() {
|
||||
shell.rm('-rf', 'dist');
|
||||
}
|
||||
|
||||
function removeTsFromDist() {
|
||||
function cleanup() {
|
||||
// add .ts filtering to babel args and remove after babel - 7 is adopted
|
||||
// --copy-files option doesn't work with --ignore
|
||||
// https://github.com/babel/babel/issues/5404
|
||||
|
||||
const tsFiles = shell.find('dist').filter(tsFile => tsFile.match(/\.ts$/));
|
||||
const files = shell.find('dist').filter(tsFile => tsFile.match(/\.(ts|tsx)$/));
|
||||
|
||||
if (tsFiles.length) {
|
||||
shell.rm(tsFiles);
|
||||
if (files.length) {
|
||||
shell.rm(files);
|
||||
}
|
||||
}
|
||||
|
||||
@ -38,12 +38,13 @@ function logError(type, packageJson) {
|
||||
const packageJson = getPackageJson();
|
||||
|
||||
removeDist();
|
||||
if (packageJson && packageJson.types && packageJson.types.indexOf('d.ts') !== -1) {
|
||||
tscfy({ errorCallback: () => logError('ts', packageJson) });
|
||||
} else {
|
||||
babelify({ errorCallback: () => logError('js', packageJson) });
|
||||
removeTsFromDist();
|
||||
tscfy({ errorCallback: () => logError('ts', packageJson) });
|
||||
}
|
||||
// if (packageJson && packageJson.types && packageJson.types.indexOf('d.ts') !== -1) {
|
||||
// tscfy({ errorCallback: () => logError('ts', packageJson) });
|
||||
// } else {
|
||||
babelify({ errorCallback: () => logError('js', packageJson) });
|
||||
cleanup();
|
||||
generateTSDefinitionFiles({ errorCallback: () => logError('ts', packageJson) });
|
||||
|
||||
// }
|
||||
|
||||
console.log(chalk.gray(`Built: ${chalk.bold(`${packageJson.name}@${packageJson.version}`)}`));
|
||||
|
@ -1119,7 +1119,7 @@
|
||||
"@babel/plugin-transform-react-jsx-self" "^7.0.0"
|
||||
"@babel/plugin-transform-react-jsx-source" "^7.0.0"
|
||||
|
||||
"@babel/preset-typescript@7.1.0":
|
||||
"@babel/preset-typescript@7.1.0", "@babel/preset-typescript@^7.1.0":
|
||||
version "7.1.0"
|
||||
resolved "https://registry.yarnpkg.com/@babel/preset-typescript/-/preset-typescript-7.1.0.tgz#49ad6e2084ff0bfb5f1f7fb3b5e76c434d442c7f"
|
||||
integrity sha512-LYveByuF9AOM8WrsNne5+N79k1YxjNB6gmpCQsnuSBAcV8QUeB+ZUxQzL7Rz7HksPbahymKkq2qBR+o36ggFZA==
|
||||
|
Loading…
x
Reference in New Issue
Block a user