Skip to content

Commit

Permalink
breaking: rename package to dts-cli
Browse files Browse the repository at this point in the history
todos:
1. update readme
2. update template
3. add website
  • Loading branch information
aladdin-add committed Sep 6, 2021
1 parent 2d833c1 commit 006989c
Show file tree
Hide file tree
Showing 34 changed files with 497 additions and 482 deletions.
14 changes: 9 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "@weiran.zsd/tsdx",
"name": "dts-cli",
"version": "0.16.2",
"author": "唯然<weiran.zsd@outlook.com>",
"description": "Zero-config TypeScript package development",
"license": "MIT",
"homepage": "https://github.com/weiran-zsd/tsdx",
"homepage": "https://github.com/weiran-zsd/dts-cli",
"repository": {
"type": "git",
"url": "git+https://github.com/weiran-zsd/tsdx.git"
"url": "git+https://github.com/weiran-zsd/dts-cli.git"
},
"keywords": [
"react",
Expand All @@ -16,9 +16,11 @@
"rollup"
],
"bugs": {
"url": "https://github.com/weiran-zsd/tsdx/issues"
"url": "https://github.com/weiran-zsd/dts-cli/issues"
},
"bin": {
"dts": "./dist/index.js"
},
"bin": "./dist/index.js",
"scripts": {
"prepare": "tsc -p tsconfig.json",
"build": "tsc -p tsconfig.json",
Expand Down Expand Up @@ -74,6 +76,7 @@
"eslint-plugin-react": "^7.24.0",
"eslint-plugin-react-hooks": "^4.2.0",
"execa": "^4.0.3",
"figlet": "^1.5.2",
"fs-extra": "^9.0.0",
"jest": "^27.0.6",
"jest-watch-typeahead": "^0.5.0",
Expand All @@ -99,6 +102,7 @@
},
"devDependencies": {
"@types/eslint": "^6.1.2",
"@types/figlet": "^1.5.4",
"@types/fs-extra": "^9.0.1",
"@types/lodash": "^4.14.161",
"@types/node": "^14.11.1",
Expand Down
2 changes: 1 addition & 1 deletion src/babelPluginTsdx.ts → src/babelPluginDts-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const createConfigItems = (type: any, items: any[]) => {
});
};

