Skip to content
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"mkdirp": "^0.5.1",
"ms": "^2.1.1",
"ora": "^3.0.0",
"progress-estimator": "^0.2.2",
"rollup": "^0.66.4",
"rollup-plugin-babel": "^4.0.3",
"rollup-plugin-commonjs": "^9.1.8",
Expand Down
31 changes: 27 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,20 @@ import { paths } from './constants';
import * as Messages from './messages';
import { createRollupConfig } from './createRollupConfig';
import { createJestConfig } from './createJestConfig';
import { safeVariableName, resolveApp, safePackageName } from './utils';
import {
safeVariableName,
resolveApp,
safePackageName,
clearConsole,
} from './utils';
import * as Output from './output';
import { concatAllArray } from 'jpjs';
const createLogger = require('progress-estimator');
// All configuration keys are optional, but it's recommended to specify a storage location.
// Learn more about configuration options below.
const logger = createLogger({
storagePath: path.join(__dirname, '.progress-estimator'),
});

const prog = sade('tsdx');

Expand Down Expand Up @@ -186,7 +197,7 @@ prog
);
} catch (e) {}
}

const spinner = ora().start();
await watch(
[cjsDev, cjsProd, ...otherConfigs].map(inputOptions => ({
watch: {
Expand All @@ -197,13 +208,23 @@ prog
...inputOptions,
}))
).on('event', async event => {
if (event.code === 'START') {
clearConsole();
spinner.start(chalk.bold.cyan('Compiling modules...'));
}
if (event.code === 'ERROR') {
spinner.fail(chalk.bold.red('Failed to compile'));
logError(event.error);
}
if (event.code === 'FATAL') {
spinner.fail(chalk.bold.red('Failed to compile'));
logError(event.error);
}
if (event.code === 'END') {
spinner.succeed(chalk.bold.green('Compiled successfully'));
console.log(`
${chalk.dim('Watching for changes')}
`);
try {
await moveTypes();
} catch (_error) {}
Expand All @@ -228,7 +249,7 @@ prog
const [cjsDev, cjsProd, ...otherConfigs] = createBuildConfigs(opts);
if (opts.format.includes('cjs')) {
try {
await fs.writeFile(
const promise = fs.writeFile(
resolveApp('dist/index.js'),
`
'use strict'
Expand All @@ -246,16 +267,18 @@ prog
overwrite: true,
}
);
logger(promise, 'Creating entry file');
} catch (e) {}
}
try {
await asyncro.map(
const promise = asyncro.map(
[cjsDev, cjsProd, ...otherConfigs],
async inputOptions => {
let bundle = await rollup(inputOptions);
await bundle.write(inputOptions.output);
}
);
logger(promise, 'Building modules');
await moveTypes();
} catch (error) {
logError(error);
Expand Down
8 changes: 8 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,11 @@ export const appDirectory = fs.realpathSync(process.cwd());
export const resolveApp = function(relativePath) {
return path.resolve(appDirectory, relativePath);
};

// Taken from Create React App, react-dev-utils/clearConsole
// @see https://github.com/facebook/create-react-app/blob/master/packages/react-dev-utils/clearConsole.js
export function clearConsole() {
process.stdout.write(
process.platform === 'win32' ? '\x1B[2J\x1B[0f' : '\x1B[2J\x1B[3J\x1B[H'
);
}
17 changes: 16 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1143,7 +1143,7 @@ cli-cursor@^2.0.0, cli-cursor@^2.1.0:
dependencies:
restore-cursor "^2.0.0"

cli-spinners@^1.1.0:
cli-spinners@^1.1.0, cli-spinners@^1.3.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/cli-spinners/-/cli-spinners-1.3.1.tgz#002c1990912d0d59580c93bd36c056de99e4259a"
integrity sha512-1QL4544moEsDVH9T/l6Cemov/37iv1RtoKf7NJ04A60+4MREXNfx/QvavbH6QoGdsD4N4Mwy49cmaINR/o2mdg==
Expand Down Expand Up @@ -2387,6 +2387,11 @@ https-browserify@^1.0.0:
resolved "https://registry.yarnpkg.com/https-browserify/-/https-browserify-1.0.0.tgz#ec06c10e0a34c0f2faf199f7fd7fc78fffd03c73"
integrity sha1-7AbBDgo0wPL68Zn3/X/Hj//QPHM=

humanize-duration@^3.15.3:
version "3.17.0"
resolved "https://registry.yarnpkg.com/humanize-duration/-/humanize-duration-3.17.0.tgz#a2cec75f9329ce68f8797b23d31d1f988992d11b"
integrity sha512-9em7CXFa0my1DF3aIQg0sTRyAX2znEOMHolUvu9nSTUjS+bRD32y0MH+Hnm3Xu0cSWrxpYb2isXSfH9pF2LP8g==

husky@^1.3.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/husky/-/husky-1.3.1.tgz#26823e399300388ca2afff11cfa8a86b0033fae0"
Expand Down Expand Up @@ -4435,6 +4440,16 @@ process@^0.11.10:
resolved "https://registry.yarnpkg.com/process/-/process-0.11.10.tgz#7332300e840161bda3e69a1d1d91a7d4bc16f182"
integrity sha1-czIwDoQBYb2j5podHZGn1LwW8YI=

progress-estimator@^0.2.2:
version "0.2.2"
resolved "https://registry.yarnpkg.com/progress-estimator/-/progress-estimator-0.2.2.tgz#1c3947a5782ea56e40c8fccc290ac7ceeb1b91cb"
integrity sha512-GF76Ac02MTJD6o2nMNtmtOFjwWCnHcvXyn5HOWPQnEMO8OTLw7LAvNmrwe8LmdsB+eZhwUu9fX/c9iQnBxWaFA==
dependencies:
chalk "^2.4.1"
cli-spinners "^1.3.1"
humanize-duration "^3.15.3"
log-update "^2.3.0"

promise-inflight@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/promise-inflight/-/promise-inflight-1.0.1.tgz#98472870bf228132fcbdd868129bad12c3c029e3"
Expand Down