Skip to content

Commit 9354b95

Browse files
Merge pull request #17 from criticalmanufacturing/master-29617-DocumentationMaster
Master 29617 documentation master
2 parents 678f537 + 6caf9b0 commit 9354b95

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+461
-177
lines changed

generators/app/index.ts

+194-18
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
import * as path from "path";
2-
import { HtmlGenerator } from "../html";
2+
import { HtmlGenerator , WebAppName } from "../html";
33
import { Answers } from "yeoman-generator";
44

5+
/**
6+
* Interface the contains the address of a registry and the corresponding available channels
7+
*/
8+
interface RegistryChannels {
9+
/**
10+
* Address of the registry
11+
*/
12+
registry: string,
13+
/**
14+
* Available channels
15+
*/
16+
channels: string[] | null;
17+
}
18+
519
export = class extends HtmlGenerator {
620

721
packagePrefix: string;
@@ -24,29 +38,31 @@ export = class extends HtmlGenerator {
2438
{
2539
type : "input",
2640
name : "packagePrefix",
27-
message : "Please specify the client's prefix (example: cmf) ",
41+
message : "Please specify the client's prefix (example: customization) ",
2842
default : null,
2943
validate: (input: string, answers: Answers): boolean => {
3044
return typeof input === "string" && !!input && input !== "cmf";
3145
},
3246
store : true
33-
},
34-
{
35-
type : "input",
36-
name : "registry",
37-
message : "What is your npm registry endpoint? ",
38-
store : true
39-
},
40-
{
41-
type : "input",
42-
name : "channel",
43-
message : "What is the channel you want to use?",
44-
store : true
4547
}
46-
]).then((answers) => {
47-
this.packagePrefix = answers.packagePrefix;
48-
this.registry = answers.registry;
49-
this.channel = answers.channel;
48+
]).then((prefixAnswers) => {
49+
this.packagePrefix = prefixAnswers.packagePrefix;
50+
// Get the registry endpoint
51+
return this._promptForRegistry()
52+
.then((registryChannels) => {
53+
this.registry = registryChannels.registry;
54+
let options: string[] | null = null;
55+
// If there are channels, use them on the prompt for channel
56+
if (registryChannels != null && registryChannels.channels != null) {
57+
options = registryChannels.channels;
58+
options.push("other");
59+
}
60+
// Get the channel
61+
return this._promptForChannel(options)
62+
.then((channel) => {
63+
this.channel = channel;
64+
});
65+
})
5066
});
5167
}
5268

