@c8y/websdk 1019.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,54 @@
1
+ **`@c8y/websdk` Package Overview**
2
+
3
+ The @c8y/websdk Angular schematic enables quick scaffolding of custom Cumulocity applications. It sets up an Angular environment integrated with essential Cumulocity features, allowing developers to efficiently focus on creating unique IoT solutions within the Cumulocity platform.
4
+
5
+ # How to use
6
+
7
+ ## Install
8
+ Install the Angular 16 `@angular/cli` package.
9
+
10
+ ```bash
11
+ npm install @angular/cli@v16-lts -g
12
+ ```
13
+
14
+ Generate a new Angular 16 application:
15
+
16
+ ```bash
17
+ ng new <appName> --interactive=false --routing=true --style=less
18
+ ```
19
+
20
+ Navigate to the application directory:
21
+
22
+ ```bash
23
+ cd <appName>
24
+ ```
25
+
26
+ Use the `ng add` command to include `@c8y/websdk`, and follow the prompts.
27
+
28
+ ```bash
29
+ ng add @c8y/websdk
30
+ ```
31
+
32
+ Bypass prompts:
33
+
34
+ ```bash
35
+ ng add @c8y/websdk --application=@c8y/<appName>@<version> --skip-confirmation
36
+ ```
37
+
38
+ > Note: In the **bypass prompts** scenario:
39
+ > - `<appName>` must be one of the following: administration, application, cockpit, codex, devicemanagement, hybrid, package-blueprint, tutorial, widget-plugin.
40
+ > - `<version>` denotes the specific package version listed in the npm registry.
41
+
42
+ ## Run development server & build
43
+
44
+ Launch the development server:
45
+
46
+ ```bash
47
+ ng serve -u https://<yourTenant>.latest.stage.c8y.io/
48
+ ```
49
+
50
+ Build the application:
51
+
52
+ ```bash
53
+ ng build <appName>
54
+ ```
@@ -0,0 +1 @@
1
+ ["administration","application","cockpit","codex","devicemanagement","hybrid","package-blueprint","tutorial","widget-plugin"]
@@ -0,0 +1,9 @@
1
+ {
2
+ "schematics": {
3
+ "ng-add": {
4
+ "description": "Adds Cumulocity IoT application to the project.",
5
+ "factory": "./ng-add/index#ngAdd",
6
+ "schema": "./ng-add/ng-add.json"
7
+ }
8
+ }
9
+ }
@@ -0,0 +1,9 @@
1
+ import { SchematicContext, Tree } from '@angular-devkit/schematics';
2
+ import { CumulocityNgAddOptions } from './ng-add.model';
3
+ /**
4
+ * This function adds a rule to the tree using the provided commandline options, predefined
5
+ * application options and module definitions.
6
+ * @param options - The options provided via commandline.
7
+ * @return a Rule function which applies the addition to the Tree and SchematicContext.
8
+ */
9
+ export declare function ngAdd(options: CumulocityNgAddOptions): (tree: Tree, context: SchematicContext) => Promise<void>;
@@ -0,0 +1,139 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ngAdd = void 0;
4
+ const tasks_1 = require("@angular-devkit/schematics/tasks");
5
+ const inquirer = require("inquirer");
6
+ const helpers_1 = require("yargs/helpers");
7
+ const pacote = require("pacote");
8
+ const yargs = require("yargs");
9
+ const fs_extra_1 = require("fs-extra");
10
+ const dependencies_1 = require("@schematics/angular/utility/dependencies");
11
+ const path_1 = require("path");
12
+ /**
13
+ * This function adds a rule to the tree using the provided commandline options, predefined
14
+ * application options and module definitions.
15
+ * @param options - The options provided via commandline.
16
+ * @return a Rule function which applies the addition to the Tree and SchematicContext.
17
+ */
18
+ function ngAdd(options) {
19
+ /**
20
+ * Return a Rule that applies the addition to the Tree and SchematicContext.
21
+ */
22
+ return async (tree, context) => {
23
+ const argv = await yargs((0, helpers_1.hideBin)(process.argv)).argv;
24
+ const registry = argv.registry || 'https://registry.npmjs.org/';
25
+ const { appName, selectedVersion } = await getApplicationNameAndVersion(options.application, registry);
26
+ triggerDevkitNgAdd(appName, selectedVersion, tree, context, options);
27
+ };
28
+ }
29
+ exports.ngAdd = ngAdd;
30
+ async function getApplicationNameAndVersion(argAppPackage, registry) {
31
+ // case 0: ''
32
+ if (!argAppPackage) {
33
+ const appName = await chooseProjectToScaffoldFrom();
34
+ const shownVersions = await getAllRelevantVersions(appName, registry);
35
+ const selectedVersion = await selectBaseVersion(shownVersions);
36
+ return { appName, selectedVersion };
37
+ }
38
+ const splitted = argAppPackage.split('@');
39
+ const isScoped = argAppPackage.startsWith('@');
40
+ // case 1: @c8y/cockpit@10.12.2 --> do not show any prompt
41
+ if (isScoped && splitted.length === 3) {
42
+ const [, appName, selectedVersion] = splitted;
43
+ return { appName: '@' + appName, selectedVersion };
44
+ }
45
+ // case 2: @c8y/cockpit
46
+ if (isScoped && splitted.length === 2) {
47
+ const appName = argAppPackage;
48
+ const shownVersions = await getAllRelevantVersions(appName, registry);
49
+ const selectedVersion = await selectBaseVersion(shownVersions);
50
+ return { appName, selectedVersion };
51
+ }
52
+ // case 3: cockpit
53
+ if (!isScoped && splitted.length === 1) {
54
+ const appName = argAppPackage;
55
+ const shownVersions = await getAllRelevantVersions(appName, registry);
56
+ const selectedVersion = await selectBaseVersion(shownVersions);
57
+ return { appName, selectedVersion };
58
+ }
59
+ // case 4: cockpit@10.10.10
60
+ if (!isScoped && splitted.length === 2) {
61
+ const [appName, selectedVersion] = splitted;
62
+ return { appName, selectedVersion };
63
+ }
64
+ // case 5: should actually not exist?!
65
+ return { appName: argAppPackage, selectedVersion: 'latest' };
66
+ }
67
+ function triggerDevkitNgAdd(appName, selectedVersion, tree, context, options) {
68
+ const dependencies = [
69
+ {
70
+ name: appName,
71
+ version: selectedVersion,
72
+ type: dependencies_1.NodeDependencyType.Dev
73
+ }
74
+ ];
75
+ dependencies.forEach(dependency => (0, dependencies_1.addPackageJsonDependency)(tree, dependency));
76
+ const taskId = context.addTask(new tasks_1.NodePackageInstallTask());
77
+ context.addTask(new tasks_1.RunSchematicTask('@c8y/devkit', 'ng-add', {
78
+ collection: null,
79
+ ...options,
80
+ application: appName
81
+ }), [taskId]);
82
+ }
83
+ async function chooseProjectToScaffoldFrom() {
84
+ const pathToAppList = (0, path_1.join)(__dirname, '../app-list.json');
85
+ const choices = await (0, fs_extra_1.readJson)(pathToAppList);
86
+ return inquirer
87
+ .prompt([
88
+ {
89
+ type: 'list',
90
+ name: 'base_project',
91
+ message: 'Which base project do you want to scaffold from?',
92
+ choices
93
+ }
94
+ ])
95
+ .then((input) => {
96
+ return `@c8y/${input.base_project}`;
97
+ });
98
+ }
99
+ async function selectBaseVersion(shownVersions) {
100
+ return inquirer
101
+ .prompt([
102
+ {
103
+ type: 'list',
104
+ name: 'base_version',
105
+ message: 'Which base version do you want to scaffold from?',
106
+ choices: shownVersions
107
+ }
108
+ ])
109
+ .then(async (answers) => {
110
+ if (answers.base_version.includes('latest') || answers.base_version.includes('next')) {
111
+ // Check if latest or next was selected and clean the string to include only the version.
112
+ answers.base_version = answers.base_version.split(' (')[0];
113
+ }
114
+ else if (answers.base_version === 'other') {
115
+ answers.base_version = await otherVersionSelectedPrompt();
116
+ }
117
+ return answers.base_version;
118
+ });
119
+ }
120
+ function otherVersionSelectedPrompt() {
121
+ return inquirer
122
+ .prompt([
123
+ {
124
+ type: 'input',
125
+ name: 'version_choice',
126
+ message: 'Enter the desired version: '
127
+ }
128
+ ])
129
+ .then((input) => {
130
+ return input.version_choice;
131
+ });
132
+ }
133
+ function getAllRelevantVersions(appName, registry) {
134
+ return pacote.packument(appName, { registry }).then(async (packument) => {
135
+ const versionList = Object.keys(packument.versions);
136
+ return [packument['dist-tags'].latest, ...versionList, 'other'];
137
+ });
138
+ }
139
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../ng-add/index.ts"],"names":[],"mappings":";;;AACA,4DAA4F;AAC5F,qCAAqC;AACrC,2CAAwC;AACxC,iCAAiC;AACjC,+BAA+B;AAC/B,uCAAoC;AACpC,2EAIkD;AAClD,+BAA4B;AAG5B;;;;;GAKG;AACH,SAAgB,KAAK,CAAC,OAA+B;IACnD;;OAEG;IACH,OAAO,KAAK,EAAE,IAAU,EAAE,OAAyB,EAAE,EAAE;QACrD,MAAM,IAAI,GAAG,MAAM,KAAK,CAAC,IAAA,iBAAO,EAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,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AM,CAAC;QACN;YACE,IAAI,EAAE,OAAO;YACb,IAAI,EAAE,gBAAgB;YACtB,OAAO,EAAE,6BAA6B;SACvC;KACF,CAAC;SACD,IAAI,CAAC,CAAC,KAAU,EAAE,EAAE;QACnB,OAAO,KAAK,CAAC,cAAc,CAAC;IAC9B,CAAC,CAAC,CAAC;AACP,CAAC;AAED,SAAS,sBAAsB,CAAC,OAAe,EAAE,QAAgB;IAC/D,OAAO,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,SAAc,EAAE,EAAE;QAC3E,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;QACpD,OAAO,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,MAAM,EAAE,GAAG,WAAW,EAAE,OAAO,CAAC,CAAC;IAClE,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,18 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "$id": "c8y-ng-add",
4
+ "title": "Cumulocity schematic",
5
+ "type": "object",
6
+ "properties": {
7
+ "project": {
8
+ "type": "string",
9
+ "description": "The name of the project.",
10
+ "$default": {
11
+ "$source": "projectName"
12
+ }
13
+ },
14
+ "application": {
15
+ "type": "string"
16
+ }
17
+ }
18
+ }
@@ -0,0 +1,4 @@
1
+ export interface CumulocityNgAddOptions {
2
+ application: string;
3
+ project: string;
4
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=ng-add.model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ng-add.model.js","sourceRoot":"","sources":["../../ng-add/ng-add.model.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@c8y/websdk",
3
+ "version": "1019.0.3",
4
+ "description": "Allows to scaffold a Cumulocity IoT application with ng add @c8y/websdk",
5
+ "license": "Apache-2.0",
6
+ "scripts": {
7
+ "test": "jest",
8
+ "build": "rimraf ./dist && tsc -p ./tsconfig.json && yarn build:applist",
9
+ "postbuild": "mkdirp ./dist/ng-add/ && yarn copy:schemas",
10
+ "copy:schemas": "npx ncp ./collection.json ./dist/collection.json && npx ncp ./ng-add/ng-add.json ./dist/ng-add/ng-add.json",
11
+ "build:applist": "ts-node ./tools/app-list-extract.ts"
12
+ },
13
+ "schematics": "./dist/collection.json",
14
+ "files": [
15
+ "dist/"
16
+ ],
17
+ "dependencies": {
18
+ "yargs": "17.7.2"
19
+ },
20
+ "devDependencies": {
21
+ "mkdirp": "3.0.1",
22
+ "ts-node": "10.9.1"
23
+ },
24
+ "author": ""
25
+ }