feat(@embark/embark-reset): allow users to specify files to be removed in reset

This commit introduces a feature where users can specify which files should be removed
as part of Embark's `reset` command.

This is done by specifying the `options.reset` section in a project's `embark.json`.
The possible options are `defaults: bool` and `files: Array<String>`:

```
// embark.json
{
  ...
  "options": {
    "reset": {
      "defaults": true,
      "files": ["some.file", "some/other.file"]
    }
  }
}
```

`defaults` tells Embark whether or not it should remove the default files that are
defined by the `reset` command. Setting it to `false` will prevent Embark from
removing any of these (mostly files located inside `.embark`).

This gives users fine control as they now can re-add subsets or those file paths
in the `files` property.

If `options.reset` doesn't exist Embark will do the default behaviour, which is
is simply resetting/removing the files it has always removed.

It now also honors `generationDir` and `buildDir` as part of the defaults.
This commit is contained in:
Pascal Precht 2019-04-12 10:54:08 +02:00 committed by Pascal Precht
parent a4f68cb0ee
commit b8357b77bf
2 changed files with 26 additions and 6 deletions

View File

@ -354,7 +354,9 @@ class Cmd {
embark.initConfig('development', {
embarkConfig: 'embark.json', interceptLogs: false
});
embark.reset();
embark.reset({
embarkConfig: 'embark.json'
});
});
}

View File

@ -1,7 +1,8 @@
let async = require('async');
const constants = require('../lib/constants');
const Logger = require('../lib/core/logger');
const {reset: embarkReset} = require('embark-reset');
const {reset: embarkReset, paths: defaultResetPaths} = require('embark-reset');
const fs = require('../lib/core/fs.js');
require('colors');
@ -408,13 +409,30 @@ class EmbarkController {
}
async reset() {
const doneMessage = __("reset done!").green;
await embarkReset({doneMessage});
async reset(options) {
const embarkConfig = require(fs.dappPath(options.embarkConfig || 'embark.json'));
let removePaths = [];
let defaultPaths = [...defaultResetPaths];
defaultPaths.push(embarkConfig.buildDir);
embarkConfig.generationDir && defaultPaths.push(embarkConfig.generationDir);
if (embarkConfig.options && embarkConfig.options.reset) {
if (embarkConfig.options.reset.defaults) {
removePaths = removePaths.concat(defaultPaths);
}
if (embarkConfig.options.reset.files) {
removePaths = removePaths.concat(embarkConfig.options.reset.files);
}
} else {
removePaths = defaultPaths;
}
removePaths = [...new Set(removePaths.map(path => path.charAt(path.length - 1) === '/' ? path.substr(0, path.length - 1) : path))];
await embarkReset({removePaths});
}
ejectWebpack() {
var fs = require('../lib/core/fs.js');
var embarkConfig = fs.embarkPath('dist/lib/modules/pipeline/webpack.config.js');
var dappConfig = fs.dappPath('webpack.config.js');
fs.copyPreserve(embarkConfig, dappConfig);