Skip to content

Commit

Permalink
Merge pull request #17 from criticalmanufacturing/master-29617-Docume…
Browse files Browse the repository at this point in the history
…ntationMaster

Master 29617 documentation master
  • Loading branch information
francisco-maciel authored Aug 6, 2018
2 parents 678f537 + 6caf9b0 commit 9354b95
Show file tree
Hide file tree
Showing 43 changed files with 461 additions and 177 deletions.
212 changes: 194 additions & 18 deletions generators/app/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
import * as path from "path";
import { HtmlGenerator } from "../html";
import { HtmlGenerator , WebAppName } from "../html";
import { Answers } from "yeoman-generator";

/**
* Interface the contains the address of a registry and the corresponding available channels
*/
interface RegistryChannels {
/**
* Address of the registry
*/
registry: string,
/**
* Available channels
*/
channels: string[] | null;
}

export = class extends HtmlGenerator {

packagePrefix: string;
Expand All @@ -24,29 +38,31 @@ export = class extends HtmlGenerator {
{
type : "input",
name : "packagePrefix",
message : "Please specify the client's prefix (example: cmf) ",
message : "Please specify the client's prefix (example: customization) ",
default : null,
validate: (input: string, answers: Answers): boolean => {
return typeof input === "string" && !!input && input !== "cmf";
},
store : true
},
{
type : "input",
name : "registry",
message : "What is your npm registry endpoint? ",
store : true
},
{
type : "input",
name : "channel",
message : "What is the channel you want to use?",
store : true
}
]).then((answers) => {
this.packagePrefix = answers.packagePrefix;
this.registry = answers.registry;
this.channel = answers.channel;
]).then((prefixAnswers) => {
this.packagePrefix = prefixAnswers.packagePrefix;
// Get the registry endpoint
return this._promptForRegistry()
.then((registryChannels) => {
this.registry = registryChannels.registry;
let options: string[] | null = null;
// If there are channels, use them on the prompt for channel
if (registryChannels != null && registryChannels.channels != null) {
options = registryChannels.channels;
options.push("other");
}
// Get the channel
return this._promptForChannel(options)
.then((channel) => {
this.channel = channel;
});
})
});
}

Expand All @@ -68,4 +84,164 @@ export = class extends HtmlGenerator {
this.config.set("isRoot", true);
this.config.save();
}

/**
* Utility method to prompt the user for channel
* @param options Available channels from the user to choose from
* @returns String containing the chosen channel
*/
private _promptForChannel(options: string[] | null): Promise<string> {
// Prompt for the user to select a channel from the list
if (options != null && options.length > 0) {
return this.prompt([
{
type : "list",
name : "channel",
message : "What channel from the available channels do you want to use?",
choices : options
},
]).then((listAnswers) => {
if (listAnswers.channel === "other") {
return this._promptForChannel(null);
} else {
return listAnswers.channel;
}
})
} else {
// Prompt for the user to input a channel
return this.prompt([
{
type : "input",
name : "channel",
message : "What is the channel you want to use?",
validate: (input: string, answers: Answers): boolean => {
return typeof input === "string" && !!input;
},
store: true
}
]).then((channelAnswer) => {
return channelAnswer.channel;
});
}
}

/**
* Utility method to ask the user to supply a channel
* @returns Registry and channel, if any
*/
_promptForRegistry(): Promise<RegistryChannels> {
return this.prompt([
{
type : "input",
name : "registry",
message : "What is your npm registry endpoint? ",
validate: (input: string, answers: Answers): boolean => {
return typeof input === "string" && !!input;
},
store : true
},
]).then((answers) => {
// Get the available channels and check that we can connect
const registryChannels = this._getChannelsFromRegistry(answers.registry);
if (registryChannels != null && registryChannels.channels != null && registryChannels.channels.length > 0) {
return registryChannels;
} else {
return this.prompt({
type : "input",
name : "confirmSkip",
message : "Registry was not found, do you wish to continue anyway? (y/n)",
validate: (input: string, answers: Answers): boolean => {
return typeof input === "string" && !!input;
},
store : false
}).then((confirmAnswers) => {
if (confirmAnswers.confirmSkip === "y" || confirmAnswers.confirmSkip === "yes" || confirmAnswers.confirmSkip === "Y" || confirmAnswers.confirmSkip === "YES") {
return <RegistryChannels> {
registry: answers.registry,
channels: null
}
} else {
return this._promptForRegistry();
}
})
}
});
}

