Skip to content
This repository was archived by the owner on Apr 24, 2024. It is now read-only.

Commit c4465e5

Browse files
committed
feat(cli): add skip-cleanup parameter
1 parent 9faa1ad commit c4465e5

File tree

2 files changed

+49
-41
lines changed

2 files changed

+49
-41
lines changed

scripts/index.js

Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const {
2121
chunkFilename,
2222
afterInitialBuildHook,
2323
afterRebuildHook,
24+
skipCleanup,
2425
},
2526
} = require('../utils/cliHandler');
2627
const { getReactScriptsVersion, isEjected } = require('../utils');
@@ -129,49 +130,48 @@ config.plugins[htmlPluginIndex] = new HtmlWebpackPlugin({
129130
});
130131

131132
spinner.succeed();
132-
spinner.start('Clear destination folder');
133133

134134
let inProgress = false;
135135

136-
fs.emptyDir(paths.appBuild)
137-
.then(() => {
138-
spinner.succeed();
139-
140-
return new Promise((resolve, reject) => {
141-
const webpackCompiler = webpack(config);
142-
new webpack.ProgressPlugin(() => {
143-
if (!inProgress) {
144-
spinner.start('Start webpack watch');
145-
inProgress = true;
146-
}
147-
}).apply(webpackCompiler);
148-
149-
webpackCompiler.watch({}, (err, stats) => {
150-
if (err) {
151-
return reject(err);
152-
}
153-
154-
spinner.succeed();
155-
156-
runHook('after rebuild hook', spinner, afterRebuildHook);
157-
158-
inProgress = false;
159-
160-
if (verbose) {
161-
console.log();
162-
console.log(
163-
stats.toString({
164-
chunks: false,
165-
colors: true,
166-
})
167-
);
168-
console.log();
169-
}
170-
171-
return resolve();
172-
});
173-
});
174-
})
136+
Promise.resolve()
137+
.then(() => skipCleanup || clearDestinationFolder())
138+
.then(
139+
() =>
140+
new Promise((resolve, reject) => {
141+
const webpackCompiler = webpack(config);
142+
new webpack.ProgressPlugin(() => {
143+
if (!inProgress) {
144+
spinner.start('Start webpack watch');
145+
inProgress = true;
146+
}
147+
}).apply(webpackCompiler);
148+
149+
webpackCompiler.watch({}, (err, stats) => {
150+
if (err) {
151+
return reject(err);
152+
}
153+
154+
spinner.succeed();
155+
156+
runHook('after rebuild hook', spinner, afterRebuildHook);
157+
158+
inProgress = false;
159+
160+
if (verbose) {
161+
console.log();
162+
console.log(
163+
stats.toString({
164+
chunks: false,
165+
colors: true,
166+
})
167+
);
168+
console.log();
169+
}
170+
171+
return resolve();
172+
});
173+
})
174+
)
175175
.then(() => copyPublicFolder())
176176
.then(() => runHook('after initial build hook', spinner, afterInitialBuildHook));
177177

@@ -207,3 +207,8 @@ function handleBuildPath(userBuildPath) {
207207

208208
return path.join(process.cwd(), userBuildPath);
209209
}
210+
211+
function clearDestinationFolder() {
212+
spinner.start('Clear destination folder');
213+
return fs.emptyDir(paths.appBuild).then(() => spinner.succeed());
214+
}

utils/cliHandler.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ module.exports = meow(
6363
},
6464
'after-rebuild-hook': {
6565
type: 'string',
66-
}
66+
},
67+
'skip-cleanup': {
68+
type: 'boolean',
69+
},
6770
},
6871
}
6972
);

0 commit comments

Comments
 (0)