UNPKG

@sprucelabs/spruce-cli

Version:

Command line interface for building Spruce skills.

47 lines 2.7 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const spruce_skill_utils_1 = require("@sprucelabs/spruce-skill-utils"); const AbstractWriter_1 = __importDefault(require("../../../writers/AbstractWriter")); class PermissionWriter extends AbstractWriter_1.default { async writeTypesFile(cwd, map) { const destination = spruce_skill_utils_1.diskUtil.resolveHashSprucePath(cwd, 'permissions', 'permissions.types.ts'); const contents = this.templates.permissionTypes({ contracts: map }); const files = await this.writeFileIfChangedMixinResults(destination, contents, 'Types file for any permission contracts you created or depend on.'); return files; } async writeCombinedFile(destinationDir, options) { const { contracts } = options; const destinationPath = spruce_skill_utils_1.diskUtil.resolveHashSprucePath(destinationDir, 'permissions'); const destinationFile = spruce_skill_utils_1.diskUtil.resolvePath(destinationPath, 'permissions.ts'); const local = contracts.map((c) => ({ nameCamel: spruce_skill_utils_1.namesUtil.toCamel(c.id), path: spruce_skill_utils_1.diskUtil.resolveRelativePath(destinationPath, c.path.replace('.ts', '')), })); const content = this.templates.permissions({ contracts: local }); const files = await this.writeFileIfChangedMixinResults(destinationFile, content, 'Import of all permission contracts for loading on boot!'); return files; } async writeContract(destinationDir, options) { const { nameReadable, nameKebab, nameCamel, description } = options; const destination = spruce_skill_utils_1.diskUtil.resolvePath(destinationDir, `${nameKebab}.permissions.ts`); const content = this.templates.permissionContractBuilder({ nameCamel, nameKebab, description, nameReadable, }); const files = await this.writeFileIfChangedMixinResults(destination, content, 'Your brand new permissions contract!'); return files; } writePlugin(cwd) { const destination = spruce_skill_utils_1.diskUtil.resolveHashSprucePath(cwd, 'features', 'permission.plugin.ts'); const pluginContents = this.templates.permissionPlugin(); const results = this.writeFileIfChangedMixinResults(destination, pluginContents, 'Enable permission support in your skill.'); return results; } } exports.default = PermissionWriter; //# sourceMappingURL=PermissionWriter.js.map