Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert source to TypeScript #54

Merged
merged 3 commits into from
Apr 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
},
"scripts": {
"build": "tsc -p tsconfig.json",
"test": "jest --config ./test/jest.config.json",
"prepare": "npm run build"
"test": "jest --config ./test/jest.config.json"
},
"files": [
"dist",
Expand Down Expand Up @@ -67,9 +66,16 @@
"typescript": "^3.4.5"
},
"devDependencies": {
"@types/ansi-escapes": "^4.0.0",
"@types/camelcase": "^5.2.0",
"@types/execa": "^0.9.0",
"@types/fs-extra": "^5.0.5",
"@types/mkdirp": "^0.5.2",
"@types/ms": "^0.7.30",
"@types/node": "^11.13.8",
"@types/ora": "^3.2.0",
"@types/rollup-plugin-json": "^3.0.2",
"@types/rollup-plugin-sourcemaps": "^0.4.2",
"husky": "^2.1.0",
"prettier": "^1.17.0",
"pretty-quick": "^1.10.0",
Expand Down
17 changes: 0 additions & 17 deletions src/constants.js

This file was deleted.

9 changes: 9 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { resolveApp } from './utils';

export const paths = {
jaredpalmer marked this conversation as resolved.
Show resolved Hide resolved
appPackageJson: resolveApp('package.json'),
testsSetup: resolveApp('test/setupTests.ts'),
appRoot: resolveApp('.'),
appSrc: resolveApp('src'),
appDist: resolveApp('dist'),
};
2 changes: 0 additions & 2 deletions src/createJestConfig.js → src/createJestConfig.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { appPackageJson } from './constants';
jaredpalmer marked this conversation as resolved.
Show resolved Hide resolved

export function createJestConfig(resolve, rootDir) {
return {
transform: {
Expand Down
4 changes: 2 additions & 2 deletions src/createRollupConfig.js → src/createRollupConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
removeScope,
external,
} from './utils';
import { paths, appPackageJson } from './constants';
import { paths } from './constants';
import { sizeSnapshot } from 'rollup-plugin-size-snapshot';
import { terser } from 'rollup-plugin-terser';
import babel from 'rollup-plugin-babel';
Expand Down Expand Up @@ -79,7 +79,7 @@ export function createRollupConfig(format, env, opts) {
'module',
'main',
opts.target !== 'node' ? 'browser' : undefined,
].filter(Boolean),
].filter(Boolean) as string[],
}),
format === 'umd' &&
commonjs({
Expand Down
12 changes: 12 additions & 0 deletions src/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
declare module 'asyncro';
declare module 'enquirer';
declare module 'jpjs';
declare module 'ora';
declare module 'sade';
declare module 'tiny-glob/sync';
jaredpalmer marked this conversation as resolved.
Show resolved Hide resolved

// Rollup plugins
declare module '@jaredpalmer/rollup-plugin-preserve-shebang';
declare module 'rollup-plugin-babel';
declare module 'rollup-plugin-size-snapshot';
declare module 'rollup-plugin-terser';
7 changes: 0 additions & 7 deletions src/getInstallArgs.js

This file was deleted.

10 changes: 10 additions & 0 deletions src/getInstallArgs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { InstallCmd } from './getInstallCmd';

export default function getInstallArgs(cmd: InstallCmd, packages: string[]) {
switch (cmd) {
case 'npm':
return ['install', ...packages, '--save-dev'];
jaredpalmer marked this conversation as resolved.
Show resolved Hide resolved
case 'yarn':
return ['add', ...packages, '--dev'];
}
}
6 changes: 4 additions & 2 deletions src/getInstallCmd.js → src/getInstallCmd.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import execa from 'execa';

let cmd;
let cmd: InstallCmd;

export default function getInstallCmd() {
export type InstallCmd = 'yarn' | 'npm';

export default function getInstallCmd(): InstallCmd {
if (cmd) {
return cmd;
}
Expand Down
32 changes: 14 additions & 18 deletions src/index.js → src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { rollup, watch } from 'rollup';
import asyncro from 'asyncro';
import chalk from 'chalk';
import util from 'util';
import fs from 'fs-extra';
import * as fs from 'fs-extra';
import jest from 'jest';
import logError from './logError';
import path from 'path';
Expand Down Expand Up @@ -43,15 +43,15 @@ try {
appPackageJson = fs.readJSONSync(resolveApp('package.json'));
} catch (e) {}

const stat = util.promisify(fs.stat);

export const isDir = name =>
stat(name)
fs
.stat(name)
.then(stats => stats.isDirectory())
.catch(() => false);

export const isFile = name =>
stat(name)
fs
.stat(name)
.then(stats => stats.isFile())
.catch(() => false);

Expand All @@ -66,8 +66,8 @@ async function jsOrTs(filename) {
}

async function getInputs(entries, source) {
let inputs = [];
let stub = [];
let inputs: any[] = [];
let stub: any[] = [];
stub
.concat(
entries && entries.length
Expand Down Expand Up @@ -197,7 +197,7 @@ prog
const installSpinner = ora(Messages.installing(deps)).start();
try {
const cmd = getInstallCmd();
await execa(cmd, getInstallArgs(getInstallCmd(), deps));
await execa(cmd, getInstallArgs(cmd, deps));
installSpinner.succeed('Installed dependecines');
console.log(Messages.start(pkg));
} catch (error) {
Expand Down Expand Up @@ -237,10 +237,7 @@ prog
module.exports = require('./${safeVariableName(
opts.name
)}.cjs.development.js')
}`,
{
overwrite: true,
}
aleclarson marked this conversation as resolved.
Show resolved Hide resolved
}`
);
} catch (e) {}
}
Expand Down Expand Up @@ -296,7 +293,7 @@ prog
const [cjsDev, cjsProd, ...otherConfigs] = createBuildConfigs(opts);
if (opts.format.includes('cjs')) {
try {
await mkdirp(resolveApp('./dist'));
await util.promisify(mkdirp)(resolveApp('./dist'));
jaredpalmer marked this conversation as resolved.
Show resolved Hide resolved
const promise = fs
.writeFile(
resolveApp('./dist/index.js'),
Expand All @@ -311,10 +308,7 @@ prog
module.exports = require('./${safePackageName(
opts.name
)}.cjs.development.js')
}`,
{
overwrite: true,
}
}`
)
.catch(e => logError(e));
logger(promise, 'Creating entry file');
Expand Down Expand Up @@ -362,7 +356,9 @@ prog
argv.push('--watchAll');
}

const maybeTestSetupFiledExists = await fs.exists(paths.testsSetup);
const maybeTestSetupFiledExists = await (fs.exists as any)(
paths.testsSetup
);
const setupTestsFile = maybeTestSetupFiledExists
? '<rootDir>/src/setupTests.ts'
: undefined;
Expand Down
File renamed without changes.
File renamed without changes.
9 changes: 2 additions & 7 deletions src/output.js → src/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ export const success = msg => {
console.log(`${chalk.green('> Success!')} ${msg}`);
};

export const time = () => {
const start = new Date();
return chalk.gray(`[${ms(new Date() - start)}]`);
jaredpalmer marked this conversation as resolved.
Show resolved Hide resolved
};

export const wait = msg => {
const spinner = ora(chalk.green(msg));
spinner.color = 'blue';
Expand All @@ -47,7 +42,7 @@ export const prompt = opts => {
const s = v.toString();

function cleanup() {
process.stdin.setRawMode(false);
process.stdin.setRawMode!(false);
process.stdin.removeListener('data', ondata);
}

Expand All @@ -64,7 +59,7 @@ export const prompt = opts => {
}
};

process.stdin.setRawMode(true);
process.stdin.setRawMode!(true);
process.stdin.resume();
process.stdin.on('data', ondata);
});
Expand Down
File renamed without changes.
15 changes: 6 additions & 9 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"include": ["src/**/*"],
"exclude": ["src/template/**/*"],
"compilerOptions": {
"allowJs": true,
"importHelpers": true,
Expand All @@ -8,13 +10,8 @@
"module": "commonjs",
"rootDir": "src",
"strict": true,
"noImplicitAny": false,
jaredpalmer marked this conversation as resolved.
Show resolved Hide resolved
"skipLibCheck": true,
"target": "es2017",
},
"include": [
"src/**/*"
],
"exclude": [
"src/template/**/*"
]
}
"target": "es2017"
}
}
Loading