UNPKG

ember-cli

Version:

Command line tool for developing ambitious ember.js apps

109 lines (89 loc) 3.17 kB
'use strict'; const path = require('path'); const Command = require('../models/command'); const mergeBlueprintOptions = require('../utilities/merge-blueprint-options'); const merge = require('lodash/merge'); const SilentError = require('silent-error'); const ClassicOptions = [{ name: 'dummy', type: Boolean, default: false, aliases: ['dum', 'id'] }]; module.exports = Command.extend({ name: 'destroy', description: 'Destroys code generated by `generate` command.', aliases: ['d'], works: 'insideProject', availableOptions: [ { name: 'dry-run', type: Boolean, default: false, aliases: ['d'] }, { name: 'verbose', type: Boolean, default: false, aliases: ['v'] }, { name: 'pod', type: Boolean, default: false, aliases: ['p', 'pods'] }, { name: 'classic', type: Boolean, default: false, aliases: ['c'] }, { name: 'in-repo-addon', type: String, default: null, aliases: ['in-repo', 'ir'] }, { name: 'in', type: String, default: null, description: 'Runs a blueprint against an in repo addon. ' + 'A path is expected, relative to the root of the project.', }, { name: 'typescript', type: Boolean, aliases: ['ts'], description: 'Specifically destroys the TypeScript output of the `generate` command. Run `--no-typescript` to instead target the JavaScript output.', }, ], anonymousOptions: ['<blueprint>'], init() { this._super.apply(this, arguments); if (!this.isViteProject) { this.availableOptions = this.availableOptions.concat(ClassicOptions); } }, beforeRun: mergeBlueprintOptions, run(commandOptions, rawArgs) { if (this.isViteProject && commandOptions.dummy) { return Promise.reject( new SilentError('The `--dummy` option to `ember destroy` is not supported in Vite-based projects.') ); } let blueprintName = rawArgs[0]; let entityName = rawArgs[1]; if (!blueprintName) { return Promise.reject( new SilentError( 'The `ember destroy` command requires a ' + 'blueprint name to be specified. ' + 'For more details, use `ember help`.' ) ); } if (!entityName) { return Promise.reject( new SilentError( 'The `ember destroy` command requires an ' + 'entity name to be specified. ' + 'For more details, use `ember help`.' ) ); } let taskArgs = { args: rawArgs, }; if (this.settings && this.settings.usePods && !commandOptions.classic) { commandOptions.pod = true; } if (commandOptions.in) { let relativePath = path.relative(this.project.root, commandOptions.in); commandOptions.in = path.resolve(relativePath); } let taskOptions = merge(taskArgs, commandOptions || {}); if (this.project.initializeAddons) { this.project.initializeAddons(); } return this.runTask('DestroyFromBlueprint', taskOptions); }, printDetailedHelp() { let ui = this.ui; ui.writeLine(''); ui.writeLine(' Run `ember help generate` to view a list of available blueprints.'); }, });