-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from criticalmanufacturing/master-29617-Docume…
…ntationMaster Master 29617 documentation master
- Loading branch information
Showing
43 changed files
with
461 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
@@ -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; | ||
}); | ||
}) | ||
}); | ||
} | ||
|
||
|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default {}; |
Oops, something went wrong.