3 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "generator-opencart-module",
3 | "version": "0.1.2",
4 | "description": "Yeoman generator for Opencart module",
5 | "homepage": "https://github.com/taiyeoguns/generator-opencart-module",
6 | "author": {
7 | "name": "Taiye Ogunnigbo",
8 | "email": "taiyeoguns@gmail.com",
9 | "url": "http://taiyeogunnigbo.name.ng/"
10 | },
11 | "files": [
12 | "generators"
13 | ],
14 | "main": "generators\\index.js",
15 | "keywords": [
16 | "opencart",
17 | "module",
18 | "yeoman-generator"
19 | ],
20 | "dependencies": {
21 | "chalk": "^1.0.0",
22 | "underscore.string": "^3.3.4",
23 | "yeoman-generator": "^0.21.1",
24 | "yosay": "^1.0.2"
25 | },
26 | "devDependencies": {
27 | "yeoman-assert": "^2.0.0",
28 | "eslint": "^2.1.0",
29 | "eslint-config-xo-space": "^0.10.0",
30 | "gulp": "^3.9.0",
31 | "gulp-eslint": "^2.0.0",
32 | "gulp-exclude-gitignore": "^1.0.0",
33 | "gulp-line-ending-corrector": "^1.0.1",
34 | "gulp-istanbul": "^0.10.3",
35 | "gulp-mocha": "^2.0.0",
36 | "gulp-plumber": "^1.0.0",
37 | "gulp-nsp": "^2.1.0",
38 | "gulp-coveralls": "^0.1.0"
39 | },
40 | "eslintConfig": {
41 | "extends": "xo-space",
42 | "env": {
43 | "mocha": true
44 | }
45 | },
46 | "repository": "https://github.com/taiyeoguns/generator-opencart-module.git",
47 | "scripts": {
48 | "prepublish": "gulp prepublish",
49 | "test": "gulp"
50 | },
51 | "license": "Apache-2.0"
52 | }
53 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Module scaffold creator for Opencart
2 |
3 | [![NPM version][npm-image]][npm-url]
4 |
5 |
6 | This package provides an easy way to create a starting structure for your Opencart module.
7 |
8 | 
9 |
10 | ## Installation - Option 1
11 | Linux, OSx, Windows:
12 | First, install [Yeoman](http://yeoman.io) and generator-opencart-module using [npm](https://www.npmjs.com/) (we assume you have pre-installed [node.js](https://nodejs.org/)).
13 |
14 | ```bash
15 | npm install -g yo
16 | npm install -g generator-opencart-module
17 | ```
18 |
19 | Then generate your new project:
20 |
21 | ```bash
22 | yo opencart-module
23 | ```
24 |
25 | ## Installation - Option 2
26 | Windows Only:
27 | To generate modules without the requirement of node.js and Yeoman, you can use a Windows computer with PowerShell. No additional software is required.
28 |
29 | To generate your new project:
30 | First, start a powershell terminal window. Then go to your instailation folder and execute the build script.
31 | ```PowerShell
32 | cd
\generators\app
33 | generate-module.ps1
34 | ```
35 | * Windows Powershell Script provided by Jayson Johnson - Edmonton Acrobatic Gymnastics - edmontonacro.ca
36 |
37 | ## Features
38 |
39 | - Allows to specify module type such as Payment, Shipping, Order Total, Feed
40 | - Supports creating modules for Opencart 1.5.x and 2.x versions.
41 | - Optionally add vQmod support
42 |
43 | ## License
44 |
45 | Apache-2.0 © [Taiye Ogunnigbo]()
46 |
47 |
48 | [npm-image]: https://badge.fury.io/js/generator-opencart-module.svg
49 | [npm-url]: https://npmjs.org/package/generator-opencart-module
50 |
--------------------------------------------------------------------------------
/generators/app/templates/2_x/_admin_view.tpl:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/gulpfile.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 | var path = require('path');
3 | var gulp = require('gulp');
4 | var eslint = require('gulp-eslint');
5 | var excludeGitignore = require('gulp-exclude-gitignore');
6 | var mocha = require('gulp-mocha');
7 | var istanbul = require('gulp-istanbul');
8 | var nsp = require('gulp-nsp');
9 | var plumber = require('gulp-plumber');
10 | var coveralls = require('gulp-coveralls');
11 |
12 | gulp.task('static', function () {
13 | return gulp.src('**/*.js')
14 | .pipe(excludeGitignore())
15 | .pipe(eslint())
16 | .pipe(eslint.format())
17 | .pipe(eslint.failAfterError());
18 | });
19 |
20 | gulp.task('nsp', function (cb) {
21 | nsp({package: path.resolve('package.json')}, cb);
22 | });
23 |
24 | gulp.task('pre-test', function () {
25 | return gulp.src('generators\**\*.js')
26 | .pipe(excludeGitignore())
27 | .pipe(istanbul({
28 | includeUntested: true
29 | }))
30 | .pipe(istanbul.hookRequire());
31 | });
32 |
33 | gulp.task('test', ['pre-test'], function (cb) {
34 | var mochaErr;
35 |
36 | gulp.src('test/**/*.js')
37 | .pipe(plumber())
38 | .pipe(mocha({reporter: 'spec'}))
39 | .on('error', function (err) {
40 | mochaErr = err;
41 | })
42 | .pipe(istanbul.writeReports())
43 | .on('end', function () {
44 | cb(mochaErr);
45 | });
46 | });
47 |
48 | gulp.task('watch', function () {
49 | gulp.watch(['generators\**\*.js', 'test/**'], ['test']);
50 | });
51 |
52 | gulp.task('coveralls', ['test'], function () {
53 | if (!process.env.CI) {
54 | return;
55 | }
56 |
57 | return gulp.src(path.join(__dirname, 'coverage/lcov.info'))
58 | .pipe(coveralls());
59 | });
60 |
61 | gulp.task('prepublish', ['nsp']);
62 | gulp.task('default', ['static', 'test', 'coveralls']);
63 |
--------------------------------------------------------------------------------
/test/app.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 | var path = require('path');
3 | var assert = require('yeoman-assert');
4 | var helpers = require('yeoman-generator').test;
5 |
6 | describe('generator-opencart-module', function () {
7 | before(function (done) {
8 | helpers.run(path.join(__dirname, '../generators/app'))
9 | .withPrompts(
10 | {
11 | module_name: 'a module',
12 | module_type: 'module',
13 | version: '2_x',
14 | vqmod: true
15 | }
16 | )
17 | .on('end', done);
18 | });
19 |
20 | /*
21 | * Admin
22 | */
23 |
24 | //controller
25 | it('creates admin controller', function () {
26 | assert.file([
27 | 'upload/admin/controller/module/a_module.php'
28 | ]);
29 | assert.fileContent('upload/admin/controller/module/a_module.php', 'class ControllerModuleAModule extends Controller {');
30 | });
31 |
32 | //language
33 | it('creates admin language', function () {
34 | assert.file([
35 | 'upload/admin/language/english/module/a_module.php'
36 | ]);
37 | });
38 |
39 | //view
40 | it('creates admin view', function () {
41 | assert.file([
42 | 'upload/admin/view/template/module/a_module.tpl'
43 | ]);
44 | });
45 |
46 | /*
47 | * Catalog
48 | */
49 |
50 | //controller
51 | it('creates catalog controller', function () {
52 | assert.file([
53 | 'upload/catalog/controller/module/a_module.php'
54 | ]);
55 | assert.fileContent('upload/catalog/controller/module/a_module.php', 'class ControllerModuleAModule extends Controller {');
56 | });
57 |
58 | //language
59 | it('creates catalog language', function () {
60 | assert.file([
61 | 'upload/catalog/language/english/module/a_module.php'
62 | ]);
63 | });
64 |
65 | //view
66 | it('creates catalog view', function () {
67 | assert.file([
68 | 'upload/catalog/view/theme/default/template/module/a_module.tpl'
69 | ]);
70 | });
71 |
72 | /*
73 | * vQmod
74 | */
75 |
76 | it('creates vqmod', function () {
77 | assert.file([
78 | 'upload/vqmod/xml/a_module.xml'
79 | ]);
80 | });
81 | });
82 |
--------------------------------------------------------------------------------
/generators/app/templates/1_5/_admin_controller.php:
--------------------------------------------------------------------------------
1 | extends Controller {
4 |
5 | private $error = array();
6 |
7 | public function index() {
8 | //Load language file
9 | $this->load->language('<%= module_type %>/<%= underscored_name %>');
10 |
11 | //Set title from language file
12 | $this->document->setTitle($this->language->get('heading_title'));
13 |
14 | //Load settings model
15 | $this->load->model('setting/setting');
16 |
17 | //Save settings
18 | if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
19 | $this->model_setting_setting->editSetting('<%= underscored_name %>', $this->request->post);
20 |
21 | $this->session->data['success'] = $this->language->get('text_success');
22 |
23 | $this->redirect($this->url->link('extension/<%= module_type %>', 'token=' . $this->session->data['token'], 'SSL'));
24 | }
25 |
26 | $text_strings = array(
27 | 'heading_title',
28 | 'button_save',
29 | 'button_cancel',
30 | 'button_add_module',
31 | 'button_remove',
32 | 'placeholder',
33 | );
34 |
35 | foreach ($text_strings as $text) {
36 | $this->data[$text] = $this->language->get($text);
37 | }
38 |
39 | //error handling
40 | if (isset($this->error['warning'])) {
41 | $this->data['error_warning'] = $this->error['warning'];
42 | } else {
43 | $this->data['error_warning'] = '';
44 | }
45 |
46 |
47 | $this->data['breadcrumbs'] = array();
48 |
49 | $this->data['breadcrumbs'][] = array(
50 | 'text' => $this->language->get('text_home'),
51 | 'href' => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
52 | 'separator' => false
53 | );
54 |
55 | $this->data['breadcrumbs'][] = array(
56 | 'text' => $this->language->get('text_<%= module_type %>'),
57 | 'href' => $this->url->link('extension/<%= module_type %>', 'token=' . $this->session->data['token'], 'SSL'),
58 | 'separator' => ' :: '
59 | );
60 |
61 | $this->data['breadcrumbs'][] = array(
62 | 'text' => $this->language->get('heading_title'),
63 | 'href' => $this->url->link('<%= module_type %>/<%= underscored_name %>', 'token=' . $this->session->data['token'], 'SSL'),
64 | 'separator' => ' :: '
65 | );
66 |
67 | $this->data['action'] = $this->url->link('<%= module_type %>/<%= underscored_name %>', 'token=' . $this->session->data['token'], 'SSL');
68 |
69 | $this->data['cancel'] = $this->url->link('extension/<%= module_type %>', 'token=' . $this->session->data['token'], 'SSL');
70 |
71 |
72 | //Check if multiple instances of this module
73 | $this->data['modules'] = array();
74 |
75 | if (isset($this->request->post['<%= underscored_name %>_module'])) {
76 | $this->data['modules'] = $this->request->post['<%= underscored_name %>_module'];
77 | } elseif ($this->config->get('<%= underscored_name %>_module')) {
78 | $this->data['modules'] = $this->config->get('<%= underscored_name %>_module');
79 | }
80 |
81 | //Prepare for display
82 | $this->load->model('design/layout');
83 |
84 | $this->data['layouts'] = $this->model_design_layout->getLayouts();
85 |
86 |
87 | $this->template = '<%= module_type %>/<%= underscored_name %>.tpl';
88 | $this->children = array(
89 | 'common/header',
90 | 'common/footer',
91 | );
92 |
93 | //Send the output.
94 | $this->response->setOutput($this->render());
95 | }
96 |
97 | /*
98 | *
99 | * Check that user actions are authorized
100 | *
101 | */
102 | private function validate() {
103 | if (!$this->user->hasPermission('modify', '<%= module_type %>/<%= underscored_name %>')) {
104 | $this->error['warning'] = $this->language->get('error_permission');
105 | }
106 |
107 | if (!$this->error) {
108 | return TRUE;
109 | } else {
110 | return FALSE;
111 | }
112 | }
113 |
114 |
115 | }
116 | ?>
--------------------------------------------------------------------------------
/generators/app/templates/2_x/_admin_controller.php:
--------------------------------------------------------------------------------
1 | extends Controller {
4 |
5 | private $error = array();
6 |
7 | public function index() {
8 |
9 | //Load language file
10 | $this->load->language('<%= module_type %>/<%= underscored_name %>');
11 |
12 | //Set title from language file
13 | $this->document->setTitle($this->language->get('heading_title'));
14 |
15 | //Load settings model
16 | $this->load->model('setting/setting');
17 |
18 | //Save settings
19 | if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
20 | $this->model_setting_setting->editSetting('<%= underscored_name %>', $this->request->post);
21 |
22 | $this->session->data['success'] = $this->language->get('text_success');
23 |
24 | $this->response->redirect($this->url->link('extension/<%= module_type %>', 'token=' . $this->session->data['token'], 'SSL'));
25 | }
26 |
27 | $text_strings = array(
28 | 'heading_title',
29 | 'button_save',
30 | 'button_cancel',
31 | 'button_add_module',
32 | 'button_remove',
33 | 'placeholder',
34 | );
35 |
36 | foreach ($text_strings as $text) {
37 | $data[$text] = $this->language->get($text);
38 | }
39 |
40 |
41 | //error handling
42 | if (isset($this->error['warning'])) {
43 | $data['error_warning'] = $this->error['warning'];
44 | } else {
45 | $data['error_warning'] = '';
46 | }
47 |
48 |
49 | $data['breadcrumbs'] = array();
50 |
51 | $data['breadcrumbs'][] = array(
52 | 'text' => $this->language->get('text_home'),
53 | 'href' => $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], 'SSL'),
54 | 'separator' => false
55 | );
56 |
57 | $data['breadcrumbs'][] = array(
58 | 'text' => $this->language->get('text_<%= module_type %>'),
59 | 'href' => $this->url->link('extension/<%= module_type %>', 'token=' . $this->session->data['token'], 'SSL'),
60 | 'separator' => ' :: '
61 | );
62 |
63 | $data['breadcrumbs'][] = array(
64 | 'text' => $this->language->get('heading_title'),
65 | 'href' => $this->url->link('<%= module_type %>/<%= underscored_name %>', 'token=' . $this->session->data['token'], 'SSL'),
66 | 'separator' => ' :: '
67 | );
68 |
69 | $data['action'] = $this->url->link('<%= module_type %>/<%= underscored_name %>', 'token=' . $this->session->data['token'], 'SSL');
70 |
71 | $data['cancel'] = $this->url->link('extension/<%= module_type %>', 'token=' . $this->session->data['token'], 'SSL');
72 |
73 |
74 | //Check if multiple instances of this module
75 | $data['modules'] = array();
76 |
77 | if (isset($this->request->post['<%= underscored_name %>_module'])) {
78 | $data['modules'] = $this->request->post['<%= underscored_name %>_module'];
79 | } elseif ($this->config->get('<%= underscored_name %>_module')) {
80 | $data['modules'] = $this->config->get('<%= underscored_name %>_module');
81 | }
82 |
83 | //Prepare for display
84 | $this->load->model('design/layout');
85 |
86 | $data['layouts'] = $this->model_design_layout->getLayouts();
87 |
88 | $data['header'] = $this->load->controller('common/header');
89 | $data['column_left'] = $this->load->controller('common/column_left');
90 | $data['footer'] = $this->load->controller('common/footer');
91 |
92 | //Send the output
93 | $this->response->setOutput($this->load->view('<%= module_type %>/<%= underscored_name %>.tpl', $data));
94 | }
95 |
96 | /*
97 | *
98 | * Check that user actions are authorized
99 | *
100 | */
101 | private function validate() {
102 | if (!$this->user->hasPermission('modify', '<%= module_type %>/<%= underscored_name %>')) {
103 | $this->error['warning'] = $this->language->get('error_permission');
104 | }
105 |
106 | if (!$this->error) {
107 | return TRUE;
108 | } else {
109 | return FALSE;
110 | }
111 | }
112 |
113 |
114 | }
115 | ?>
--------------------------------------------------------------------------------
/generators/app/index.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 | var yeoman = require('yeoman-generator');
3 | var chalk = require('chalk');
4 | var yosay = require('yosay');
5 | var _s = require('underscore.string');
6 |
7 | //
8 | var classify_format, underscore_format, titleize_format, oc_version, mod_type;
9 |
10 | var CONTROLLER_DIR = 'upload/%c%/controller/%t%/',
11 | LANGUAGE_DIR = 'upload/%c%/language/english/%t%/',
12 | MODEL_DIR = 'upload/%c%/model/%t%/',
13 | ADMIN_VIEW_DIR = 'upload/admin/view/template/%t%/',
14 | CATALOG_VIEW_DIR = 'upload/catalog/view/theme/default/template/%t%/',
15 | VQMOD_DIR = 'upload/vqmod/xml/';
16 |
17 | module.exports = yeoman.generators.Base.extend({
18 | prompting: function() {
19 | var done = this.async();
20 |
21 | // Have Yeoman greet the user.
22 | this.log(yosay(
23 | 'Welcome to the ' + chalk.blue('Opencart Module') + ' starter generator!'
24 | ));
25 |
26 | var prompts = [{
27 | type: 'input',
28 | name: 'module_name',
29 | message: 'What name would you like for your module?',
30 | default: this.appname
31 | }, {
32 | type: 'list',
33 | name: 'version',
34 | message: 'What version of Opencart will your module be for?',
35 | choices: [{
36 | name: '1.5.x',
37 | value: '1_5'
38 | }, {
39 | name: '2.x',
40 | value: '2_x'
41 | }],
42 | default: 1
43 | }, {
44 | type: 'list',
45 | name: 'module_type',
46 | message: 'What type of module do you want to create?',
47 | choices: [{
48 | name: 'Module',
49 | value: 'module'
50 | },
51 | {
52 | name: 'Payment',
53 | value: 'payment'
54 | },
55 | {
56 | name: 'Shipping',
57 | value: 'shipping'
58 | },
59 | {
60 | name: 'Order Total',
61 | value: 'total'
62 | },
63 | {
64 | name: 'Feed',
65 | value: 'feed'
66 | }],
67 | default: 0
68 | }, {
69 | type: 'confirm',
70 | name: 'vqmod',
71 | message: 'Will the module require vQmod support?',
72 | default: false
73 | }];
74 |
75 | this.prompt(prompts, function(props) {
76 | this.props = props;
77 |
78 | oc_version = this.props.version;
79 | mod_type = this.props.module_type;
80 |
81 | classify_format = _s(mod_type).classify().value() + _s(this.props.module_name).classify().value();
82 | underscore_format = _s(this.props.module_name).underscored().value();
83 | titleize_format = _s(this.props.module_name).titleize().value();
84 |
85 | done();
86 | }.bind(this));
87 | },
88 |
89 | writing: function() {
90 |
91 | this.log('Working...');
92 |
93 | //admin
94 |
95 | this.fs.copyTpl(
96 | this.templatePath(oc_version + '/_admin_controller.php'),
97 | this.destinationPath(_s(CONTROLLER_DIR).replaceAll('%c%', 'admin').replaceAll('%t%', mod_type).value() + underscore_format + '.php'), {
98 | classified_name: classify_format,
99 | underscored_name: underscore_format,
100 | module_type: mod_type
101 | }
102 | );
103 |
104 | this.fs.copyTpl(
105 | this.templatePath(oc_version + '/_admin_language.php'),
106 | this.destinationPath(_s(LANGUAGE_DIR).replaceAll('%c%', 'admin').replaceAll('%t%', mod_type).value() + underscore_format + '.php'), {
107 | titleized_name: titleize_format,
108 | underscored_name: underscore_format,
109 | module_type: mod_type
110 | }
111 | );
112 |
113 | this.fs.copyTpl(
114 | this.templatePath(oc_version + '/_admin_view.tpl'),
115 | this.destinationPath(_s(ADMIN_VIEW_DIR).replaceAll('%t%', mod_type).value() + underscore_format + '.tpl'), {
116 | underscored_name: underscore_format,
117 | module_type: mod_type
118 | }
119 | );
120 |
121 | //catalog
122 |
123 | this.fs.copyTpl(
124 | this.templatePath(oc_version + '/_catalog_controller.php'),
125 | this.destinationPath(_s(CONTROLLER_DIR).replaceAll('%c%', 'catalog').replaceAll('%t%', mod_type).value() + underscore_format + '.php'), {
126 | classified_name: classify_format,
127 | underscored_name: underscore_format,
128 | module_type: mod_type
129 | }
130 | );
131 |
132 | this.fs.copyTpl(
133 | this.templatePath(oc_version + '/_catalog_language.php'),
134 | this.destinationPath(_s(LANGUAGE_DIR).replaceAll('%c%', 'catalog').replaceAll('%t%', mod_type).value() + underscore_format + '.php'), {
135 | titleized_name: titleize_format,
136 | module_type: mod_type
137 | }
138 | );
139 |
140 | this.fs.copyTpl(
141 | this.templatePath(oc_version + '/_catalog_model.php'),
142 | this.destinationPath(_s(MODEL_DIR).replaceAll('%c%', 'catalog').replaceAll('%t%', mod_type).value() + underscore_format + '.php'), {
143 | classified_name: classify_format,
144 | module_type: mod_type
145 | }
146 | );
147 |
148 | this.fs.copyTpl(
149 | this.templatePath(oc_version + '/_catalog_view.tpl'),
150 | this.destinationPath(_s(CATALOG_VIEW_DIR).replaceAll('%t%', mod_type).value() + underscore_format + '.tpl'), {
151 | titleized_name: titleize_format,
152 | module_type: mod_type
153 | }
154 | );
155 |
156 | //vqmod
157 | if (this.props.vqmod == true) {
158 | this.fs.copyTpl(
159 | this.templatePath(oc_version + '/_vqmod.xml'),
160 | this.destinationPath(VQMOD_DIR + underscore_format + '.xml'), {
161 | titleized_name: titleize_format,
162 | underscored_name: underscore_format
163 | }
164 | );
165 | }
166 |
167 | },
168 |
169 | end: function() {
170 | this.log(yosay(
171 | 'Your module starter ' + chalk.blue(titleize_format) + ' has been created successfully!'
172 | ));
173 | }
174 | });
--------------------------------------------------------------------------------
/generators/app/generate-module.ps1:
--------------------------------------------------------------------------------
1 | cls
2 |
3 | $CONTROLLER_DIR = 'upload/%c%/controller/%t%/'
4 | $LANGUAGE_DIR = 'upload/%c%/language/english/%t%/'
5 | $MODEL_DIR = 'upload/%c%/model/%t%/'
6 | $ADMIN_VIEW_DIR = 'upload/admin/view/template/%t%/'
7 | $CATALOG_VIEW_DIR = 'upload/catalog/view/theme/default/template/%t%/'
8 | $VQMOD_DIR = 'upload/vqmod/xml/'
9 |
10 |
11 | echo "Welcome to the Opencart Module starter generator!"
12 | ############# Prompts
13 |
14 | # Module Name
15 | $module_name = Read-Host -Prompt 'What name would you like for your module?'
16 | # End Module Name
17 |
18 | # Version
19 | $title = "Version"
20 | $message = "What version of Opencart will your module be for?"
21 |
22 | $v15x = New-Object System.Management.Automation.Host.ChoiceDescription "&1 1.5.x", `
23 | "1.5.x"
24 |
25 | $v2x = New-Object System.Management.Automation.Host.ChoiceDescription "&2 2.0x", `
26 | "2.x"
27 |
28 | $options = [System.Management.Automation.Host.ChoiceDescription[]]($v15x, $v2x)
29 |
30 | $result = $host.ui.PromptForChoice($title, $message, $options, 1)
31 |
32 | switch ($result)
33 | {
34 | 0 {$version = "1_5"}
35 | 1 {$version = "2_x"}
36 | }
37 |
38 | # End Version
39 |
40 | # Module Type
41 | $title = "Module Type"
42 | $message = "What type of module do you want to create?"
43 |
44 | $modtype_module = New-Object System.Management.Automation.Host.ChoiceDescription "&Module", `
45 | "module"
46 |
47 | $modtype_payment = New-Object System.Management.Automation.Host.ChoiceDescription "&Payment", `
48 | "payment"
49 |
50 | $modtype_shipping = New-Object System.Management.Automation.Host.ChoiceDescription "&Shipping", `
51 | "shipping"
52 |
53 | $modtype_total = New-Object System.Management.Automation.Host.ChoiceDescription "&Order Total", `
54 | "total"
55 |
56 | $modtype_feed = New-Object System.Management.Automation.Host.ChoiceDescription "&Feed", `
57 | "feed"
58 |
59 | $options = [System.Management.Automation.Host.ChoiceDescription[]]($modtype_module, $modtype_payment, $modtype_shipping, $modtype_total, $modtype_feed)
60 |
61 | $result = $host.ui.PromptForChoice($title, $message, $options, 0)
62 |
63 | switch ($result)
64 | {
65 | 0 {$module_type = "module"}
66 | 1 {$module_type = "payment"}
67 | 2 {$module_type = "shipping"}
68 | 2 {$module_type = "total"}
69 | 2 {$module_type = "feed"}
70 |
71 | }
72 |
73 | # END Module Type
74 |
75 |
76 | # vQMod Support
77 | $title = "vQMod Support"
78 | $message = "Will the module require vQmod support?"
79 |
80 | $yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes", `
81 | "true"
82 |
83 | $no = New-Object System.Management.Automation.Host.ChoiceDescription "&No", `
84 | "false"
85 |
86 | $options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no)
87 |
88 | $result = $host.ui.PromptForChoice($title, $message, $options, 1)
89 |
90 | switch ($result)
91 | {
92 | 0 {$vqmod = $true}
93 | 1 {$vqmod = $false}
94 | }
95 |
96 | # End vQMod SUpport
97 |
98 | $TextInfo = (Get-Culture).TextInfo
99 | $titleize_format = $TextInfo.ToTitleCase($module_name)
100 | $classify_format = $TextInfo.ToTitleCase($module_type) + $TextInfo.ToTitleCase($module_name) -replace (' ','')
101 | $underscore_format = $TextInfo.ToLower($module_name) -replace (' ','_')
102 |
103 |
104 | ######## End Prompts
105 |
106 | echo "Module: $module_name"
107 | echo "Version: $version"
108 | echo "Module Type: $module_type"
109 | echo "vQmod Support: $vqmod"
110 | echo "Titlized Module Name: $titleize_format"
111 | echo "Classify Module Name: $classify_format"
112 | echo "Undersore Module Name: $underscore_format"
113 |
114 |
115 | #############################################################
116 | ### Process Files ###########################################
117 | #############################################################
118 |
119 | $templateFile = "templates\$version\_admin_controller.php"
120 | $destinationFile = $CONTROLLER_DIR -replace ("%c%","admin") -replace ("%t%",$module_type)
121 | $destinationFile = $destinationFile + "$underscore_format.php"
122 | New-Item $destinationFile -Type file -Force | Out-Null
123 | Get-Content $templateFile |
124 | Foreach-Object { $_ -replace "<%= classified_name %>", "$classify_format" } |
125 | Foreach-Object { $_ -replace "<%= module_type %>","$module_type" } |
126 | Foreach-Object { $_ -replace "<%= underscored_name %>","$underscore_format" } |
127 | Set-Content -path "$destinationFile" -force
128 |
129 | $templateFile = "templates\$version\_admin_language.php"
130 | $destinationFile = $LANGUAGE_DIR -replace ("%c%","admin") -replace ("%t%",$module_type)
131 | $destinationFile = $destinationFile + "$underscore_format.php"
132 | New-Item $destinationFile -Type file -Force | Out-Null
133 | Get-Content $templateFile |
134 | Foreach-Object { $_ -replace "<%= classified_name %>", "$classify_format" } |
135 | Foreach-Object { $_ -replace "<%= titleized_name %>", "$titleize_format" } |
136 | Foreach-Object { $_ -replace "<%= module_type %>","$module_type" } |
137 | Foreach-Object { $_ -replace "<%= underscored_name %>","$underscore_format" } |
138 | Set-Content -path "$destinationFile" -force
139 |
140 | $templateFile = "templates\$version\_admin_view.tpl"
141 | $destinationFile = $ADMIN_VIEW_DIR -replace ("%t%",$module_type)
142 | $destinationFile = $destinationFile + "$underscore_format.tpl"
143 | New-Item $destinationFile -Type file -Force | Out-Null
144 | Get-Content $templateFile |
145 | Foreach-Object { $_ -replace "<%= classified_name %>", "$classify_format" } |
146 | Foreach-Object { $_ -replace "<%= titleized_name %>", "$titleize_format" } |
147 | Foreach-Object { $_ -replace "<%= module_type %>","$module_type" } |
148 | Foreach-Object { $_ -replace "<%= underscored_name %>","$underscore_format" } |
149 | Set-Content -path "$destinationFile" -force
150 |
151 | ############### Catalog ##################
152 |
153 | $templateFile = "templates\$version\_catalog_controller.php"
154 | $destinationFile = $CONTROLLER_DIR -replace ("%c%","catalog") -replace ("%t%",$module_type)
155 | $destinationFile = $destinationFile + "$underscore_format.php"
156 | New-Item $destinationFile -Type file -Force | Out-Null
157 | Get-Content $templateFile |
158 | Foreach-Object { $_ -replace "<%= classified_name %>", "$classify_format" } |
159 | Foreach-Object { $_ -replace "<%= titleized_name %>", "$titleize_format" } |
160 | Foreach-Object { $_ -replace "<%= module_type %>","$module_type" } |
161 | Foreach-Object { $_ -replace "<%= underscored_name %>","$underscore_format" } |
162 | Set-Content -path "$destinationFile" -force
163 |
164 |
165 | $templateFile = "templates\$version\_catalog_language.php"
166 | $destinationFile = $LANGUAGE_DIR -replace ("%c%","catalog") -replace ("%t%",$module_type)
167 | $destinationFile = $destinationFile + "$underscore_format.php"
168 | New-Item $destinationFile -Type file -Force | Out-Null
169 | Get-Content $templateFile |
170 | Foreach-Object { $_ -replace "<%= classified_name %>", "$classify_format" } |
171 | Foreach-Object { $_ -replace "<%= titleized_name %>", "$titleize_format" } |
172 | Foreach-Object { $_ -replace "<%= module_type %>","$module_type" } |
173 | Foreach-Object { $_ -replace "<%= underscored_name %>","$underscore_format" } |
174 | Set-Content -path "$destinationFile" -force
175 |
176 |
177 | $templateFile = "templates\$version\_catalog_model.php"
178 | $destinationFile = $MODEL_DIR -replace ("%c%","catalog") -replace ("%t%",$module_type)
179 | $destinationFile = $destinationFile + "$underscore_format.php"
180 | New-Item $destinationFile -Type file -Force | Out-Null
181 | Get-Content $templateFile |
182 | Foreach-Object { $_ -replace "<%= classified_name %>", "$classify_format" } |
183 | Foreach-Object { $_ -replace "<%= titleized_name %>", "$titleize_format" } |
184 | Foreach-Object { $_ -replace "<%= module_type %>","$module_type" } |
185 | Foreach-Object { $_ -replace "<%= underscored_name %>","$underscore_format" } |
186 | Set-Content -path "$destinationFile" -force
187 |
188 | $templateFile = "templates\$version\_catalog_view.tpl"
189 | $destinationFile = $CATALOG_VIEW_DIR -replace ("%c%","catalog") -replace ("%t%",$module_type)
190 | $destinationFile = $destinationFile + "$underscore_format.tpl"
191 | New-Item $destinationFile -Type file -Force | Out-Null
192 | Get-Content $templateFile |
193 | Foreach-Object { $_ -replace "<%= classified_name %>", "$classify_format" } |
194 | Foreach-Object { $_ -replace "<%= titleized_name %>", "$titleize_format" } |
195 | Foreach-Object { $_ -replace "<%= module_type %>","$module_type" } |
196 | Foreach-Object { $_ -replace "<%= underscored_name %>","$underscore_format" } |
197 | Set-Content -path "$destinationFile" -force
198 |
199 | ############## vQmod ########
200 |
201 | if ($vqmod -eq $true) {
202 | $templateFile = "templates\$version\_vqmod.xml"
203 | $destinationFile = $VQMOD_DIR -replace ("%c%","catalog") -replace ("%t%",$module_type)
204 | $destinationFile = $destinationFile + "$underscore_format.xml"
205 | New-Item $destinationFile -Type file -Force | Out-Null
206 | Get-Content $templateFile |
207 | Foreach-Object { $_ -replace "<%= classified_name %>", "$classify_format" } |
208 | Foreach-Object { $_ -replace "<%= titleized_name %>", "$titleize_format" } |
209 | Foreach-Object { $_ -replace "<%= module_type %>","$module_type" } |
210 | Foreach-Object { $_ -replace "<%= underscored_name %>","$underscore_format" } |
211 | Set-Content -path "$destinationFile" -force
212 | }
213 |
214 | echo " " " " "Your module starter $titleize_format has been created successfully!"
--------------------------------------------------------------------------------