Skip to content

Commit

Permalink
chore: convert files to typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson committed Apr 30, 2019
1 parent ade861d commit 96df781
Show file tree
Hide file tree
Showing 15 changed files with 68 additions and 60 deletions.
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 = {
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';

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';

// 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'];
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
27 changes: 15 additions & 12 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 @@ -196,7 +196,8 @@ prog

const installSpinner = ora(Messages.installing(deps)).start();
try {
await execa(getInstallArgs(getInstallCmd(), deps));
const installArgs = getInstallArgs(getInstallCmd(), deps);
await execa(installArgs[0], installArgs.slice(1));
installSpinner.succeed('Installed dependecines');
console.log(Messages.start(pkg));
} catch (error) {
Expand Down Expand Up @@ -239,7 +240,7 @@ prog
}`,
{
overwrite: true,
}
} as fs.WriteFileOptions
);
} catch (e) {}
}
Expand Down Expand Up @@ -295,7 +296,7 @@ prog
const [cjsDev, cjsProd, ...otherConfigs] = createBuildConfigs(opts);
if (opts.format.includes('cjs')) {
try {
await mkdirp(resolveApp('./dist'));
await util.promisify(mkdirp)(resolveApp('./dist'));
const promise = fs
.writeFile(
resolveApp('./dist/index.js'),
Expand All @@ -313,7 +314,7 @@ prog
}`,
{
overwrite: true,
}
} as fs.WriteFileOptions
)
.catch(e => logError(e));
logger(promise, 'Creating entry file');
Expand Down Expand Up @@ -361,7 +362,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)}]`);
};

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,
"skipLibCheck": true,
"target": "es2017",
},
"include": [
"src/**/*"
],
"exclude": [
"src/template/**/*"
]
}
"target": "es2017"
}
}

0 comments on commit 96df781

Please sign in to comment.