Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@eclipse-che/che-devworkspace-generator

Package Overview
Dependencies
Maintainers
5
Versions
143
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@eclipse-che/che-devworkspace-generator - npm Package Compare versions

Comparing version 0.0.1-7784e80 to 0.0.1-bd2d989

lib/api/devfile-context.d.ts

3

lib/generate.js

@@ -90,2 +90,3 @@ "use strict";

context = _a.sent();
if (!outputFile) return [3 /*break*/, 3];
allContentArray = context.devWorkspaceTemplates.map(function (template) { return jsYaml.dump(template); });

@@ -97,2 +98,4 @@ allContentArray.push(jsYaml.dump(context.devWorkspace));

_a.sent();
_a.label = 3;
case 3:
console.log("DevWorkspace " + context.devWorkspaceTemplates[0].metadata.name + " was generated.");

@@ -99,0 +102,0 @@ return [2 /*return*/, context];

131

lib/main.js

@@ -77,41 +77,22 @@ "use strict";

var Main = /** @class */ (function () {
/**
* Default constructor.
*/
function Main() {
// no-op
}
Main.prototype.doStart = function () {
// Generates a devfile context object based on params
Main.prototype.generateDevfileContext = function (params) {
return __awaiter(this, void 0, void 0, function () {
var devfilePath, devfileUrl, outputFile, editorPath, pluginRegistryUrl, editorEntry, projects, args, axiosInstance, inversifyBinbding, container, devfileContent, editorContent, githubResolver, githubUrl, devfileParsed, editorDevfile, generate;
var devfilePath, devfileUrl, outputFile, editorPath, pluginRegistryUrl, editorEntry, projects, axiosInstance, inversifyBinbding, container, devfileContent, editorContent, githubResolver, githubUrl, devfileParsed, editorDevfile, generate;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
projects = [];
args = process.argv.slice(2);
args.forEach(function (arg) {
if (arg.startsWith('--devfile-path:')) {
devfilePath = arg.substring('--devfile-path:'.length);
}
if (arg.startsWith('--devfile-url:')) {
devfileUrl = arg.substring('--devfile-url:'.length);
}
if (arg.startsWith('--plugin-registry-url:')) {
pluginRegistryUrl = arg.substring('--plugin-registry-url:'.length);
}
if (arg.startsWith('--editor-entry:')) {
editorEntry = arg.substring('--editor-entry:'.length);
}
if (arg.startsWith('--editor-path:')) {
editorPath = arg.substring('--editor-path:'.length);
}
if (arg.startsWith('--output-file:')) {
outputFile = arg.substring('--output-file:'.length);
}
if (arg.startsWith('--project.')) {
var name = arg.substring('--project.'.length, arg.indexOf('='));
var location = arg.substring(arg.indexOf('=') + 1);
location = location.replace('{{_INTERNAL_URL_}}', '{{ INTERNAL_URL }}');
projects.push({ name: name, location: location });
}
});
devfilePath = params.devfilePath, devfileUrl = params.devfileUrl, outputFile = params.outputFile, editorPath = params.editorPath, pluginRegistryUrl = params.pluginRegistryUrl, editorEntry = params.editorEntry, projects = params.projects;
if (!editorPath && !editorEntry) {
throw new Error('missing --editor-path: or --editor-entry: parameter');
throw new Error('missing editorPath or editorEntry');
}
if (!devfilePath && !devfileUrl && !params.devfileContent) {
throw new Error('missing devfilePath or devfileUrl or devfileContent');
}
if (editorEntry && !pluginRegistryUrl) {

@@ -121,8 +102,2 @@ pluginRegistryUrl = 'https://eclipse-che.github.io/che-plugin-registry/main/v3';

}
if (!devfilePath && !devfileUrl) {
throw new Error('missing --devfile-path: or --devfile-url: parameter');
}
if (!outputFile) {
throw new Error('missing --output-file: parameter');
}
axiosInstance = axios["default"];

@@ -160,21 +135,26 @@ inversifyBinbding = new inversify_binding_1.InversifyBinding();

devfileContent = jsYaml.dump(devfileParsed);
return [3 /*break*/, 5];
case 3: return [4 /*yield*/, fs.readFile(devfilePath)];
return [3 /*break*/, 6];
case 3:
if (!devfilePath) return [3 /*break*/, 5];
return [4 /*yield*/, fs.readFile(devfilePath)];
case 4:
devfileContent = _a.sent();
_a.label = 5;
return [3 /*break*/, 6];
case 5:
devfileContent = params.devfileContent;
_a.label = 6;
case 6:
// enhance projects
devfileContent = this.replaceIfExistingProjects(devfileContent, projects);
if (!editorEntry) return [3 /*break*/, 7];
if (!editorEntry) return [3 /*break*/, 8];
return [4 /*yield*/, container.get(plugin_registry_resolver_1.PluginRegistryResolver).loadDevfilePlugin(editorEntry)];
case 6:
case 7:
editorDevfile = _a.sent();
editorContent = jsYaml.dump(editorDevfile);
return [3 /*break*/, 9];
case 7: return [4 /*yield*/, fs.readFile(editorPath)];
case 8:
return [3 /*break*/, 10];
case 8: return [4 /*yield*/, fs.readFile(editorPath)];
case 9:
editorContent = _a.sent();
_a.label = 9;
case 9:
_a.label = 10;
case 10:
generate = container.get(generate_1.Generate);

@@ -214,12 +194,59 @@ return [2 /*return*/, generate.generate(devfileContent, editorContent, outputFile)];

return __awaiter(this, void 0, void 0, function () {
var error_1;
var devfilePath, devfileUrl, outputFile, editorPath, pluginRegistryUrl, editorEntry, projects, args, error_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
return [4 /*yield*/, this.doStart()];
projects = [];
args = process.argv.slice(2);
args.forEach(function (arg) {
if (arg.startsWith('--devfile-path:')) {
devfilePath = arg.substring('--devfile-path:'.length);
}
if (arg.startsWith('--devfile-url:')) {
devfileUrl = arg.substring('--devfile-url:'.length);
}
if (arg.startsWith('--plugin-registry-url:')) {
pluginRegistryUrl = arg.substring('--plugin-registry-url:'.length);
}
if (arg.startsWith('--editor-entry:')) {
editorEntry = arg.substring('--editor-entry:'.length);
}
if (arg.startsWith('--editor-path:')) {
editorPath = arg.substring('--editor-path:'.length);
}
if (arg.startsWith('--output-file:')) {
outputFile = arg.substring('--output-file:'.length);
}
if (arg.startsWith('--project.')) {
var name = arg.substring('--project.'.length, arg.indexOf('='));
var location = arg.substring(arg.indexOf('=') + 1);
location = location.replace('{{_INTERNAL_URL_}}', '{{ INTERNAL_URL }}');
projects.push({ name: name, location: location });
}
});
_a.label = 1;
case 1:
_a.trys.push([1, 3, , 4]);
if (!editorPath && !editorEntry) {
throw new Error('missing --editor-path: or --editor-entry: parameter');
}
if (!devfilePath && !devfileUrl) {
throw new Error('missing --devfile-path: or --devfile-url: parameter');
}
if (!outputFile) {
throw new Error('missing --output-file: parameter');
}
return [4 /*yield*/, this.generateDevfileContext({
devfilePath: devfilePath,
devfileUrl: devfileUrl,
editorPath: editorPath,
outputFile: outputFile,
pluginRegistryUrl: pluginRegistryUrl,
editorEntry: editorEntry,
projects: projects
})];
case 2:
_a.sent();
return [2 /*return*/, true];
case 2:
case 3:
error_1 = _a.sent();

@@ -229,3 +256,3 @@ console.error('stack=' + error_1.stack);

return [2 /*return*/, false];
case 3: return [2 /*return*/];
case 4: return [2 /*return*/];
}

@@ -232,0 +259,0 @@ });

{
"name": "@eclipse-che/che-devworkspace-generator",
"version": "0.0.1-7784e80",
"version": "0.0.1-bd2d989",
"private": false,

@@ -21,9 +21,11 @@ "description": "Generates DevWorkspaces by transforming existing devfiles",

"build": "yarn run format && yarn run compile && yarn run lint && yarn run test",
"compile": "tsc --project .",
"compile": "tsc --declaration --project .",
"format": "if-env SKIP_FORMAT=true && echo 'skip format check' || prettier --check '{src,tests}/**/*.ts' package.json",
"format:fix": "prettier --write '{src,tests}/**/*.ts' package.json",
"lint": "if-env SKIP_LINT=true && echo 'skip lint check' || eslint --cache=true --no-error-on-unmatched-pattern=true '{src,tests}/(!model|**)/*.ts'",
"lint:fix": "eslint --fix --cache=true --no-error-on-unmatched-pattern=true \"{src,tests}/(!model|**)/*.{ts,tsx}\"",
"lint:fix": "eslint --fix --cache=true --no-error-on-unmatched-pattern=true \"{src,tests}/(!model|**)/*.ts\"",
"test": "if-env SKIP_TEST=true && echo 'skip test' || jest --forceExit",
"watch": "tsc -w",
"license:check": "docker run --rm -t -v ${PWD}/:/workspace/project quay.io/che-incubator/dash-licenses:next --check",
"license:generate": "docker run --rm -t -v ${PWD}/:/workspace/project quay.io/che-incubator/dash-licenses:next",
"publish:next": "yarn publish --registry=https://registry.npmjs.org/ --no-git-tag-version --new-version 0.0.1-\"$(date +%s)\""

@@ -76,3 +78,3 @@ },

"collectCoverageFrom": [
"src/**/*.{ts,tsx}"
"src/**/*.ts"
],

@@ -79,0 +81,0 @@ "coverageThreshold": {

@@ -31,13 +31,15 @@ /**********************************************************************

async generate(devfileContent: string, editorContent: string, outputFile: string): Promise<DevfileContext> {
async generate(devfileContent: string, editorContent: string, outputFile?: string): Promise<DevfileContext> {
const context = await this.generateContent(devfileContent, editorContent);
// write the result
// write templates and then DevWorkspace in a single file
const allContentArray = context.devWorkspaceTemplates.map(template => jsYaml.dump(template));
allContentArray.push(jsYaml.dump(context.devWorkspace));
if (outputFile) {
// write templates and then DevWorkspace in a single file
const allContentArray = context.devWorkspaceTemplates.map(template => jsYaml.dump(template));
allContentArray.push(jsYaml.dump(context.devWorkspace));
const generatedContent = allContentArray.join('---\n');
const generatedContent = allContentArray.join('---\n');
await fs.writeFile(outputFile, generatedContent, 'utf-8');
await fs.writeFile(outputFile, generatedContent, 'utf-8');
}

@@ -44,0 +46,0 @@ console.log(`DevWorkspace ${context.devWorkspaceTemplates[0].metadata.name} was generated.`);

@@ -23,42 +23,27 @@ /**********************************************************************

export class Main {
protected async doStart(): Promise<DevfileContext> {
let devfilePath: string | undefined;
let devfileUrl: string | undefined;
let outputFile: string | undefined;
let editorPath: string | undefined;
let pluginRegistryUrl: string | undefined;
let editorEntry: string | undefined;
const projects: { name: string; location: string }[] = [];
/**
* Default constructor.
*/
constructor() {
// no-op
}
// Generates a devfile context object based on params
public async generateDevfileContext(params: {
devfilePath?: string;
devfileUrl?: string;
devfileContent?: string;
outputFile?: string;
editorPath?: string;
pluginRegistryUrl?: string;
editorEntry?: string;
projects: { name: string; location: string }[];
}): Promise<DevfileContext> {
let { devfilePath, devfileUrl, outputFile, editorPath, pluginRegistryUrl, editorEntry, projects } = params;
const args = process.argv.slice(2);
args.forEach(arg => {
if (arg.startsWith('--devfile-path:')) {
devfilePath = arg.substring('--devfile-path:'.length);
}
if (arg.startsWith('--devfile-url:')) {
devfileUrl = arg.substring('--devfile-url:'.length);
}
if (arg.startsWith('--plugin-registry-url:')) {
pluginRegistryUrl = arg.substring('--plugin-registry-url:'.length);
}
if (arg.startsWith('--editor-entry:')) {
editorEntry = arg.substring('--editor-entry:'.length);
}
if (arg.startsWith('--editor-path:')) {
editorPath = arg.substring('--editor-path:'.length);
}
if (arg.startsWith('--output-file:')) {
outputFile = arg.substring('--output-file:'.length);
}
if (arg.startsWith('--project.')) {
const name = arg.substring('--project.'.length, arg.indexOf('='));
let location = arg.substring(arg.indexOf('=') + 1);
location = location.replace('{{_INTERNAL_URL_}}', '{{ INTERNAL_URL }}');
projects.push({ name, location });
}
});
if (!editorPath && !editorEntry) {
throw new Error('missing --editor-path: or --editor-entry: parameter');
throw new Error('missing editorPath or editorEntry');
}
if (!devfilePath && !devfileUrl && !params.devfileContent) {
throw new Error('missing devfilePath or devfileUrl or devfileContent');
}
if (editorEntry && !pluginRegistryUrl) {

@@ -68,8 +53,2 @@ pluginRegistryUrl = 'https://eclipse-che.github.io/che-plugin-registry/main/v3';

}
if (!devfilePath && !devfileUrl) {
throw new Error('missing --devfile-path: or --devfile-url: parameter');
}
if (!outputFile) {
throw new Error('missing --output-file: parameter');
}

@@ -112,4 +91,6 @@ const axiosInstance = axios.default;

devfileContent = jsYaml.dump(devfileParsed);
} else if (devfilePath) {
devfileContent = await fs.readFile(devfilePath);
} else {
devfileContent = await fs.readFile(devfilePath);
devfileContent = params.devfileContent;
}

@@ -160,4 +141,58 @@

async start(): Promise<boolean> {
let devfilePath: string | undefined;
let devfileUrl: string | undefined;
let outputFile: string | undefined;
let editorPath: string | undefined;
let pluginRegistryUrl: string | undefined;
let editorEntry: string | undefined;
const projects: { name: string; location: string }[] = [];
const args = process.argv.slice(2);
args.forEach(arg => {
if (arg.startsWith('--devfile-path:')) {
devfilePath = arg.substring('--devfile-path:'.length);
}
if (arg.startsWith('--devfile-url:')) {
devfileUrl = arg.substring('--devfile-url:'.length);
}
if (arg.startsWith('--plugin-registry-url:')) {
pluginRegistryUrl = arg.substring('--plugin-registry-url:'.length);
}
if (arg.startsWith('--editor-entry:')) {
editorEntry = arg.substring('--editor-entry:'.length);
}
if (arg.startsWith('--editor-path:')) {
editorPath = arg.substring('--editor-path:'.length);
}
if (arg.startsWith('--output-file:')) {
outputFile = arg.substring('--output-file:'.length);
}
if (arg.startsWith('--project.')) {
const name = arg.substring('--project.'.length, arg.indexOf('='));
let location = arg.substring(arg.indexOf('=') + 1);
location = location.replace('{{_INTERNAL_URL_}}', '{{ INTERNAL_URL }}');
projects.push({ name, location });
}
});
try {
await this.doStart();
if (!editorPath && !editorEntry) {
throw new Error('missing --editor-path: or --editor-entry: parameter');
}
if (!devfilePath && !devfileUrl) {
throw new Error('missing --devfile-path: or --devfile-url: parameter');
}
if (!outputFile) {
throw new Error('missing --output-file: parameter');
}
await this.generateDevfileContext({
devfilePath,
devfileUrl,
editorPath,
outputFile,
pluginRegistryUrl,
editorEntry,
projects,
});
return true;

@@ -164,0 +199,0 @@ } catch (error) {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc