Skip to content

Commit

Permalink
(refactor): replace ensureDistFolder with fs.outputFile (#406)
Browse files Browse the repository at this point in the history
- fs.outputFile will create any directories that don't already exist

- also remove extraneous ensureDistFolder w/ try-catch in build command
  • Loading branch information
agilgur5 authored and jaredpalmer committed Jan 4, 2020
1 parent cfc1e76 commit ea124bc
Showing 1 changed file with 3 additions and 15 deletions.
18 changes: 3 additions & 15 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import jest from 'jest';
import { CLIEngine } from 'eslint';
import logError from './logError';
import path from 'path';
import mkdirp from 'mkdirp';
import rimraf from 'rimraf';
import execa from 'execa';
import shell from 'shelljs';
Expand Down Expand Up @@ -289,7 +288,6 @@ prog
if (!opts.noClean) {
await cleanDistFolder();
}
await ensureDistFolder();
opts.name = opts.name || appPackageJson.name;
opts.input = await getInputs(opts.entry, appPackageJson.source);
if (opts.format.includes('cjs')) {
Expand Down Expand Up @@ -396,16 +394,10 @@ prog
const opts = await normalizeOpts(dirtyOpts);
const buildConfigs = await createBuildConfigs(opts);
await cleanDistFolder();
await ensureDistFolder();
const logger = await createProgressEstimator();
if (opts.format.includes('cjs')) {
try {
await ensureDistFolder();
const promise = writeCjsEntryFile(opts.name).catch(logError);
logger(promise, 'Creating entry file');
} catch (e) {
logError(e);
}
const promise = writeCjsEntryFile(opts.name).catch(logError);
logger(promise, 'Creating entry file');
}
try {
const promise = asyncro
Expand Down Expand Up @@ -442,10 +434,6 @@ async function normalizeOpts(opts: WatchOpts): Promise<NormalizedOpts> {
};
}

function ensureDistFolder() {
return util.promisify(mkdirp)(paths.appDist);
}

async function cleanDistFolder() {
try {
await util.promisify(fs.access)(paths.appDist);
Expand All @@ -468,7 +456,7 @@ if (process.env.NODE_ENV === 'production') {
${baseLine}.cjs.development.js')
}
`;
return fs.writeFile(path.join(paths.appDist, 'index.js'), contents);
return fs.outputFile(path.join(paths.appDist, 'index.js'), contents);
}

function getAuthorName() {
Expand Down

0 comments on commit ea124bc

Please sign in to comment.