@@ -68,4 +84,164 @@ export = class extends HtmlGenerator {
6884
this.config.set("isRoot", true);
6985
this.config.save();
7086
}
87+
88+
/**
89+
* Utility method to prompt the user for channel
90+
* @param options Available channels from the user to choose from
91+
* @returns String containing the chosen channel
92+
*/
93+
private _promptForChannel(options: string[] | null): Promise<string> {
94+
// Prompt for the user to select a channel from the list
95+
if (options != null && options.length > 0) {
96+
return this.prompt([
97+
{
98+
type : "list",
99+
name : "channel",
100+
message : "What channel from the available channels do you want to use?",
101+
choices : options
102+
},
103+
]).then((listAnswers) => {
104+
if (listAnswers.channel === "other") {
105+
return this._promptForChannel(null);
106+
} else {
107+
return listAnswers.channel;
108+
}
109+
})
110+
} else {
111+
// Prompt for the user to input a channel
112+
return this.prompt([
113+
{
114+
type : "input",
115+
name : "channel",
116+
message : "What is the channel you want to use?",
117+
validate: (input: string, answers: Answers): boolean => {
118+
return typeof input === "string" && !!input;
119+
},
120+
store: true
121+
}
122+
]).then((channelAnswer) => {
123+
return channelAnswer.channel;
124+
});
125+
}
126+
}
127+
128+
/**
129+
* Utility method to ask the user to supply a channel
130+
* @returns Registry and channel, if any
131+
*/
132+
_promptForRegistry(): Promise<RegistryChannels> {
133+
return this.prompt([
134+
{
135+
type : "input",
136+
name : "registry",
137+
message : "What is your npm registry endpoint? ",
138+
validate: (input: string, answers: Answers): boolean => {
139+
return typeof input === "string" && !!input;
140+
},
141+
store : true
142+
},
143+
]).then((answers) => {
144+
// Get the available channels and check that we can connect
145+
const registryChannels = this._getChannelsFromRegistry(answers.registry);
146+
if (registryChannels != null && registryChannels.channels != null && registryChannels.channels.length > 0) {
147+
return registryChannels;
148+
} else {
149+
return this.prompt({
150+
type : "input",
151+
name : "confirmSkip",
152+
message : "Registry was not found, do you wish to continue anyway? (y/n)",
153+
validate: (input: string, answers: Answers): boolean => {
154+
return typeof input === "string" && !!input;
155+
},
156+
store : false
157+
}).then((confirmAnswers) => {
158+
if (confirmAnswers.confirmSkip === "y" || confirmAnswers.confirmSkip === "yes" || confirmAnswers.confirmSkip === "Y" || confirmAnswers.confirmSkip === "YES") {
159+
return <RegistryChannels> {
160+
registry: answers.registry,
161+
channels: null
162+
}
163+
} else {
164+
return this._promptForRegistry();
165+
}
166+
})
167+
}
168+
});
169+
}
170+
171+
/**
172+
* Retrieves the available channel by calling npm info for the given registry
173+
* @param registry registry endpoint
174+
* @returns Registry and available channels, if any
175+
*/
176+
private _getChannelsFromRegistry(registry: string): RegistryChannels {
177+
try {
178+
const result = this.spawnCommandSync("npm", ["info", WebAppName.MES, `--registry=${registry}`, `--fetch-retry-maxtimeout=10`, `--fetch-retry-mintimeout=5`, "--json"], {stdio: 'pipe'});
179+
if (result != null && result.stdout != null) {
180+
const json = this._Utf8ArrayToStr(result.stdout)
181+
if (json != null) {
182+
const packageJson = JSON.parse(json);
183+
if (packageJson != null && packageJson["dist-tags"] != null) {
184+
const channels = Object.keys(packageJson["dist-tags"]);
185+
return <RegistryChannels> {
186+
registry: registry,
187+
channels: channels
188+
}
189+
}
190+
}
191+
}
192+
} catch(e) {
193+
return <RegistryChannels> {
194+
registry: registry,
195+
channels: null
196+
}
197+
}
198+
199+
return <RegistryChannels> {
200+
registry: registry,
201+
channels: null
202+
}
203+
}
204+
205+
206+
/* utf.js - UTF-8 <=> UTF-16 conversion
207+
*
208+
* http://www.onicos.com/staff/iz/amuse/javascript/expert/utf.txt
209+
* Copyright (C) 1999 Masanao Izumo <[email protected]>
210+
* Version: 1.0
211+
* LastModified: Dec 25 1999
212+
* This library is free. You can redistribute it and/or modify it.
213+
*/
214+
private _Utf8ArrayToStr(array) {
215+
var out, i, len, c;
216+
var char2, char3;
217+
218+
out = "";
219+
len = array.length;
220+
i = 0;
221+
while(i < len) {
222+
c = array[i++];
223+
switch(c >> 4)
224+
{
225+
case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
226+
// 0xxxxxxx
227+
out += String.fromCharCode(c);
228+
break;
229+
case 12: case 13:
230+
// 110x xxxx 10xx xxxx
231+
char2 = array[i++];
232+
out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F));
233+
break;
234+
case 14:
235+
// 1110 xxxx 10xx xxxx 10xx xxxx
236+
char2 = array[i++];
237+
char3 = array[i++];
238+
out += String.fromCharCode(((c & 0x0F) << 12) |
239+
((char2 & 0x3F) << 6) |
240+
((char3 & 0x3F) << 0));
241+
break;
242+
}
243+
}
244+
245+
return out;
246+
}
71247
}

generators/application/index.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as path from "path";
2-
import { HtmlGenerator } from "../html";
2+
import { HtmlGenerator , WebAppName} from "../html";
33
import { Answers } from "yeoman-generator";
44

55
export = class extends HtmlGenerator {
@@ -35,7 +35,7 @@ export = class extends HtmlGenerator {
3535
type : "list",
3636
name : "basePackage",
3737
message : "What is the base package you want to use?",
38-
choices : ["cmf.core.web.internal", "cmf.mes.web.internal", "other"]
38+
choices : [WebAppName.MES, WebAppName.Core , "other"]
3939
},
4040
{
4141
type : "input",
@@ -69,7 +69,8 @@ export = class extends HtmlGenerator {
6969
registry: this.ctx.__config.registry
7070
});
7171
this.fs.copy(this.templatePath("web.config"), this.destinationPath("web.config"));
72-
this.fs.copyTpl(this.templatePath("index.html"), this.destinationPath("index.html"), {isExtendingMes: this.basePackage === "cmf.mes.web.internal"});
72+
this.fs.copy(this.templatePath("manifest.json"), this.destinationPath("manifest.json"));
73+
this.fs.copyTpl(this.templatePath("index.html"), this.destinationPath("index.html"), {isExtendingMes: this.basePackage === WebAppName.MES});
7374
}
7475