/**
* Retrieves the available channel by calling npm info for the given registry
* @param registry registry endpoint
* @returns Registry and available channels, if any
*/
private _getChannelsFromRegistry(registry: string): RegistryChannels {
try {
const result = this.spawnCommandSync("npm", ["info", WebAppName.MES, `--registry=${registry}`, `--fetch-retry-maxtimeout=10`, `--fetch-retry-mintimeout=5`, "--json"], {stdio: 'pipe'});
if (result != null && result.stdout != null) {
const json = this._Utf8ArrayToStr(result.stdout)
if (json != null) {
const packageJson = JSON.parse(json);
if (packageJson != null && packageJson["dist-tags"] != null) {
const channels = Object.keys(packageJson["dist-tags"]);
return <RegistryChannels> {
registry: registry,
channels: channels
}
}
}
}
} catch(e) {
return <RegistryChannels> {
registry: registry,
channels: null
}
}

return <RegistryChannels> {
registry: registry,
channels: null
}
}


/* utf.js - UTF-8 <=> UTF-16 conversion
*
* http://www.onicos.com/staff/iz/amuse/javascript/expert/utf.txt
* Copyright (C) 1999 Masanao Izumo <[email protected]>
* Version: 1.0
* LastModified: Dec 25 1999
* This library is free. You can redistribute it and/or modify it.
*/
private _Utf8ArrayToStr(array) {
var out, i, len, c;
var char2, char3;

out = "";
len = array.length;
i = 0;
while(i < len) {
c = array[i++];
switch(c >> 4)
{
case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
// 0xxxxxxx
out += String.fromCharCode(c);
break;
case 12: case 13:
// 110x xxxx 10xx xxxx
char2 = array[i++];
out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F));
break;
case 14:
// 1110 xxxx 10xx xxxx 10xx xxxx
char2 = array[i++];
char3 = array[i++];
out += String.fromCharCode(((c & 0x0F) << 12) |
((char2 & 0x3F) << 6) |
((char3 & 0x3F) << 0));
break;
}
}

return out;
}
}
7 changes: 4 additions & 3 deletions generators/application/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as path from "path";
import { HtmlGenerator } from "../html";
import { HtmlGenerator , WebAppName} from "../html";
import { Answers } from "yeoman-generator";

export = class extends HtmlGenerator {
Expand Down Expand Up @@ -35,7 +35,7 @@ export = class extends HtmlGenerator {
type : "list",
name : "basePackage",
message : "What is the base package you want to use?",
choices : ["cmf.core.web.internal", "cmf.mes.web.internal", "other"]
choices : [WebAppName.MES, WebAppName.Core , "other"]
},
{
type : "input",
Expand Down Expand Up @@ -69,7 +69,8 @@ export = class extends HtmlGenerator {
registry: this.ctx.__config.registry
});
this.fs.copy(this.templatePath("web.config"), this.destinationPath("web.config"));
this.fs.copyTpl(this.templatePath("index.html"), this.destinationPath("index.html"), {isExtendingMes: this.basePackage === "cmf.mes.web.internal"});
this.fs.copy(this.templatePath("manifest.json"), this.destinationPath("manifest.json"));
this.fs.copyTpl(this.templatePath("index.html"), this.destinationPath("index.html"), {isExtendingMes: this.basePackage === WebAppName.MES});
}

