Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
dennykorsukewitz committed Nov 21, 2023
1 parent c0570f1 commit f4c9059
Show file tree
Hide file tree
Showing 12 changed files with 282 additions and 36 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/unittest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
name: UnitTest

on:
release:
types:
- published
push:
branches: ["dev", "dev-update", "private-dk-dev-init"]
workflow_dispatch: # Allows you to run this workflow manually from the Actions tab

jobs:
UnitTest-Jest:
name: UnitTest:Jest
runs-on: ubuntu-22.04 # ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install dependencies
run: npm install
- name: Run jest with coverage
run: npm run coverage
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ brew install node
`generator-sublime-package` uses the yeoman module to create that epic scaffold.

Install [Yeoman](http://yeoman.io)

```bash
# install yeoman global
npm install -g yo
Expand Down Expand Up @@ -148,4 +149,4 @@ For download see [Sublime-GitHubFileFetcher](https://github.com/dennykorsukewitz

Enjoy!

Your [Denny Korsukéwitz](https://github.com/dennykorsukewitz) 🚀
Your [Denny Korsukéwitz](https://github.com/dennykorsukewitz) 🚀
16 changes: 0 additions & 16 deletions __tests__/app.js

This file was deleted.

64 changes: 64 additions & 0 deletions __tests__/generators/app.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
'use strict';

const path = require('path');
const helpers = require('yeoman-test');

describe('generators:app', () => {
describe('creates files without existing package', () => {
let runResult;

const config = {};
const expectedFiles = ['.gitignore'];

beforeEach(async () => {
runResult = await helpers
.run(path.join(process.env.INIT_CWD, '/generators/app'))
.withPrompts(config)
.withLocalConfig(config);
});

afterEach(() => {
if (runResult) {
runResult.restore();
}
});

it('runs correctly', () => {
runResult.assertFile(expectedFiles);
});
});

describe('creates files with existing package', () => {
let runResult;

const config = {
// generator_data
sublime_version: '4.0.x',
package_name: 'My-Package',
package_description: 'My description.',
github_username: 'dennykorsukewitz',
github_fullname: 'Denny Korsukéwitz',
generators: '',
};

const expectedFiles = ['.gitignore'];

beforeEach(async () => {
runResult = await helpers
.run(path.join(process.env.INIT_CWD, '/generators/app'))
.withPrompts(config)
.withLocalConfig(config);
});

afterEach(() => {
if (runResult) {
runResult.restore();
}
});

it('runs correctly', () => {
runResult.assertFile(expectedFiles);
});
});
});

2 changes: 1 addition & 1 deletion generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ module.exports = class extends Generator {
if (!config.generators || !config.generators.length) {
this.log(
yosay(
`${chalk.red('I have not found any generators for this version:')} ${chalk.green(config.sublime_version)}`,
`${chalk.red('I have not found any or new generators for this version:')} ${chalk.green(config.sublime_version)}`,
),
);
return;
Expand Down
8 changes: 8 additions & 0 deletions generators/plugin/USAGE
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Description:
Creates a new python plugin.

Example:
yo sublime-package:plugin

This will create:
plugin.py: Default python template
9 changes: 9 additions & 0 deletions generators/plugin/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const config = {
name: 'README.md',
priority: 5,
versions: {
'4.0.x': '',
},
prompts: [],
};
module.exports = config;
76 changes: 76 additions & 0 deletions generators/plugin/index.js
Original file line number Diff line number Diff line change
@@ -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);
}
};

84 changes: 84 additions & 0 deletions generators/plugin/templates/plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@

import sublime
import sublime_plugin


def plugin_loaded():

global settings
settings = sublime.load_settings("GitHubFileFetcher.sublime-settings")


class ExampleCommand(sublime_plugin.TextCommand):
def run(self, edit):

self.view.insert(edit, 0, "Hello, World!")

# Status Message
sublime.status_message("Hello, World!")

# Owner/Repository Selection.
self.window.show_quick_panel(
items=['yes', 'no'],
on_select=self.quick_panel_selected,
on_highlight=None,
flags=32,
selected_index=-1,
placeholder="Your placeholder",
)

# Create search_string input panel
self.window.show_input_panel(
caption="Hello, World!",
initial_text="Hello, World!",
on_done=self.input_panel_set,
on_change=None,
on_cancel=None,
)

def quick_panel_selected(self, index):

if index == -1:
return

def input_panel_set(self, value):

if value == -1:
return

class ExampleCommand(sublime_plugin.WindowCommand):
def run(self):

self.view.insert(edit, 0, "Hello, World!")

# Status Message
sublime.status_message("Hello, World!")

# Owner/Repository Selection.
self.window.show_quick_panel(
items=['yes', 'no'],
on_select=self.quick_panel_selected,
on_highlight=None,
flags=32,
selected_index=-1,
placeholder="Your placeholder",
)

# Create search_string input panel
self.window.show_input_panel(
caption="Hello, World!",
initial_text="Hello, World!",
on_done=self.input_panel_set,
on_change=None,
on_cancel=None,
)

def quick_panel_selected(self, index):

if index == -1:
return

def input_panel_set(self, value):

if value == -1:
return
2 changes: 1 addition & 1 deletion generators/readme/USAGE
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ Example:
yo sublime-package:readme

This will create:
README.md: Description and minimal user instructions
readme.md: Description and minimal user instructions
1 change: 0 additions & 1 deletion generators/readme/templates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,3 @@ git clone [email protected]:<%= github_username %>/<%= package_name %>.git <%= pack
## Download

For download see [<%= package_name %>](https://github.com/<%= github_username %>/<%= package_name %>/releases)

31 changes: 15 additions & 16 deletions src/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const chalk = require('chalk');
const yosay = require('yosay');
const glob = require('glob');
const changeCase = require('change-case');
const gitconfig = require('gitconfig')
const gitconfig = require('gitconfig');

const { interpolation } = require('interpolate-json');

Expand Down Expand Up @@ -189,7 +189,8 @@ function SetPackageName(Generator, config) {
if (config && config.package_prefix && config.package_seperator && config.package_suffix) {
// config.package_name = config.package_prefix + config.package_seperator + config.package_suffix;
config.package_name_predicted = config.package_prefix + config.package_seperator + config.package_suffix;
} else {
}
else {
config.package_name_predicted = name;
}
Generator.config.set('package_name_predicted', config.package_name_predicted);
Expand Down Expand Up @@ -228,22 +229,21 @@ function SayStart(Generator, config) {
);
}

function Cleanup(Generator, config) {
function Cleanup(Generator) {

let delete_items = [
"temp_path",
"generator",
"generator_config",
"supported_versions",
"generators_by_versions",
"generators",
"temp_path",
"package_name_predicted",
]
const delete_items = [
'temp_path',
'generator',
'generator_config',
'supported_versions',
'generators_by_versions',
'generators',
'temp_path',
'package_name_predicted',
];

// delete config to .yo-rc.json
for (const key in delete_items) {
console.log(delete_items[key]);
Generator.config.delete(delete_items[key]);
}
Generator.config.save();
Expand All @@ -254,7 +254,7 @@ function Cleanup(Generator, config) {
function End(Generator, config) {

// Cleanup all obsolete files or data
Cleanup(Generator, config);
Cleanup(Generator);

return;
}
Expand All @@ -263,7 +263,6 @@ module.exports = {
Cleanup,
End,
GetAvailableGenerators,
GetSupportedVersions,
InitConfig,
InterpolatePrompts,
SayStart,
Expand Down

0 comments on commit f4c9059

Please sign in to comment.