7576
install() {

generators/application/templates/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
66

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

910
<!-- Mobile configuration -->
1011
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"background_color": "#007ac9",
3+
"display": "standalone",
4+
"icons": [
5+
{
6+
"src": "/node_modules/cmf.style/assets/img/logoCMF_192.png",
7+
"type": "image/png",
8+
"sizes": "192x192"
9+
},
10+
{
11+
"src": "/node_modules/cmf.style/assets/img/logoCMF_512.png",
12+
"type": "image/png",
13+
"sizes": "512x512"
14+
}
15+
],
16+
"name": "Critical Manufacturing",
17+
"start_url": "/",
18+
"short_name": "MES",
19+
"theme_color": "#ffffff"
20+
}
21+

generators/component/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export = class extends HtmlGenerator {
6868
// 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
6969
const metadataFile = this.destinationPath(`${sourcePackageFolder}/../${packageName}.metadata.ts`);
7070
const fileContent = this.fs.read(metadataFile);
71-
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`} };
71+
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`} };
7272
const routesSetting = { regex: /routes[ ]{0,}:[\s\S]*?\[/, unshifter: () => {return `routes: [\n{\n\n${routeConfigSetting.unshifter()}]\n}\n`} };
7373
const flexSetting = { regex: /flex[ ]{0,}:[\s\S]*?\{/, unshifter: () => {return `flex: {\n${routesSetting.unshifter()}],\n`} };
7474
const matchedSetting = [routeConfigSetting, routesSetting, flexSetting].find((setting) => fileContent.match(setting.regex) != null);

generators/component/templates/component.ts

+9-16
Original file line numberDiff line numberDiff line change
@@ -42,26 +42,22 @@ import * as ng from "@angular/core";
4242
* * Where and When to use it?
4343
*
4444
* ### Inputs
45-
* (Provide a detailed list of the inputs here. Syntax for each input description:
46-
* " * type [string, number, Object...] : name - description") Ex:
4745
* `string` : **name** - The name of this component
4846
* `number` : **value** - The value of this component
4947
*
5048
* ### Outputs
51-
* (Provide a detailed list of the outputs here. Syntax for each output description:
52-
* " * type [string, number, Object...] : name - description") Ex:
5349
* `string` : **onNameChange** - When the name of the component change, this output emits the new name
5450
* `number` : **onValueChange** - When the value of the component change, this output emits the new value
5551
*
5652
* ### Example
5753
* To use the component, assume this HTML Template as an example:
5854
*
5955
* ```HTML
60-
* <<%= component.selector %> [input]="myInputValue" (output)="myOutputValue"></<%= component.selector %>>
56+
* <<%= component.selector %>></<%= component.selector %>>
6157
* ```
6258
*
63-
* ### _NOTES_ (optional)
64-
* (Provide additional notes here)
59+
* ### _NOTES_
60+
* (optional, Provide additional notes here)
6561
*
6662
* @description
6763
*
@@ -70,19 +66,16 @@ import * as ng from "@angular/core";
7066
* ### Dependencies
7167
*
7268
* #### Components
73-
* (Provide a detailed list of components that this component depends on) Ex:
74-
* * ComponentA : `package` (Ex: `cmf.core.controls`)
75-
* * ComponentB : `package` (Ex: `cmf.core.controls`)
69+
* * ComponentA : `package`
70+
* * ComponentB : `package`
7671
*
7772
* #### Services
78-
* (Provide a detailed list of services that this component depends on) Ex:
79-
* * ServiceA : `package` (Ex: `cmf.core.controls`)
80-
* * ServiceB : `package` (Ex: `cmf.core.controls`)
73+
* * ServiceA : `package`
74+
* * ServiceB : `package`
8175
*
8276
* #### Directives
83-
* (Provide a detailed list of directives that this component depends on) Ex:
84-
* * DirectiveA : `package` (Ex: `cmf.core.controls`)
85-
* * DirectiveB : `package` (Ex: `cmf.core.controls`)
77+
* * DirectiveA : `package`
78+
* * DirectiveB : `package`
8679
*
8780
*/
8881
@Component({
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default {};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default {};

0 commit comments

Comments
 (0)