UNPKG

sfdx-hardis

Version:

Swiss-army-knife Toolbox for Salesforce. Allows you to define a complete CD/CD Pipeline. Orchestrate base commands and assist users with interactive wizards

70 lines 3.16 kB
/* jscpd:ignore-start */ import { SfCommand, Flags } from '@salesforce/sf-plugins-core'; import { Messages } from '@salesforce/core'; import c from 'chalk'; import fs from 'fs-extra'; import { glob } from 'glob'; import * as path from 'path'; import { uxLog } from '../../../../common/utils/index.js'; import { GLOB_IGNORE_PATTERNS } from '../../../../common/utils/projectUtils.js'; Messages.importMessagesDirectoryFromMetaUrl(import.meta.url); const messages = Messages.loadMessages('sfdx-hardis', 'org'); export default class CleanHiddenItems extends SfCommand { static title = 'Clean retrieved hidden items in dx sources'; static description = 'Remove unwanted hidden items within sfdx project sources'; static examples = ['$ sf hardis:project:clean:hiddenitems']; static flags = { folder: Flags.string({ char: 'f', default: 'force-app', description: 'Root folder', }), debug: Flags.boolean({ char: 'd', default: false, description: messages.getMessage('debugMode'), }), websocket: Flags.string({ description: messages.getMessage('websocket'), }), skipauth: Flags.boolean({ description: 'Skip authentication check when a default username is required', }), }; // Set this to true if your command requires a project workspace; 'requiresProject' is false by default static requiresProject = true; folder; debugMode = false; async run() { const { flags } = await this.parse(CleanHiddenItems); this.folder = flags.folder || './force-app'; this.debugMode = flags.debug || false; // Delete standard files when necessary uxLog(this, c.cyan(`Removing hidden dx managed source files`)); /* jscpd:ignore-end */ const rootFolder = path.resolve(this.folder); const findManagedPattern = rootFolder + `/**/*.{app,cmp,evt,tokens,html,css,js,xml}`; const matchingCustomFiles = await glob(findManagedPattern, { cwd: process.cwd(), ignore: GLOB_IGNORE_PATTERNS }); let counter = 0; for (const matchingCustomFile of matchingCustomFiles) { if (!fs.existsSync(matchingCustomFile)) { continue; } const fileContent = await fs.readFile(matchingCustomFile, 'utf8'); if (fileContent.startsWith('(hidden)')) { const componentFolder = path.dirname(matchingCustomFile); const folderSplit = componentFolder.split(path.sep); const toRemove = folderSplit.includes('lwc') || folderSplit.includes('aura') ? componentFolder : matchingCustomFile; await fs.remove(toRemove); uxLog(this, c.cyan(`Removed hidden item ${c.yellow(toRemove)}`)); counter++; } } // Summary const msg = `Removed ${c.green(c.bold(counter))} hidden source items`; uxLog(this, c.cyan(msg)); // Return an object to be displayed with --json return { outputString: msg }; } } //# sourceMappingURL=hiddenitems.js.map