From fba40afe1c03d9e35dbbcb1f0d57001dcbeb7a52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denny=20Korsuk=C3=A9witz?= Date: Tue, 21 Nov 2023 14:11:46 +0100 Subject: [PATCH] WIP --- .github/settings.yml | 2 +- README.md | 68 +++++++++-------- generators/app/USAGE | 16 ++-- generators/app/config.js | 54 ++++++++------ generators/app/index.js | 26 ++++--- generators/app/templates/.gitattributes | 12 +++ generators/app/templates/.gitignore | 3 + generators/app/templates/changelog.txt | 11 +++ generators/app/templates/dummyfile.txt | 0 generators/app/templates/install.txt | 9 +++ generators/app/templates/messages.json | 4 + generators/app/templates/version.txt | 13 ++++ generators/readme/USAGE | 8 ++ generators/readme/config.js | 13 ++++ generators/readme/index.js | 76 +++++++++++++++++++ generators/readme/templates/README.md | 97 +++++++++++++++++++++++++ package.json | 41 ++++++----- src/helper.js | 85 ++++++++++++++++++---- 18 files changed, 433 insertions(+), 105 deletions(-) create mode 100644 generators/app/templates/.gitattributes create mode 100644 generators/app/templates/.gitignore create mode 100644 generators/app/templates/changelog.txt delete mode 100644 generators/app/templates/dummyfile.txt create mode 100644 generators/app/templates/install.txt create mode 100644 generators/app/templates/messages.json create mode 100644 generators/app/templates/version.txt create mode 100644 generators/readme/USAGE create mode 100644 generators/readme/config.js create mode 100644 generators/readme/index.js create mode 100644 generators/readme/templates/README.md diff --git a/.github/settings.yml b/.github/settings.yml index 29d9f2c..1e40e40 100644 --- a/.github/settings.yml +++ b/.github/settings.yml @@ -3,7 +3,7 @@ repository: name: generator-sublime-package # A short description of the repository that will show up on GitHub - description: Todo + description: Sublime-Package is a Sublime Text package generator for yeoman, which creates scaffold for a sublime-package. # A URL with more information about the repository homepage: https://dennykorsukewitz.github.io/generator-sublime-package/ diff --git a/README.md b/README.md index 7773095..1c4e847 100644 --- a/README.md +++ b/README.md @@ -2,22 +2,17 @@ # Sublime-Package -**Sublime-Package** is a Sublime Text package generator for [yeoman](https://yeoman.io/). - -We are all lazy 🦥 and only want to code 👨‍💻 if it is not already exists. +**Sublime-Package** is a Sublime Text package generator for [yeoman](https://yeoman.io/), which creates scaffold for a sublime-package. +We are all lazy 🦥 and only want to code 👨‍💻 if it is not already exists. \ So i created this yeoman generator to easy get an scaffold for a sublime-package. | Repository | GitHub | NPM | | ------ | ------ | ------ | -| ![GitHub release (latest by date)](https://img.shields.io/github/v/release/dennykorsukewitz/generator-sublime-package) | ![GitHub open issues](https://img.shields.io/github/issues/dennykorsukewitz/generator-sublime-package) ![GitHub closed issues](https://img.shields.io/github/issues-closed/dennykorsukewitz/generator-sublime-package?color=#44CC44) | ![npm](https://img.shields.io/npm/dy/generator-sublime-package) | -| ![GitHub license](https://img.shields.io/github/license/dennykorsukewitz/generator-sublime-package) | ![GitHub pull requests](https://img.shields.io/github/issues-pr/dennykorsukewitz/generator-sublime-package?label=PR) ![GitHub closed pull requests](https://img.shields.io/github/issues-pr-closed/dennykorsukewitz/generator-sublime-package?color=g&label=PR) | ![npm](https://img.shields.io/npm/dm/generator-sublime-package) | -| ![GitHub language count](https://img.shields.io/github/languages/count/dennykorsukewitz/generator-sublime-package?style=flat&label=language) | ![GitHub contributors](https://img.shields.io/github/contributors/dennykorsukewitz/generator-sublime-package) | ![npm](https://img.shields.io/npm/dw/generator-sublime-package) | -| ![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/dennykorsukewitz/generator-sublime-package) | ![GitHub downloads](https://img.shields.io/github/downloads/dennykorsukewitz/generator-sublime-package/total?style=flat) | ![npm](https://img.shields.io/npm/dt/generator-sublime-package) | - -todo -![npm bundle size](https://img.shields.io/bundlephobia/min/generator-sublime-package) -![npm collaborators](https://img.shields.io/npm/collaborators/generator-sublime-package) +| ![GitHub release (latest by date)](https://img.shields.io/github/v/release/dennykorsukewitz/generator-sublime-package) | ![GitHub open issues](https://img.shields.io/github/issues/dennykorsukewitz/generator-sublime-package) ![GitHub closed issues](https://img.shields.io/github/issues-closed/dennykorsukewitz/generator-sublime-package?color=#44CC44) | ![npm version](https://badge.fury.io/js/generator-sublime-package.svg) | +| ![GitHub license](https://img.shields.io/github/license/dennykorsukewitz/generator-sublime-package) | ![GitHub pull requests](https://img.shields.io/github/issues-pr/dennykorsukewitz/generator-sublime-package?label=PR) ![GitHub closed pull requests](https://img.shields.io/github/issues-pr-closed/dennykorsukewitz/generator-sublime-package?color=g&label=PR) | ![npm bundle size](https://img.shields.io/bundlephobia/min/generator-sublime-package) ![npm collaborators](https://img.shields.io/npm/collaborators/generator-sublime-package) | +| ![GitHub language count](https://img.shields.io/github/languages/count/dennykorsukewitz/generator-sublime-package?style=flat&label=language) | ![GitHub contributors](https://img.shields.io/github/contributors/dennykorsukewitz/generator-sublime-package) | ![npm](https://img.shields.io/npm/dy/generator-sublime-package) ![npm](https://img.shields.io/npm/dm/generator-sublime-package) | +| ![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/dennykorsukewitz/generator-sublime-package) | ![GitHub downloads](https://img.shields.io/github/downloads/dennykorsukewitz/generator-sublime-package/total?style=flat) | ![npm](https://img.shields.io/npm/dw/generator-sublime-package) ![npm](https://img.shields.io/npm/dt/generator-sublime-package) | | Status | | ------ | @@ -25,28 +20,22 @@ todo --- -TODO - -[![Node.js](https://img.shields.io/badge/nodejs-16.13.0-blue.svg)](https://github.com/nodejs/node) -[![yeoman-generator version](https://badge.fury.io/js/yeoman-generator.svg)](https://badge.fury.io/js/yeoman-generator) -[![yo version](https://badge.fury.io/js/yo.svg)](https://badge.fury.io/js/yo) - -![Yeoman](doc/images/Yeoman_Logo.png) +## Feature -We use the Yeoman as a node.js module. +The following files can be created. +- .gitattributes +- .gitignore +- messages/changelog.txt +- messages/install.txt +- messages/version.txt +- messages.json +- README.md --- -## Feature - -TODO - - ## Usage -TODO - ```bash # let the magic happen yo sublime-package @@ -56,13 +45,10 @@ yo sublime-package --generators # run subgenerators directly yo sublime-package:SUBGENERATOR -yo sublime-package:sopm +yo sublime-package:readme ``` -## Settings - -TODO - +--- ## Dependencies @@ -89,6 +75,8 @@ Install [Yeoman](http://yeoman.io) npm install -g yo ``` +--- + ## Installation ### 1. NPM @@ -122,8 +110,12 @@ Run this link command in generator-sublime-package directory to link this genera npm link ./ ``` +--- + ## Development +### Dependencies + ```bash # install yeoman-test for jest tests npm install -g yeoman-test @@ -137,7 +129,7 @@ npm install -g ejs-lint ``` -### Common Commands +### Commands ```bash npm run lint # lint all JS files @@ -145,3 +137,15 @@ npm run lint-fix # lint and fix all JS files npm run test # start jest (tests) npm run coverage # start jest (tests) with coverage ``` + +--- + +## Download + +For download see [Sublime-GitHubFileFetcher](https://github.com/dennykorsukewitz/Sublime-GitHubFileFetcher/releases) + +--- + +Enjoy! + +Your [Denny Korsukéwitz](https://github.com/dennykorsukewitz) 🚀 \ No newline at end of file diff --git a/generators/app/USAGE b/generators/app/USAGE index 7a28805..71ee6af 100644 --- a/generators/app/USAGE +++ b/generators/app/USAGE @@ -6,10 +6,16 @@ Example: yo sublime-package --generators This will create: - .gitignore: default gitignore file + .gitattributes default .gitattributes file + .gitignore default .gitignore file + messages/changelog.txt default changelog.txt file + messages/install.txt default install.txt file + messages/version.txt default version.txt file + messages.json default messages.json file Variables: - TODO - TODO - TODO - TODO + sublime_version + package_name + package_description + github_username + github_fullname \ No newline at end of file diff --git a/generators/app/config.js b/generators/app/config.js index d480f39..4b084f1 100644 --- a/generators/app/config.js +++ b/generators/app/config.js @@ -1,35 +1,45 @@ const config = { name: 'Sublime-Package-Generator', + versions: { + '4.0.x': '', + }, prompts: [ + // { + // name: 'sublime_version', + // message: 'For which sublime version should this package be?', + // type: 'list', + // choices: '${config.supported_versions}', + // default: '4.0.x', + // store: true, + // }, { - name: 'framework_version', - message: 'For which framework version should this package be?', - type: 'list', - choices: '${config.supported_versions}', - default: '7.0.x', + name: 'package_name', + message: 'What is the name of your new Sublime-Package?', + type: 'input', + default: '${config.package_name_predicted}', store: true, }, { - name: 'package_name', - message: 'Please add or confirm the package prefix / customer contraction.', + name: 'package_description', type: 'input', - default: '${config.package_prefix}', + message: 'Description. What does the package contain?', + default: '**${config.package_name_predicted}** is a Sublime Text package that...', + store: true, + }, + { + name: 'github_username', + message: 'What is the GitHub user name of your new Sublime-Package?', + type: 'input', + default: '${config.github_username}', + store: true, + }, + { + name: 'github_fullname', + message: 'What is your GitHub full name?', + type: 'input', + default: '${config.github_fullname}', store: true, }, - // { - // name: 'package_seperator', - // message: 'Please add or confirm the package seperator.', - // type: 'input', - // default: '${config.package_seperator}', - // store: true, - // }, - // { - // name: 'package_suffix', - // message: 'Please add or confirm the package suffix.', - // type: 'input', - // default: '${config.package_suffix}', - // store: true, - // }, ], }; module.exports = config; \ No newline at end of file diff --git a/generators/app/index.js b/generators/app/index.js index d69fe61..3942ae3 100644 --- a/generators/app/index.js +++ b/generators/app/index.js @@ -23,21 +23,26 @@ module.exports = class extends Generator { config = this.config.getAll(); // Denny: delete me - if (config.package_name == 'DK-Test') { - console.log('initializing config'); - console.log(config); - console.log(generator_config); - } + console.log('initializing config'); + console.log(config); + console.log('initializing generator_config'); + console.log(generator_config); // Says hello helper.SayStart(this, config); + generator_config.prompts = helper.InterpolatePrompts(this, config, generator_config.prompts); + + console.log('generator_config.prompts'); + console.log(generator_config.prompts); + + // add only not answered prompt's (questions) to array prompts generator_config.prompts.forEach(prompt => { if (!config[prompt.name]) { - // if add supported framework_version 's - if (prompt.name == 'framework_version') { + // if add supported sublime_version 's + if (prompt.name == 'sublime_version') { prompt.choices = config.supported_versions; } prompts.push(prompt); @@ -58,16 +63,16 @@ module.exports = class extends Generator { } config.generators = []; - config.framework_version = config.framework_version || answers.framework_version; + config.sublime_version = config.sublime_version || answers.sublime_version || '4.0.x'; - if (!config.generators.length && config.framework_version && config.generators_by_versions) { + if (!config.generators.length && config.sublime_version && config.generators_by_versions) { config.generators = helper.GetAvailableGenerators(this, config); } if (!config.generators || !config.generators.length) { this.log( yosay( - `${chalk.red('I have not found any generators for this version:')} ${chalk.green(config.framework_version)}`, + `${chalk.red('I have not found any generators for this version:')} ${chalk.green(config.sublime_version)}`, ), ); return; @@ -99,7 +104,6 @@ module.exports = class extends Generator { this.config.set(key, answers[key]); } - helper.SetPackageName(this, config); this.config.save(); } diff --git a/generators/app/templates/.gitattributes b/generators/app/templates/.gitattributes new file mode 100644 index 0000000..039f22a --- /dev/null +++ b/generators/app/templates/.gitattributes @@ -0,0 +1,12 @@ +# Exclude files from exporting + +## Graphics +*.png export-ignore +*.jpg export-ignore +*.jpeg export-ignore +*.gif export-ignore +*.tif export-ignore +*.tiff export-ignore +*.ico export-ignore +*.svg export-ignore +*.eps export-ignore \ No newline at end of file diff --git a/generators/app/templates/.gitignore b/generators/app/templates/.gitignore new file mode 100644 index 0000000..5b0735f --- /dev/null +++ b/generators/app/templates/.gitignore @@ -0,0 +1,3 @@ +.yo-rc.json +node_modules +coverage \ No newline at end of file diff --git a/generators/app/templates/changelog.txt b/generators/app/templates/changelog.txt new file mode 100644 index 0000000..5c2c818 --- /dev/null +++ b/generators/app/templates/changelog.txt @@ -0,0 +1,11 @@ +Changelog + +All notable changes to the "<%= package_name %>" package will be documented in this file. + +--- + +Version 0.0.0 + +Initial release of <%= package_name %> package. + +- TODO \ No newline at end of file diff --git a/generators/app/templates/dummyfile.txt b/generators/app/templates/dummyfile.txt deleted file mode 100644 index e69de29..0000000 diff --git a/generators/app/templates/install.txt b/generators/app/templates/install.txt new file mode 100644 index 0000000..b13abb3 --- /dev/null +++ b/generators/app/templates/install.txt @@ -0,0 +1,9 @@ +⭐ Congratulations ⭐ + +<%= package_description %> + +------------------- + +🌟 Version 0.0.0 🌟 - Feature List + +- TODO diff --git a/generators/app/templates/messages.json b/generators/app/templates/messages.json new file mode 100644 index 0000000..8535cc0 --- /dev/null +++ b/generators/app/templates/messages.json @@ -0,0 +1,4 @@ +{ + "install": "messages/install.txt", + "0.0.0": "messages/version.txt" +} \ No newline at end of file diff --git a/generators/app/templates/version.txt b/generators/app/templates/version.txt new file mode 100644 index 0000000..1e322ed --- /dev/null +++ b/generators/app/templates/version.txt @@ -0,0 +1,13 @@ +🌟 Version 0.0.0 🌟 + +Initial release of TODO package. + +- TODO + +GitHub link - https://github.com/<%= github_username %>/<%= package_name %> + +--- + +Enjoy! + +Your [Denny Korsukéwitz](https://github.com/<%= github_username %>) 🚀 \ No newline at end of file diff --git a/generators/readme/USAGE b/generators/readme/USAGE new file mode 100644 index 0000000..b437289 --- /dev/null +++ b/generators/readme/USAGE @@ -0,0 +1,8 @@ +Description: + Creates README.md markdown file. + +Example: + yo sublime-package:readme + + This will create: + README.md: Description and minimal user instructions diff --git a/generators/readme/config.js b/generators/readme/config.js new file mode 100644 index 0000000..42f0ffd --- /dev/null +++ b/generators/readme/config.js @@ -0,0 +1,13 @@ +const config = { + name: 'README.md', + priority: 5, + versions: { + '4.0.x': '', + }, + required_data: [ + 'package_name', + 'sublime_version', + ], + prompts: [], +}; +module.exports = config; \ No newline at end of file diff --git a/generators/readme/index.js b/generators/readme/index.js new file mode 100644 index 0000000..eaf3d38 --- /dev/null +++ b/generators/readme/index.js @@ -0,0 +1,76 @@ +'use strict'; +/* eslint no-empty-function: ["error", { "allow": ["methods"] }] */ + +const Generator = require('yeoman-generator'); +const chalk = require('chalk'); +const yosay = require('yosay'); +const path = require('path'); +const helper = require('./../../src/helper.js'); +const generator = path.basename(__dirname); +const generator_config = require('./config.js'); + +let config = {}; +let answers = {}; + +module.exports = class extends Generator { + // initializing - Your initialization methods (checking current project state, getting configs, etc) + async initializing() { + + // create or update config + await helper.InitConfig(this, generator_config); + + // get current config + config = this.config.getAll(); + config.generator_name = generator_config.name || generator; + } + + // prompting - Where you prompt users for options (where you’d call this.prompt()) + async prompting() { + this.log( + yosay( + `${chalk.green(config.generator_name)}`, + ), + ); + answers = await this.prompt(generator_config.prompts); + } + + // configuring - Saving configurations and configure the project (creating .editorconfig files and other metadata files) + configuring() {} + + // default - If the method name doesn’t match a priority, it will be pushed to this group. + default() {} + + // writing - Where you write the generator specific files (routes, controllers, etc) + writing() { + + // merge data + const data = { + ...config, + ...answers, + }; + + // template path + const template_path = 'README.md'; + + // destination path + const destination_path = 'README.md'; + + this.renderTemplate( + this.templatePath(template_path), + this.destinationPath(destination_path), + data, + ); + } + + // conflicts - Where conflicts are handled (used internally) + conflicts() { } + + // install - Where installations are run (npm, bower) + install() {} + + // end - Called last, cleanup, say good bye, etc + end() { + helper.End(this, config); + } +}; + diff --git a/generators/readme/templates/README.md b/generators/readme/templates/README.md new file mode 100644 index 0000000..857f25f --- /dev/null +++ b/generators/readme/templates/README.md @@ -0,0 +1,97 @@ +# <%= package_name %>> + +<%= package_description %> + +## Feature + +TODO + +--- + +## Usage + +TODO + +--- + +## Settings + +TODO + +--- + +## Installation + +To install this package, you have **three** options: + +### 1. Search Package via `Package Control` + +Search and install online package via [Sublime Package Control](http://wbond.net/sublime_packages/package_control). + +`Tools` -> `Command Palette` -> `Package Control: Install Package` -> simply search for `<%= package_name %>` to install. + +### 2. Install via sublime-package file + +Download latest [sublime-package file](https://github.com/<%= github_username %>/<%= package_name %>/releases) and move the package `<%= package_name %>.sublime-package` to `Installed Packages` folder. + +#### OSX + +``` +cd ~/Library/Application\ Support/Sublime\ Text\ 2/Installed Packages/ +- or ST 3 - +cd ~/Library/Application\ Support/Sublime\ Text\ 3/Installed Packages/ +``` + +#### Linux + +``` +cd ~/.config/sublime-text-2/Installed Packages +- or ST 3 - +cd ~/.config/sublime-text-3/Installed Packages +``` + +#### Windows + +``` +cd "%APPDATA%\Sublime Text 2\Installed Packages" +- or ST 3 - +cd "%APPDATA%\Sublime Text 3\Installed Packages" +``` + +### 3. Source code + +Clone the latest [dev branch](https://github.com/<%= github_username %>/<%= package_name %>) and unpack it to Sublime Package folder `Packages`. + +#### OSX + +``` +cd ~/Library/Application\ Support/Sublime\ Text\ 2/Packages/ +- or ST 3 - +cd ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/ +git clone git@github.com:<%= github_username %>/<%= package_name %>.git <%= package_name %> +``` + +#### Linux + +``` +cd ~/.config/sublime-text-2/Packages +- or ST 3 - +cd ~/.config/sublime-text-3/Packages +git clone git@github.com:<%= github_username %>/<%= package_name %>.git <%= package_name %> +``` + +#### Windows + +``` +cd "%APPDATA%\Sublime Text 2\Packages" +- or ST 3 - +cd "%APPDATA%\Sublime Text 3\Packages" +git clone git@github.com:<%= github_username %>/<%= package_name %>.git <%= package_name %> +``` + +--- + +## Download + +For download see [<%= package_name %>>](https://github.com/<%= github_username %>/<%= package_name %>>/releases) + diff --git a/package.json b/package.json index b8a33da..ab371cb 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,22 @@ { "name": "generator-sublime-package", - "version": "0.1.0", - "description": "We are lazy and only want to code if it is not already there.", + "version": "0.0.1", + "description": "Sublime-Package is a Sublime Text package generator for yeoman, which creates scaffold for a sublime-package.", "homepage": "https://github.com/dennykorsukewitz/generator-sublime-package", "author": { "name": "Denny Korsukéwitz", "email": "dennykorsukewitz@gmail.com", "url": "https://dennykorsukewitz.github.io/" }, + "repository": "dennykorsukewitz/generator-sublime-package", + "license": "AGPL-3.0", + "keywords": [ + "sublime", + "sublime-text", + "sublime-package", + "yeoman", + "yeoman-generator" + ], "scripts": { "lint": "eslint .", "lint-fix": "eslint . --fix", @@ -15,24 +24,22 @@ "test": "jest --colors", "coverage": "jest --coverage --colors --verbose --forceExit" }, - "repository": "dennykorsukewitz/generator-sublime-package", - "license": "AGPL-3.0", "files": [ "generators" ], - "keywords": [ - "sublime", - "sublime-text", - "sublime-package", - "yeoman", - "yeoman-generator" - ], "main": "generators/index.js", "dependencies": { "chalk": "^2.1.0", - "change-case": "^5.2.0", - "node-fetch": "^2.6.1", - "yeoman-generator": "^7.1.1", + "change-case": "^4.1.2", + "gitconfig": "^2.0.8", + "interpolate-json": "^2.2.2", + "mock-fs": "^5.2.0", + "recursive-readdir": "^2.2.3", + "snake-case": "^3.0.4", + "to-snake-case": "^1.0.0", + "xmldom": "^0.6.0", + "xpath": "^0.0.32", + "yeoman-generator": "^5.7.0", "yosay": "^2.0.2" }, "devDependencies": { @@ -40,19 +47,17 @@ "eslint-config-prettier": "^6.6.0", "eslint-config-xo": "^0.27.2", "eslint-plugin-prettier": "^3.1.1", - "husky": "^3.0.9", "jest": "^26.1.0", "lint-staged": "^9.4.3", "prettier": "^1.19.1", "yeoman-assert": "^3.1.1", - "yeoman-test": "^8.2.0" + "yeoman-test": "^6.3.0" }, "engines": { "npm": ">= 4.0.0", - "node": ">=16.0.0" + "node": ">=16.0.0 <17.0.0" }, "jest": { - "testEnvironment": "node", "testTimeout": 20000 }, "lint-staged": { diff --git a/src/helper.js b/src/helper.js index 41a08fa..c3ab3f4 100644 --- a/src/helper.js +++ b/src/helper.js @@ -4,6 +4,7 @@ const chalk = require('chalk'); const yosay = require('yosay'); const glob = require('glob'); const change_case = require('change-case'); +const gitconfig = require('gitconfig') const { interpolation } = require('interpolate-json'); @@ -24,12 +25,25 @@ async function InitConfig(Generator, GeneratorConfig) { config.file_list = await GetFileList(Generator, config); config = SetTempPath(Generator, config); + config = SetPackageName(Generator, config); // get all possible versions config = await GetSupportedVersions(Generator, config); + // gitconfig.get({ + // location: 'global' + // }).then((mygitconfig) => { + // console.log(mygitconfig); + // config.github_username = mygitconfig.user.user + // config.github_fullname = mygitconfig.user.name + // }) + let mygitconfig = await gitconfig.get({ + location: 'global' + }) + console.log(mygitconfig); + // get only needed / available generators - if (!config.generators && config.framework_version) { + if (!config.generators && config.sublime_version) { config.generators = GetAvailableGenerators(Generator, config); } @@ -48,7 +62,7 @@ async function GetSupportedVersions(Generator, config) { const generators_by_versions = {}; files.forEach(file => { - let pattern = /(app|__subgenerator__|__renamer__)/i; + let pattern = /(app)/i; let result = file.match(pattern); if (result) { return; @@ -110,7 +124,7 @@ async function GetFileList(Generator, config, ignore_files) { function GetAvailableGenerators(Generator, config) { - let generators = config.generators_by_versions[config.framework_version]; + let generators = config.generators_by_versions[config.sublime_version]; // skip xml_config_file generator if xml_config_file already exists if (config.xml_config_file) { @@ -194,30 +208,60 @@ function InterpolatePrompts(Generator, config, prompts, answers) { return interpolatePrompts; } +function SetPackageName(Generator, config) { + + if (config && config.package_dir) { + + const name = config.package_dir.split(/[\\/]/).pop(); + + console.log('name'); + console.log(name); + + config.package_seperator = '-'; + const package_name_split = name.split(config.package_seperator); + + if (package_name_split.length == 2) { + config.package_prefix = package_name_split.shift(); + config.package_suffix = package_name_split.pop(); + config.package_name = config.package_prefix + config.package_seperator + config.package_suffix; + } + + if (config && config.package_prefix && config.package_seperator && config.package_suffix) { + config.package_name = config.package_prefix + config.package_seperator + config.package_suffix; + Generator.config.set('package_name', config.package_name); + } else { + config.package_name_predicted = name; + } + } + + return config; +} function SayStart(Generator, config) { Generator.log(chalk.hex('#FFA500')(` - ______ -|___ / - / / _ __ _ _ _ __ _ _ - / / | '_ \\ | | | | | '_ \\ | | | | - / /__ | | | | | |_| | | | | | | |_| | -/_____| |_| |_| \\__,_| |_| |_| \\__, | - __/ / - |___/ + _____ _ _ _ + / ____| | | | (_) + | (___ _ _| |__ | |_ _ __ ___ ___ + \\___ \\| | | | '_ \\| | | '_ \` _ \\ / _ \\ + ____) | |_| | |_) | | | | | | | | __/ + |_____/ \\__,_|_.__/|_|_|_| |_| |_|\\___| `)); let package_information = ''; - if (config && config.package_name && config.framework_version && config.package_version) { - package_information = `\nName: ${config.package_name}\nFramework: ${config.framework_version}\nVersion: ${config.package_version}`; + console.log(config); + if (config && config.package_name && config.sublime_version) { + package_information = `\nName: ${config.package_name}\nSublime: ${config.sublime_version}`; + } + if (config && config.package_version) { + package_information += `\nVersion: ${config.package_version}`; } // Have Yeoman greet the user. Generator.log( yosay( - `Welcome to the ${chalk.green('Sublime-PackageGenerator')}! + `Welcome to the ${chalk.green('Sublime-PackageGenerator')} ${package_information}`, ), ); @@ -226,7 +270,15 @@ function SayStart(Generator, config) { function Cleanup(Generator) { // delete .yo-rc.json (config) - Generator.deleteDestination('.yo-rc.json'); + // Generator.deleteDestination('.yo-rc.json'); + + // todo delete + // temp_path + // generator + // generator_config + // supported_versions + // generators_by_versions + // generators return; } @@ -238,7 +290,7 @@ function End(Generator, config) { // SetFileList(Generator, config); // } - // Cleanup all obsolete files + // Cleanup all obsolete files or data Cleanup(Generator, config); return; @@ -252,5 +304,6 @@ module.exports = { InitConfig, InterpolatePrompts, SayStart, + SetPackageName, SetTempPath, };