-
Notifications
You must be signed in to change notification settings - Fork 0
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 #3 from nomo-app/init-nomo_cli.config.js
Init nomo cli.config.js
- Loading branch information
Showing
6 changed files
with
223 additions
and
88 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,38 +1,61 @@ | ||
export interface NomoManifest { | ||
/** | ||
* If min_nomo_version is set, then outdated versions of the Nomo App will refuse to install the WebOn. | ||
*/ | ||
min_nomo_version?: string | null; | ||
/** | ||
* nomo_manifest_version should be 1.1.0. | ||
*/ | ||
nomo_manifest_version: string; | ||
/** | ||
* A list of permissions for security-critical features. | ||
*/ | ||
permissions: string[]; | ||
/** | ||
* webon_id should be the reverse-domain of a domain that is owned by the WebOn-author. | ||
* See https://en.wikipedia.org/wiki/Reverse_domain_name_notation for more details about the reverse domain name notation. | ||
*/ | ||
webon_id: string; | ||
/** | ||
* webon_name is the user-visible name of the WebOn. | ||
*/ | ||
webon_name: string; | ||
/** | ||
* webon_version should comply with the semantic versioning standard. | ||
* See https://semver.org/ for details. | ||
*/ | ||
webon_version: string; | ||
/** | ||
* If true, then the WebOn could be displayed in both card-mode and fullscreen-mode. | ||
* If false, then the WebOn will only be displayed in fullscreen-mode. | ||
*/ | ||
card_mode?: boolean; | ||
/** | ||
* If defined, then the WebOn can decide whether a navigation bar should be shown or not. | ||
*/ | ||
show_navbar?: boolean; | ||
} | ||
|
||
/** | ||
* If min_nomo_version is set, then outdated versions of the Nomo App will refuse to install the WebOn. | ||
*/ | ||
min_nomo_version?: string | null; | ||
/** | ||
* nomo_manifest_version should be 1.1.0. | ||
*/ | ||
nomo_manifest_version: string; | ||
/** | ||
* A list of permissions for security-critical features. | ||
*/ | ||
permissions: string[]; | ||
/** | ||
* webon_id should be the reverse-domain of a domain that is owned by the WebOn-author. | ||
* See https://en.wikipedia.org/wiki/Reverse_domain_name_notation for more details about the reverse domain name notation. | ||
*/ | ||
webon_id: string; | ||
/** | ||
* webon_name is the user-visible name of the WebOn. | ||
*/ | ||
webon_name: string; | ||
/** | ||
* webon_version should comply with the semantic versioning standard. | ||
* See https://semver.org/ for details. | ||
*/ | ||
webon_version: string; | ||
/** | ||
* If true, then the WebOn could be displayed in both card-mode and fullscreen-mode. | ||
* If false, then the WebOn will only be displayed in fullscreen-mode. | ||
*/ | ||
card_mode?: boolean; | ||
/** | ||
* If defined, then the WebOn can decide whether a navigation bar should be shown or not. | ||
*/ | ||
show_navbar?: boolean; | ||
} | ||
|
||
export interface NomoCliConfig { | ||
deployTargets: { | ||
production: { | ||
rawSSH: { | ||
sshHost: string; | ||
sshBaseDir: string; | ||
publicBaseUrl: string; | ||
}; | ||
}; | ||
staging: { | ||
rawSSH: { | ||
sshHost: string; | ||
sshBaseDir: string; | ||
publicBaseUrl: string; | ||
sshPort: number; | ||
}; | ||
}; | ||
}; | ||
} | ||
export interface GeneratedFile { | ||
filePath: string; | ||
content: string; | ||
} |
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,75 @@ | ||
import { NomoManifest } from "../init/interface"; | ||
|
||
class WebOnError extends Error { | ||
constructor(message: string) { | ||
super(message); | ||
this.name = "WebOnError"; | ||
} | ||
} | ||
|
||
async function validateManifest( | ||
manifest: NomoManifest, | ||
webonUrl: string, | ||
{ devMode }: { devMode: boolean } | ||
): Promise<void> { | ||
const webonVersion = manifest.webon_version; | ||
if (!_isValidSemanticVersion(webonVersion)) { | ||
throw new WebOnError( | ||
`webon_version ${webonVersion} does not comply with semantic versioning regexp` | ||
); | ||
} | ||
|
||
const webonId = manifest.webon_id; | ||
if (!isValidWebOnId(webonId)) { | ||
throw new WebOnError(`webon_id ${webonId} does not comply with regexp`); | ||
} | ||
|
||
const manifestVersion = manifest.nomo_manifest_version; | ||
if (!_isValidSemanticVersion(manifestVersion)) { | ||
throw new WebOnError( | ||
`nomo_manifest_version ${manifestVersion} does not comply with semantic versioning regexp` | ||
); | ||
} | ||
|
||
if (manifest.webon_name.trim() == null) { | ||
throw new WebOnError("webon_name is empty"); | ||
} | ||
|
||
const minNomoVersion = manifest.min_nomo_version; | ||
if (minNomoVersion != null) { | ||
if (!_isValidSemanticVersion(minNomoVersion)) { | ||
throw new WebOnError( | ||
`min_nomo_version ${minNomoVersion} does not comply with semantic versioning regexp` | ||
); | ||
} | ||
// Assume you have a function similar to versionTwoGreaterThanVersionOne | ||
const currentVersion = "1.2.0"; // You need to replace this with the actual version | ||
if (versionTwoGreaterThanVersionOne(currentVersion, minNomoVersion)) { | ||
throw new WebOnError( | ||
`Nomo App outdated! This WebOn requires ${minNomoVersion}, but the current version is ${currentVersion}` | ||
); | ||
} | ||
} | ||
} | ||
|
||
|
||
function _isValidSemanticVersion(version: string): boolean { | ||
const pattern = /^(\d+)\.(\d+)\.(\d+)$/; | ||
const regex = new RegExp(pattern); | ||
return regex.test(version); | ||
} | ||
|
||
// Assuming versionTwoGreaterThanVersionOne is a function you have implemented | ||
function versionTwoGreaterThanVersionOne( | ||
versionTwo: string, | ||
versionOne: string | ||
): boolean { | ||
// Implement the comparison logic here | ||
return false; | ||
} | ||
|
||
export function isValidWebOnId(webon_id: string): boolean { | ||
const webonIdRegExp = | ||
/^(?:[a-zA-Z0-9_-]+\.)*[a-zA-Z0-9_-]+(?:\.[a-zA-Z0-9_-]+)+$/; | ||
return webonIdRegExp.test(webon_id); | ||
} |