install() {
Expand Down
1 change: 1 addition & 0 deletions generators/application/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />

<link rel="shortcut icon" href="node_modules/cmf.style/assets/img/favicon.ico" />
<link rel="manifest" href="/manifest.json">

<!-- Mobile configuration -->
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
Expand Down
21 changes: 21 additions & 0 deletions generators/application/templates/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"background_color": "#007ac9",
"display": "standalone",
"icons": [
{
"src": "/node_modules/cmf.style/assets/img/logoCMF_192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "/node_modules/cmf.style/assets/img/logoCMF_512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"name": "Critical Manufacturing",
"start_url": "/",
"short_name": "MES",
"theme_color": "#ffffff"
}

2 changes: 1 addition & 1 deletion generators/component/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export = class extends HtmlGenerator {
// This algorithm will make sure all situations are accounted. It will unshift the result instead of pushing as it would way more complicated to know where the array of literal end
const metadataFile = this.destinationPath(`${sourcePackageFolder}/../${packageName}.metadata.ts`);
const fileContent = this.fs.read(metadataFile);
const routeConfigSetting = { regex: /routeConfig[ ]{0,}:[\s\S]*?\[/, unshifter : () => {return `routeConfig: [\n{path: "${answers.url}", loadChildren: ` + "`${packageName}/src/components/" + `${this.options.componentName}/${this.options.componentName}#${this.componentClass}Module` + "`" + `, data: {title: "${this.componentClass}"}},\n`} };
const routeConfigSetting = { regex: /routeConfig[ ]{0,}:[\s\S]*?\[/, unshifter : () => {return `routeConfig: [\n {\n path: "${answers.url}",\n loadChildren: ` + "`${packageName}/src/components/" + `${this.options.componentName}/${this.options.componentName}#${this.componentClass}Module` + "`" + `,\n data: {title: "${this.componentClass}"}\n },\n`} };
const routesSetting = { regex: /routes[ ]{0,}:[\s\S]*?\[/, unshifter: () => {return `routes: [\n{\n\n${routeConfigSetting.unshifter()}]\n}\n`} };
const flexSetting = { regex: /flex[ ]{0,}:[\s\S]*?\{/, unshifter: () => {return `flex: {\n${routesSetting.unshifter()}],\n`} };
const matchedSetting = [routeConfigSetting, routesSetting, flexSetting].find((setting) => fileContent.match(setting.regex) != null);
Expand Down
25 changes: 9 additions & 16 deletions generators/component/templates/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,26 +42,22 @@ import * as ng from "@angular/core";
* * Where and When to use it?
*
* ### Inputs
* (Provide a detailed list of the inputs here. Syntax for each input description:
* " * type [string, number, Object...] : name - description") Ex:
* `string` : **name** - The name of this component
* `number` : **value** - The value of this component
*
* ### Outputs
* (Provide a detailed list of the outputs here. Syntax for each output description:
* " * type [string, number, Object...] : name - description") Ex:
* `string` : **onNameChange** - When the name of the component change, this output emits the new name
* `number` : **onValueChange** - When the value of the component change, this output emits the new value
*
* ### Example
* To use the component, assume this HTML Template as an example:
*
* ```HTML
* <<%= component.selector %> [input]="myInputValue" (output)="myOutputValue"></<%= component.selector %>>
* <<%= component.selector %>></<%= component.selector %>>
* ```
*
* ### _NOTES_ (optional)
* (Provide additional notes here)
* ### _NOTES_
* (optional, Provide additional notes here)
*
* @description
*
Expand All @@ -70,19 +66,16 @@ import * as ng from "@angular/core";
* ### Dependencies
*
* #### Components
* (Provide a detailed list of components that this component depends on) Ex:
* * ComponentA : `package` (Ex: `cmf.core.controls`)
* * ComponentB : `package` (Ex: `cmf.core.controls`)
* * ComponentA : `package`
* * ComponentB : `package`
*
* #### Services
* (Provide a detailed list of services that this component depends on) Ex:
* * ServiceA : `package` (Ex: `cmf.core.controls`)
* * ServiceB : `package` (Ex: `cmf.core.controls`)
* * ServiceA : `package`
* * ServiceB : `package`
*
* #### Directives
* (Provide a detailed list of directives that this component depends on) Ex:
* * DirectiveA : `package` (Ex: `cmf.core.controls`)
* * DirectiveB : `package` (Ex: `cmf.core.controls`)
* * DirectiveA : `package`
* * DirectiveB : `package`
*
*/
@Component({
Expand Down
1 change: 1 addition & 0 deletions generators/component/templates/i18n/component.zh-CN.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {};
1 change: 1 addition & 0 deletions generators/component/templates/i18n/component.zh-TW.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {};
Loading

0 comments on commit 9354b95

Please sign in to comment.