@sprucelabs/spruce-cli
Version:
Command line interface for building Spruce skills.
130 lines • 5.32 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const setupVscodeOptions_schema_1 = __importDefault(require("./../../../.spruce/schemas/spruceCli/v2020_07_22/setupVscodeOptions.schema"));
const AbstractAction_1 = __importDefault(require("../../AbstractAction"));
class SetupAction extends AbstractAction_1.default {
invocationMessage = 'Setting up Visual Studio Codez... 👾';
recommendedExtensions = [
{
id: 'dbaeumer.vscode-eslint',
label: 'ESLint: Syntax validation and fixing. Formats your code on save for you.',
},
{
id: 'christian-kohler.npm-intellisense',
label: 'NPM Intellisense: Autocompletion for npm modules in your package.json.',
},
{
id: 'mikestead.dotenv',
label: 'ENV Formatting: Support for nice .env formatting right in vscode!',
},
{
id: 'yoavbls.pretty-ts-errors',
label: 'Pretty TypeScript Errors: Makes Typescript errors to make them much easier to read.',
},
];
optionsSchema = setupVscodeOptions_schema_1.default;
dependencies = [
{
name: 'eslint',
isDev: true,
},
{
name: 'eslint-config-spruce',
isDev: true,
},
];
async execute(options) {
const { all } = this.validateAndNormalizeOptions(options);
this.ui.startLoading('Checking state of vscode.');
const missing = await this.getMissingExtensions();
const choices = missing.map((ext) => ({
value: ext.id,
label: ext.label,
}));
const response = {
summaryLines: [],
};
const skipConfirmExtensions = all || missing.length === 0;
if (!skipConfirmExtensions) {
this.ui.stopLoading();
}
await this.optionallyInstallVscodeExtensions(skipConfirmExtensions, missing, choices, response);
this.ui.startLoading('Writing vscode configurations...');
const files = await this.Writer('vscode').writeVsCodeConfigurations(this.cwd, !all);
response.files = files;
response.packagesInstalled = [];
await this.optionallyInstallEsListModules(response, all);
response.hints = [
"Ok, now that that's done 😅, lets make sure Visual Studio Code can run tasks whenever you open this project.",
'',
'Step 1: Open the Command Palette (View -> Command Palette or cmd+shift+p) and type "Manage".',
'Step 2: Select "Tasks: Manage Automatic Tasks".',
'Step 3: Allow.',
'Step 4: Open the Command Palette (cmd+shift+p)).',
'Step 5: Select "Developer: Reload Window".',
'💪',
];
return response;
}
async optionallyInstallVscodeExtensions(skipConfirmExtensions, missing, choices, response) {
const answers = skipConfirmExtensions
? missing.map((m) => m.id)
: await this.ui.prompt({
type: 'select',
label: 'Which extensions should I install?',
isArray: true,
options: {
choices,
},
});
if (answers && answers?.length > 0) {
this.ui.startLoading(`Installing ${answers.length} extensions...`);
for (const answer of answers) {
response.summaryLines?.push(`Installed ${answer} extension.`);
}
await this.Service('vsCode').installExtensions(answers);
this.ui.stopLoading();
}
}
async optionallyInstallEsListModules(response, all) {
const pkg = this.Service('pkg');
for (const module of this.dependencies) {
if (!pkg.isInstalled(module.name)) {
;
(response.packagesInstalled ?? []).push(module);
}
}
if ((response.packagesInstalled ?? []).length > 0) {
await this.installEsLintModules(all, response, pkg);
}
}
async installEsLintModules(all, response, pkg) {
this.ui.stopLoading();
const shouldInstallPackages = all ||
(await this.ui.confirm('Last thing! Ready for me to install eslint modules?'));
this.ui.startLoading('Installing dev dependencies');
if (shouldInstallPackages) {
for (const module of response.packagesInstalled ?? []) {
await pkg.install(module.name, {
isDev: module.isDev,
});
}
}
}
async getMissingExtensions() {
const currentExtensions = await this.Service('vsCode').getVSCodeExtensions();
const missingExtensions = this.recommendedExtensions.filter((recommendedExtension) => {
const currentExtension = currentExtensions.find((e) => e === recommendedExtension.id);
if (currentExtension) {
return false;
}
return true;
});
return missingExtensions;
}
}
exports.default = SetupAction;
//# sourceMappingURL=SetupAction.js.map