Skip to content

Instantly share code, notes, and snippets.

@allenmichael
Created December 23, 2015 19:23
Show Gist options
  • Save allenmichael/e68bb06b3bdd26508047 to your computer and use it in GitHub Desktop.
Save allenmichael/e68bb06b3bdd26508047 to your computer and use it in GitHub Desktop.
A Grunt task to add to your Gruntfile.js
grunt.registerTask('delActionDomain', 'Deleting the specified action domain...', function(actionDomainName) {
//Load the Yeoman file as a variable
var yoFile = grunt.file.readJSON('./.yo-rc.json');
//Always delete dist folder and functions.json -- grunt build will recreate these files using manifests
grunt.file.delete('./assets/dist');
grunt.file.delete('./assets/functions.json');
if(actionDomainName) {
//Delete domain folder
grunt.file.delete('./assets/src/domains/' + actionDomainName);
//Retrieve each action listed in the Yeoman file
var actions = _.filter(yoFile['generator-mozu-actions'].actionNames, function(name) {
if(name.includes(actionDomainName)) {
return name;
}
});
//Delete unit tests for each action for the domain
_.each(actions, function(action) {
grunt.file.delete('./assets/test/' + action + '.t.js');
});
//Delete Action Domain manifest file
grunt.file.delete('./assets/src/' + actionDomainName + '.manifest.js');
//Alter Yeoman included actions
yoFile['generator-mozu-actions'].domains = _.without(yoFile['generator-mozu-actions'].domains, actionDomainName);
yoFile['generator-mozu-actions'].actionNames = _.difference(yoFile['generator-mozu-actions'].actionNames, actions);
var yoString = JSON.stringify(yoFile);
grunt.file.delete('./.yo-rc.json');
grunt.file.write('./.yo-rc.json', yoString);
}
//Rebuild
grunt.task.run('build');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment