tsds-build
Version:
Development stack for TypeScript libraries
36 lines (35 loc) • 1.49 kB
JavaScript
var _ref;
import fs from 'fs';
import camelcase from 'lodash.camelcase';
import path from 'path';
import loadConfigSync from 'read-tsconfig-sync';
import { loadConfig } from 'tsds-lib';
export const pkg = JSON.parse(fs.readFileSync(path.join(process.cwd(), 'package.json'), 'utf8'));
const config = loadConfig();
if (!(config === null || config === void 0 ? void 0 : config.source)) throw new Error('Missing "source" in package.json or .tsdsrc.json. Add "source": "src/index.ts" (or .tsx) to your config.');
export const source = config.source;
const entry = (_ref = config === null || config === void 0 ? void 0 : config.entry) !== null && _ref !== void 0 ? _ref : source;
export const input = path.join.apply(null, [
process.cwd(),
...entry.split('/')
]);
export const name = camelcase(pkg.name);
export const globals = (config === null || config === void 0 ? void 0 : config.globals) || {};
const DEPS = [
'dependencies',
'optionalDependencies',
'peerDependencies'
];
DEPS.forEach((x)=>{
const deps = pkg[x] || {};
for(const name in deps){
if (globals[name] === undefined) console.log(`umd dependency ${name}is missing. Add a "tsds": { "globals": { "${name}": "SomeName" } } to your package.json`);
}
});
const _tsconfig = loadConfigSync(process.cwd());
if (!_tsconfig) throw new Error('Could not find tsconfig.json');
export const tsconfig = _tsconfig;
tsconfig.config.compilerOptions = {
...tsconfig.config.compilerOptions,
target: 'es5'
};