Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
pixeldublu committed Mar 8, 2020
1 parent 1bf54ec commit c2c1438
Show file tree
Hide file tree
Showing 20 changed files with 2,687 additions and 2,254 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2019 pixeldublu <[email protected]>
Copyright (c) 2020 pixeldublu <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
37 changes: 36 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,36 @@
npm install and then npm link and then you can use yo ngx-rocket-module-generator
# generator-ngx-rocket-list-edit-module [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-image]][daviddm-url]
> Generates ngx rocket style module with list and manage edit view
## Installation

First, install [Yeoman](http://yeoman.io) and generator-ngx-rocket-list-edit-module using [npm](https://www.npmjs.com/) (we assume you have pre-installed [node.js](https://nodejs.org/)).

```bash
npm install -g yo
npm install -g generator-ngx-rocket-list-edit-module
```

Then generate your new project:

```bash
yo ngx-rocket-list-edit-module
```

## Getting To Know Yeoman

* Yeoman has a heart of gold.
* Yeoman is a person with feelings and opinions, but is very easy to work with.
* Yeoman can be too opinionated at times but is easily convinced not to be.
* Feel free to [learn more about Yeoman](http://yeoman.io/).

## License

MIT © [pixeldublu]()


[npm-image]: https://badge.fury.io/js/generator-ngx-rocket-list-edit-module.svg
[npm-url]: https://npmjs.org/package/generator-ngx-rocket-list-edit-module
[travis-image]: https://travis-ci.com/pixeldublu/generator-ngx-rocket-list-edit-module.svg?branch=master
[travis-url]: https://travis-ci.com/pixeldublu/generator-ngx-rocket-list-edit-module
[daviddm-image]: https://david-dm.org/pixeldublu/generator-ngx-rocket-list-edit-module.svg?theme=shields.io
[daviddm-url]: https://david-dm.org/pixeldublu/generator-ngx-rocket-list-edit-module
16 changes: 16 additions & 0 deletions __tests__/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';
const path = require('path');
const assert = require('yeoman-assert');
const helpers = require('yeoman-test');

describe('generator-ngx-rocket-list-edit-module:app', () => {
beforeAll(() => {
return helpers
.run(path.join(__dirname, '../generators/app'))
.withPrompts({ someAnswer: true });
});

it('creates files', () => {
assert.file(['dummyfile.txt']);
});
});
80 changes: 43 additions & 37 deletions generators/app/index.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
"use strict";
const Generator = require("yeoman-generator");
const chalk = require("chalk");
const glob = require("glob");
const yosay = require("yosay");
const glob = require("glob");

module.exports = class extends Generator {
async prompting() {
let answers;

// Have Yeoman greet the user.
this.log(
yosay(
`Welcome to the lovely ${chalk.red(
"yo-ngx-rocket-module-generator"
)} generator!
Use this only from the main angular folder!`
)
prompting() {
yosay(
`Welcome to the lovely ${chalk.red(
"yo-ngx-rocket-module-generator"
)} generator!
Use this only from the main angular folder!`
);

const prompts = [{
const prompts = [
{
type: "input",
name: "name",
message: "yo-ngx-rocket-module-generator module name ? Start with uppercase. Ex: Cars"
message:
"yo-ngx-rocket-module-generator module name ? Start with uppercase. Ex: Cars"
},
{
type: "input",
Expand All @@ -38,33 +35,42 @@ module.exports = class extends Generator {

writing() {
const parent = this;
glob(this.templatePath() + "/**/*", function (err, files) {
files.forEach(file => {
const originalFileName = file.replace(
parent.templatePath().replace(/\\/gi, "/") + "/",
""
);
const newFileName = originalFileName.replace(
/template/gi,
String(parent.props.name).toLowerCase()
);
if (/\./gi.test(originalFileName)) {
parent.fs.copyTpl(
parent.templatePath(originalFileName),
parent.destinationPath('src/app/' + String(parent.props.name).toLowerCase() + '/' + newFileName), {
mainTitle: parent.props.name,
secondaryTitle: String(parent.props.name).toLowerCase(),
mainModel: parent.props.model,
secondaryModel: String(parent.props.model).toLowerCase()
}
glob(this.templatePath() + "/**/*", function(err, files) {
if (err) {
console.error(err);
} else {
files.forEach(file => {
const originalFileName = file.replace(
parent.templatePath().replace(/\\/gi, "/") + "/",
""
);
}

});
const newFileName = originalFileName.replace(
/template/gi,
String(parent.props.name).toLowerCase()
);
if (/\./gi.test(originalFileName)) {
parent.fs.copyTpl(
parent.templatePath(originalFileName),
parent.destinationPath(
"src/app/" +
String(parent.props.name).toLowerCase() +
"/" +
newFileName
),
{
mainTitle: parent.props.name,
secondaryTitle: String(parent.props.name).toLowerCase(),
mainModel: parent.props.model,
secondaryModel: String(parent.props.model).toLowerCase()
}
);
}
});
}
});
}

install() {
// this.installDependencies();
// This.installDependencies();
}
};
79 changes: 79 additions & 0 deletions generators/app/templates/core/configuration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
export interface ConfigurationParameters {
apiKeys?: { [key: string]: string };
username?: string;
password?: string;
accessToken?: string | (() => string);
basePath?: string;
withCredentials?: boolean;
}

export class Configuration {
apiKeys?: { [key: string]: string };
username?: string;
password?: string;
accessToken?: string | (() => string);
basePath?: string;
withCredentials?: boolean;

constructor(configurationParameters: ConfigurationParameters = {}) {
this.apiKeys = configurationParameters.apiKeys;
this.username = configurationParameters.username;
this.password = configurationParameters.password;
this.accessToken = configurationParameters.accessToken;
this.basePath = configurationParameters.basePath;
this.withCredentials = configurationParameters.withCredentials;
}

/**
* Select the correct content-type to use for a request.
* Uses {@link Configuration#isJsonMime} to determine the correct content-type.
* If no content type is found return the first found type if the contentTypes is not empty
* @param contentTypes - the array of content types that are available for selection
* @returns the selected content-type or <code>undefined</code> if no selection could be made.
*/
public selectHeaderContentType(contentTypes: string[]): string | undefined {
if (contentTypes.length == 0) {
return undefined;
}

let type = contentTypes.find(x => this.isJsonMime(x));
if (type === undefined) {
return contentTypes[0];
}
return type;
}

/**
* Select the correct accept content-type to use for a request.
* Uses {@link Configuration#isJsonMime} to determine the correct accept content-type.
* If no content type is found return the first found type if the contentTypes is not empty
* @param accepts - the array of content types that are available for selection.
* @returns the selected content-type or <code>undefined</code> if no selection could be made.
*/
public selectHeaderAccept(accepts: string[]): string | undefined {
if (accepts.length == 0) {
return undefined;
}

let type = accepts.find(x => this.isJsonMime(x));
if (type === undefined) {
return accepts[0];
}
return type;
}

/**
* Check if the given MIME is a JSON MIME.
* JSON MIME examples:
* application/json
* application/json; charset=UTF8
* APPLICATION/JSON
* application/vnd.company+json
* @param mime - MIME (Multipurpose Internet Mail Extensions)
* @return True if the given MIME is JSON, false otherwise.
*/
public isJsonMime(mime: string): boolean {
const jsonMime: RegExp = new RegExp('^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i');
return mime != null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json');
}
}
13 changes: 13 additions & 0 deletions generators/app/templates/core/models/template.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
*
* OpenAPI spec version: 0.0.1
*
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
*/

export interface <%= mainModel %> {
id?: number;
name?: string;
}
Loading

0 comments on commit c2c1438

Please sign in to comment.