export const babelPluginTsdx = createBabelInputPluginFactory(() => ({
export const babelPluginDts = createBabelInputPluginFactory(() => ({
// Passed the plugin options.
options({ custom: customOptions, ...pluginOptions }: any) {
return {
Expand Down
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const paths = {
appErrorsJson: resolveApp('errors/codes.json'),
appErrors: resolveApp('errors'),
appDist: resolveApp('dist'),
appConfig: resolveApp('tsdx.config.js'),
appConfig: resolveApp('dts.config.js'),
jestConfig: resolveApp('jest.config.js'),
progressEstimatorCache: resolveApp('node_modules/.cache/.progress-estimator'),
};
22 changes: 11 additions & 11 deletions src/createBuildConfigs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ import * as fs from 'fs-extra';
import { concatAllArray } from 'jpjs';

import { paths } from './constants';
import { TsdxOptions, NormalizedOpts } from './types';
import { DtsOptions, NormalizedOpts } from './types';

import { createRollupConfig } from './createRollupConfig';

// check for custom tsdx.config.js
let tsdxConfig = {
rollup(config: RollupOptions, _options: TsdxOptions): RollupOptions {
// check for custom dts.config.js
let dtsBuildConfig = {
rollup(config: RollupOptions, _options: DtsOptions): RollupOptions {
return config;
},
};

if (fs.existsSync(paths.appConfig)) {
tsdxConfig = require(paths.appConfig);
dtsBuildConfig = require(paths.appConfig);
}

export async function createBuildConfigs(
Expand All @@ -24,7 +24,7 @@ export async function createBuildConfigs(
const allInputs = concatAllArray(
opts.input.map((input: string) =>
createAllFormats(opts, input).map(
(options: TsdxOptions, index: number) => ({
(options: DtsOptions, index: number) => ({
...options,
// We want to know if this is the first run for each entryfile
// for certain plugins (e.g. css)
Expand All @@ -35,18 +35,18 @@ export async function createBuildConfigs(
);

return await Promise.all(
allInputs.map(async (options: TsdxOptions, index: number) => {
// pass the full rollup config to tsdx.config.js override
allInputs.map(async (options: DtsOptions, index: number) => {
// pass the full rollup config to dts-cli.config.js override
const config = await createRollupConfig(options, index);
return tsdxConfig.rollup(config, options);
return dtsBuildConfig.rollup(config, options);
})
);
}

function createAllFormats(
opts: NormalizedOpts,
input: string
): [TsdxOptions, ...TsdxOptions[]] {
): [DtsOptions, ...DtsOptions[]] {
return [
opts.format.includes('cjs') && {
...opts,
Expand Down Expand Up @@ -85,5 +85,5 @@ function createAllFormats(
env: 'production',
input,
},
].filter(Boolean) as [TsdxOptions, ...TsdxOptions[]];
].filter(Boolean) as [DtsOptions, ...DtsOptions[]];
}
12 changes: 6 additions & 6 deletions src/createRollupConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import typescript from 'rollup-plugin-typescript2';
import ts from 'typescript';

import { extractErrors } from './errors/extractErrors';
import { babelPluginTsdx } from './babelPluginTsdx';
import { TsdxOptions } from './types';
import { babelPluginDts } from './babelPluginDts-build';
import { DtsOptions } from './types';

const errorCodeOpts = {
errorMapFilePath: paths.appErrorsJson,
Expand All @@ -25,7 +25,7 @@ const errorCodeOpts = {
let shebang: any = {};

export async function createRollupConfig(
opts: TsdxOptions,
opts: DtsOptions,
outputNum: number
): Promise<RollupOptions> {
const findAndRecordErrorCodes = await extractErrors({
Expand Down Expand Up @@ -61,7 +61,7 @@ export async function createRollupConfig(
input: opts.input,
// Tell Rollup which packages to ignore
external: (id: string) => {
// bundle in polyfills as TSDX can't (yet) ensure they're installed as deps
// bundle in polyfills as DTS can't (yet) ensure they're installed as deps
if (id.startsWith('regenerator-runtime')) {
return false;
}
Expand All @@ -71,7 +71,7 @@ export async function createRollupConfig(
// Rollup has treeshaking by default, but we can optimize it further...
treeshake: {
// We assume reading a property of an object never has side-effects.
// This means tsdx WILL remove getters and setters defined directly on objects.
// This means dts WILL remove getters and setters defined directly on objects.
// Any getters or setters defined on classes will not be effected.
//
// @example
Expand Down Expand Up @@ -184,7 +184,7 @@ export async function createRollupConfig(
check: !opts.transpileOnly && outputNum === 0,
useTsconfigDeclarationDir: Boolean(tsCompilerOptions?.declarationDir),
}),
babelPluginTsdx({
babelPluginDts({
exclude: 'node_modules/**',
extensions: [...DEFAULT_BABEL_EXTENSIONS, 'ts', 'tsx'],
passPerPreset: true,
Expand Down
4 changes: 2 additions & 2 deletions src/deprecated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ export async function moveTypes() {

// see note above about deprecation window
console.warn(
'[tsdx]: Your rootDir is currently set to "./". Please change your ' +
'[dts]: Your rootDir is currently set to "./". Please change your ' +
'rootDir to "./src".\n' +
'TSDX has deprecated setting tsconfig.compilerOptions.rootDir to ' +
'DTS has deprecated setting tsconfig.compilerOptions.rootDir to ' +
'"./" as it caused buggy output for declarationMaps and more.\n' +
'You may also need to change your include to remove "test", which also ' +
'caused declarations to be unnecessarily created for test files.'
Expand Down
2 changes: 1 addition & 1 deletion src/errors/extractErrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export async function extractErrors(opts: any) {
}

if (!opts.name || !('name' in opts)) {
throw new Error('Missing options. Ensure you pass --name flag to tsdx');
throw new Error('Missing options. Ensure you pass --name flag to dts');
}

const errorMapFilePath = opts.errorMapFilePath;
Expand Down
19 changes: 6 additions & 13 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from 'rollup';
import asyncro from 'asyncro';
import chalk from 'chalk';
import figlet from 'figlet';
import * as fs from 'fs-extra';
import * as jest from 'jest';
import { CLIEngine } from 'eslint';
Expand Down Expand Up @@ -49,7 +50,7 @@ import { composePackageJson } from './templates/utils';
import * as deprecated from './deprecated';
const pkg = require('../package.json');

const prog = sade('tsdx');
const prog = sade('dts');

let appPackageJson: PackageJson;

Expand Down Expand Up @@ -100,7 +101,7 @@ async function getInputs(
prog
.version(pkg.version)
.command('create <pkg>')
.describe('Create a new package with TSDX')
.describe('Create a new package with DTS')
.example('create mypackage')
.option(
'--template',
Expand All @@ -111,15 +112,7 @@ prog
.example('create --template react mypackage')
.action(async (pkg: string, opts: any) => {
console.log(
chalk.blue(`
::::::::::: :::::::: ::::::::: ::: :::
:+: :+: :+: :+: :+: :+: :+:
+:+ +:+ +:+ +:+ +:+ +:+
+#+ +#++:++#++ +#+ +:+ +#++:+
+#+ +#+ +#+ +#+ +#+ +#+
#+# #+# #+# #+# #+# #+# #+#
### ######## ######### ### ###
`)
chalk.cyan(figlet.textSync('DTS', { horizontalLayout: 'full' }))
);
const bootSpinner = ora(`Creating ${chalk.bold.green(pkg)}...`);
let template;
Expand Down Expand Up @@ -569,8 +562,8 @@ prog
opts['_'] = defaultInputs;
console.log(
chalk.yellow(
`Defaulting to "tsdx lint ${defaultInputs.join(' ')}"`,
'\nYou can override this in the package.json scripts, like "lint": "tsdx lint src otherDir"'
`Defaulting to "dts lint ${defaultInputs.join(' ')}"`,
'\nYou can override this in the package.json scripts, like "lint": "dts lint src otherDir"'
)
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as Output from './output';

// This was copied from Razzle. Lots of unused stuff.
const program = {
name: 'tsdx',
name: 'dts',
};

export const help = function () {
Expand All @@ -20,7 +20,7 @@ export const missingProjectName = function () {
Please specify the project directory:
${chalk.cyan(program.name)} ${chalk.green('<project-directory>')}
For example:
${chalk.cyan(program.name)} ${chalk.green('my-tsdx-lib')}
${chalk.cyan(program.name)} ${chalk.green('my-dts-lib')}
Run ${chalk.cyan(`${program.name} --help`)} to see all options.
`;
};
Expand Down
14 changes: 8 additions & 6 deletions src/templates/basic.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Template } from './template';

//TODO: REPLACE `@weiran.zsd/tsdx` WITH `dts-cli`

const basicTemplate: Template = {
name: 'basic',
dependencies: [
Expand All @@ -23,11 +25,11 @@ const basicTemplate: Template = {
node: '>=10',
},
scripts: {
start: 'tsdx watch',
build: 'tsdx build',
test: 'tsdx test',
lint: 'tsdx lint',
prepare: 'tsdx build',
start: 'dts watch',
build: 'dts build',
test: 'dts test',
lint: 'dts lint',
prepare: 'dts build',
size: 'size-limit',
analyze: 'size-limit --why',
},
Expand All @@ -46,7 +48,7 @@ const basicTemplate: Template = {
*/
husky: {
hooks: {
'pre-commit': 'tsdx lint',
'pre-commit': 'dts lint',
},
},
prettier: {
Expand Down
2 changes: 1 addition & 1 deletion src/templates/react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const reactTemplate: Template = {
},
scripts: {
...basicTemplate.packageJson.scripts,
test: 'tsdx test --passWithNoTests',
test: 'dts test --passWithNoTests',
} as PackageJson['scripts'],
},
};
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export interface NormalizedOpts
format: [ModuleFormat, ...ModuleFormat[]];
}

export interface TsdxOptions extends SharedOpts {
export interface DtsOptions extends SharedOpts {
// Name of package
name: string;
// path to file
Expand Down
4 changes: 2 additions & 2 deletions templates/basic/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"skipLibCheck": true,
// error out if import and file system have a casing mismatch. Recommended by TS
"forceConsistentCasingInFileNames": true,
// `tsdx build` ignores this option, but it is commonly used when type-checking separately with `tsc`
"noEmit": true,
// `dts build` ignores this option, but it is commonly used when type-checking separately with `tsc`
"noEmit": true
}
}
4 changes: 2 additions & 2 deletions templates/react-with-storybook/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"skipLibCheck": true,
// error out if import and file system have a casing mismatch. Recommended by TS
"forceConsistentCasingInFileNames": true,
// `tsdx build` ignores this option, but it is commonly used when type-checking separately with `tsc`
"noEmit": true,
// `dts build` ignores this option, but it is commonly used when type-checking separately with `tsc`
"noEmit": true
}
}
2 changes: 1 addition & 1 deletion templates/react/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import * as React from 'react';

// Delete me
export const Thing = () => {
return <div>the snozzberries taste like snozzberries</div>;
return <div>Welcome to your first test package.</div>;
};
4 changes: 2 additions & 2 deletions templates/react/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"skipLibCheck": true,
// error out if import and file system have a casing mismatch. Recommended by TS
"forceConsistentCasingInFileNames": true,
// `tsdx build` ignores this option, but it is commonly used when type-checking separately with `tsc`
"noEmit": true,
// `dts build` ignores this option, but it is commonly used when type-checking separately with `tsc`
"noEmit": true
}
}
2 changes: 1 addition & 1 deletion test/e2e/fixtures/build-default/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"scripts": {
"build": "tsdx build"
"build": "dts build"
},
"name": "build-default",
"license": "MIT"
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/fixtures/build-default/package2.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"scripts": {
"build": "tsdx build"
"build": "dts build"
},
"name": "build-default-2",
"license": "MIT"
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/fixtures/build-invalid/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"scripts": {
"build": "tsdx build"
"build": "dts build"
},
"name": "build-invalid",
"license": "MIT"
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/fixtures/build-withTsconfig/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"scripts": {
"build": "tsdx build"
"build": "dts build"
},
"name": "build-withtsconfig",
"license": "MIT"
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/tsdx-build-default.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const testDir = 'e2e';
const fixtureName = 'build-default';
const stageName = `stage-${fixtureName}`;

describe('tsdx build :: zero-config defaults', () => {
describe('dts build :: zero-config defaults', () => {
beforeAll(() => {
util.teardownStage(stageName);
util.setupStageWithFixture(testDir, stageName, fixtureName);
Expand Down

0 comments on commit 006989c

Please sign in to comment.