From 3596939160b48ea088199ec10264a53dab12e5c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denny=20Korsuk=C3=A9witz?= Date: Tue, 21 Nov 2023 21:37:10 +0100 Subject: [PATCH] WIP --- generators/plugin/config.js | 14 +++++++++++--- generators/plugin/index.js | 4 +++- generators/readme/config.js | 2 +- src/helper.js | 18 +++++++++++------- 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/generators/plugin/config.js b/generators/plugin/config.js index e30a222..1d5a9b6 100644 --- a/generators/plugin/config.js +++ b/generators/plugin/config.js @@ -1,9 +1,17 @@ const config = { - name: 'README.md', - priority: 5, + name: 'Plugin', + priority: 2, versions: { '4.0.x': '', }, - prompts: [], + prompts: [ + { + name: 'plugin_name', + message: 'What is the name of your new plugin?', + type: 'input', + default: '${config.package_name_pascal_case}', + store: true, + }, + ], }; module.exports = config; \ No newline at end of file diff --git a/generators/plugin/index.js b/generators/plugin/index.js index 6b0a8e1..753ab72 100644 --- a/generators/plugin/index.js +++ b/generators/plugin/index.js @@ -31,6 +31,8 @@ module.exports = class extends Generator { `${chalk.green(config.generator_name)}`, ), ); + + generator_config.prompts = helper.InterpolatePrompts(this, config, generator_config.prompts); answers = await this.prompt(generator_config.prompts); } @@ -51,7 +53,7 @@ module.exports = class extends Generator { this.renderTemplate( this.templatePath('plugin.py'), - this.destinationPath(`${data.package_name}.py`), + this.destinationPath(`${data.package_name_pascal_case}.py`), data, ); } diff --git a/generators/readme/config.js b/generators/readme/config.js index e30a222..21dea8a 100644 --- a/generators/readme/config.js +++ b/generators/readme/config.js @@ -1,6 +1,6 @@ const config = { name: 'README.md', - priority: 5, + priority: 1, versions: { '4.0.x': '', }, diff --git a/src/helper.js b/src/helper.js index c806e61..c824fdd 100644 --- a/src/helper.js +++ b/src/helper.js @@ -14,13 +14,8 @@ async function InitConfig(Generator, GeneratorConfig) { config.generator = Generator._namespace; config.generator_config = GeneratorConfig; - if (config.init_config) { - return config; - } - // package directory name of current package config.package_dir = Generator.destinationRoot(); - config.init_config = true; config.file_list = await GetFileList(Generator, config); @@ -129,6 +124,9 @@ function GetAvailableGenerators(Generator, config) { let generators = config.generators_by_versions[config.sublime_version]; + console.log('generators'); + console.log(generators); + // skip README generator if file already exists if (config && config.file_list && config.file_list.includes('README.md')) { generators = generators.filter(function(generator_data) { @@ -176,12 +174,12 @@ function SetPackageName(Generator, config) { const name = config.package_dir.split(/[\\/]/).pop(); - config.package_seperator = '-'; - const package_name_split = name.split(config.package_seperator); + const package_name_split = name.split('-'); if (package_name_split.length == 2) { config.package_prefix = package_name_split.shift(); config.package_suffix = package_name_split.pop(); + config.package_seperator = '-'; } if (config && config.package_prefix && config.package_seperator && config.package_suffix) { @@ -191,6 +189,12 @@ function SetPackageName(Generator, config) { else { config.package_name_predicted = name; } + + if (config && config.package_name) { + + config.package_name_pascal_case = changeCase.pascalCase(config.package_name); + } + Generator.config.set('package_name_predicted', config.package_name_predicted); }