Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
4c794fc
"tutorial repo"
denise-khuu Nov 23, 2020
26eb021
tutorial repo
denise-khuu Nov 23, 2020
c154ca3
Update Playbook
denise-khuu Nov 23, 2020
8516461
Playbook repo
denise-khuu Nov 23, 2020
a907100
Feature add Project and Playbook repo
denise-khuu Nov 23, 2020
2d992e9
createProject
denise-khuu Nov 23, 2020
664b7a7
createProject() and cd-Template
denise-khuu Nov 23, 2020
081df1e
createProject() and cd-Template
denise-khuu Nov 23, 2020
67274b2
createProject() and cd-Template
denise-khuu Nov 23, 2020
d7b3090
Playbook
denise-khuu Nov 23, 2020
90b2c3f
playbook
denise-khuu Nov 23, 2020
c2d6a08
createProject added Comments
denise-khuu Nov 23, 2020
709f4b1
createProject and currentDir added
denise-khuu Nov 23, 2020
dcd83e1
createProject and currentDir
denise-khuu Nov 23, 2020
2921d99
index.asciidoc createProject added
denise-khuu Nov 24, 2020
efe47a5
Merge branch 'main' of https://github.com/devonfw-forge/tutorial-comp…
denise-khuu Nov 24, 2020
df3ed0b
merging problems solved
denise-khuu Nov 24, 2020
eb6317d
merging problems solved
denise-khuu Nov 24, 2020
322b704
merging problems solved
denise-khuu Nov 24, 2020
eaba1a1
git modules deleted and added functions console/index.ts
denise-khuu Nov 24, 2020
6cd7590
git modules deleted and added functions console/index.ts
denise-khuu Nov 24, 2020
8c981c1
git modules deleted and added functions console/index.ts
denise-khuu Nov 24, 2020
4ae350e
currentDir changed with path.join
denise-khuu Nov 24, 2020
1e6534c
currentDir changed with path.join
denise-khuu Nov 24, 2020
e69f8a6
currentDir changed with path.join
denise-khuu Nov 24, 2020
f3c07eb
added name and language variables
denise-khuu Nov 25, 2020
ceb5f79
added name and language variables
denise-khuu Nov 25, 2020
dde0695
project name and language are added
denise-khuu Nov 25, 2020
0c7cae6
cd.md changed the instructions
denise-khuu Nov 25, 2020
3fcff73
cd.md changed the instructions
denise-khuu Nov 25, 2020
e61b2d9
added parameters to runcreateProject
denise-khuu Nov 25, 2020
9175012
added name tag to createProject
denise-khuu Nov 25, 2020
0a233a3
Merge branch 'main' of https://github.com/devonfw-forge/tutorial-comp…
denise-khuu Nov 30, 2020
92536d5
update
denise-khuu Nov 30, 2020
a5ef5a3
changeCurrentDir is splitted to a function generating a template and …
denise-khuu Dec 2, 2020
f63da61
Merge pull request #5 from denise-khuu/main
denise-khuu Dec 2, 2020
7f3a1dc
Merge pull request #6 from denise-khuu/feature/changecurrentdir
denise-khuu Dec 2, 2020
b6aba5a
deleted relPath
denise-khuu Dec 2, 2020
cab266a
changed newPath to dirPaths
denise-khuu Dec 2, 2020
8f97bdc
dirUtils replace concat with path.join
denise-khuu Dec 2, 2020
95a0b26
replace dummy path
denise-khuu Dec 2, 2020
f9ea402
Template will only be generated, if targetDir and currentDir have dif…
denise-khuu Dec 3, 2020
e94c16a
function changed to createDevon4jProject
denise-khuu Dec 3, 2020
23b9ef9
function changed to createDevon4jProject
denise-khuu Dec 3, 2020
4e07be2
WIP: feature/buildJava
denise-khuu Dec 3, 2020
b96aa95
npm dependency of jasmine changed
denise-khuu Dec 3, 2020
2d505c9
npm test in buildRun.sh
denise-khuu Dec 3, 2020
14ab8e8
npm test in buildRun.sh
denise-khuu Dec 3, 2020
c07d6a6
npm test in buildRun.sh
denise-khuu Dec 3, 2020
993a283
jasmine without @types
denise-khuu Dec 3, 2020
db775ec
jasmine without @types
denise-khuu Dec 3, 2020
d0740ae
jasmine without @types
denise-khuu Dec 3, 2020
eac509b
jasmine without @types and dirUtilsSpec changed
denise-khuu Dec 3, 2020
37a8c85
jasmine in dependencies not devd
denise-khuu Dec 3, 2020
11f22d5
Merge pull request #8 from denise-khuu/main
denise-khuu Dec 7, 2020
10a8d44
@types/jasmine is added to package.json and path param
denise-khuu Dec 7, 2020
698af05
documentation
denise-khuu Dec 7, 2020
db6742e
Exit code and slash instead of backslash
denise-khuu Dec 7, 2020
92e585c
changed back to createproject with one param and cd commands in template
denise-khuu Dec 9, 2020
ae466ec
Function.md changed back
denise-khuu Dec 9, 2020
1551bde
Merge branch 'main' into feature/createproject
denise-khuu Dec 9, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions buildRun.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ Copy-Item -Force -Recurse -Path $PSScriptRoot\engine\parser.def -Destination $PS
Copy-Item -Force -Recurse -Path $PSScriptRoot\playbooks\ -Destination $PSScriptRoot\build
Copy-Item -Force -Recurse -Path $PSScriptRoot\environments\ -Destination $PSScriptRoot\build
Copy-Item -Force -Recurse -Path $PSScriptRoot\runners\ -Destination $PSScriptRoot\build
npm test
node $PSScriptRoot\build\engine\run.js
1 change: 1 addition & 0 deletions buildRun.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ cp engine/parser.def build/engine/parser.def
cp -r playbooks build
cp -r environments build
cp -r runners build
npm test
node build/engine/run.js
2 changes: 2 additions & 0 deletions localBuildRun.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ Copy-Item -Force -Recurse -Path $PSScriptRoot\engine\parser.def -Destination $PS
Copy-Item -Force -Recurse -Path $PSScriptRoot\..\tutorials -Destination $PSScriptRoot\build\playbooks
Copy-Item -Force -Recurse -Path $PSScriptRoot\environments\ -Destination $PSScriptRoot\build
Copy-Item -Force -Recurse -Path $PSScriptRoot\runners\ -Destination $PSScriptRoot\build
npm test
if(-not $?) { throw 'tests failed' }
node $PSScriptRoot\build\engine\run.js
5 changes: 5 additions & 0 deletions localBuildRun.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,9 @@ cp engine/parser.def build/engine/parser.def
cp -r ../tutorials build/playbooks
cp -r environments build
cp -r runners build
npm test
if [ $? -eq 1 ]; then
echo 'tests failed'
exit 1
fi
node build/engine/run.js
3 changes: 3 additions & 0 deletions localBuildTest.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
tsc
npm test
if(-not $?){ throw 'tests failed' }
6 changes: 6 additions & 0 deletions localBuildTest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
tsc
npm test
if [ $? -eq 1 ]; then
echo 'tests failed'
exit 1
fi
22 changes: 22 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
"ts-pegjs": "^0.2.7",
"yargs": "^16.1.0"
},
"devDependencies": {},
"devDependencies": {
"@types/jasmine": "^3.6.2",
"jasmine": "^3.6.2"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "npx jasmine"
},
"author": "",
"license": "ISC"
Expand Down
7 changes: 0 additions & 7 deletions runners/console/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,6 @@ export class Console extends Runner {
return null;
}

runBuildJava(step: Step, command: Command): RunResult {
return null;
}

async assertInstallDevonfwIde(step: Step, command: Command, result: RunResult) {
let installedTools = command.parameters[0];

Expand Down Expand Up @@ -153,9 +149,6 @@ export class Console extends Runner {
.fileExits(path.join(workspaceDir, command.parameters[0], "core", "src", "main", "java", "com", "example", "application", command.parameters[0], "SpringBootApp.java"));
}

async assertbuildJava(step: Step, command: Command, result: RunResult) {
console.log("assertbuildJava exceptions");
}


private executeCommandSync(command: string, directory: string, result: RunResult, input?: string) {
Expand Down
51 changes: 51 additions & 0 deletions runners/katacoda/dirUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import * as path from 'path';

export class DirUtils{

getCdParam(currentDir:string, targetDir:string):string{

//returns an empty string, if both variables have the same path
if(currentDir == targetDir){
return "";
}

let dirPath = "";

let currentPaths = currentDir.split(path.sep);
let targetPaths = targetDir.split(path.sep);

let index;
let isEqual = true;

//saves the remaining path, if currentdir is the prefix of targetDir
if(targetDir.substring(0,currentDir.length) == currentDir){
return path.join(targetDir.replace(currentDir + path.sep, '')).replace("\\", "/");
}


else{
//returns the absolut directory, if the first parent folder is different
if(currentPaths[1] != targetPaths[1]){
return targetDir.replace("\\", "/");
}

//iterates throught currentPath array to compare parent directories
currentPaths.forEach((currentPath, i) => {
if(currentPath == targetPaths[i] && isEqual == true){
index = i;
}else{
isEqual = false;
dirPath = path.join(dirPath,'..');
}
})

//slice targetPaths to get the relative path
targetPaths = targetPaths.slice(index + 1, targetPaths.length);

return path.join(dirPath, targetPaths.join(path.sep)).replace("\\", "/");

}

}

}
48 changes: 45 additions & 3 deletions runners/katacoda/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Command } from "../../engine/command";
import { KatacodaTools } from "./katacodaTools";
import { KatacodaStep, KatacodaSetupScript } from "./katacodaInterfaces";
import { KatacodaAssetManager } from "./katacodaAssetManager";
import { DirUtils } from "./dirUtils";
import * as path from 'path';
import * as ejs from 'ejs';
import * as fs from 'fs';
Expand All @@ -20,7 +21,8 @@ export class Katacoda extends Runner {
private setupScripts: KatacodaSetupScript[] = [];
private assetManager: KatacodaAssetManager;
private setupDir: string;

private currentDir: string = "/root";

init(playbook: Playbook): void {
// create directory for katacoda tutorials if not exist
this.createFolder(path.join(this.getOutputDirectory(), "katacoda/"), false)
Expand Down Expand Up @@ -66,6 +68,8 @@ export class Katacoda extends Runner {
}

runInstallDevonfwIde(step: Step, command: Command): RunResult {
let cdCommand = this.changeCurrentDir("/root");

let tools = command.parameters[0].join(" ").replace(/vscode/,"").replace(/eclipse/, "").trim();

// create script to download devonfw ide settings
Expand All @@ -81,7 +85,11 @@ export class Katacoda extends Runner {
"title": "Install devonfw IDE",
"text": "step" + this.stepsCount + ".md",
});
this.renderTemplate("installDevonfwIde.md", this.outputPathTutorial + "step" + (this.stepsCount++) + ".md", { text: step.text, textAfter: step.textAfter });
this.renderTemplate("installDevonfwIde.md", this.outputPathTutorial + "step" + (this.stepsCount++) + ".md", { text: step.text, textAfter: step.textAfter, cdCommand: cdCommand});

//update current directory
this.currentDir = path.join(this.currentDir, "devonfw");

return null;
}

Expand All @@ -90,7 +98,7 @@ export class Katacoda extends Runner {
"title": "Install CobiGen",
"text": "step" + this.stepsCount + ".md"
});
this.renderTemplate("installCobiGen.md", this.outputPathTutorial + "step" + (this.stepsCount++) + ".md", { text: step.text, textAfter: step.textAfter });
this.renderTemplate("installCobiGen.md", this.outputPathTutorial + "step" + (this.stepsCount++) + ".md", { text: step.text, textAfter: step.textAfter});
return null;
}

Expand All @@ -110,6 +118,24 @@ export class Katacoda extends Runner {
});
this.renderTemplate("cobiGenJava.md", this.outputPathTutorial + "step" + (this.stepsCount++) + ".md", { text: step.text, textAfter: step.textAfter, javaFile: params[0], cobiGenTemplates: cobiGenTemplates });
return null;

}

runCreateDevon4jProject(step: Step, command:Command): RunResult {

// generate template to change directory, if the current directory is not equal to the required start directory
let cdCommand = this.changeCurrentDir(path.join("/root", "devonfw"));

this.steps.push({
"title": "Create a new project",
"text": "step" + this.stepsCount + ".md"
});

//update current directory
this.currentDir = path.join(this.currentDir, "workspace", "main");

this.renderTemplate("createDevon4jProject.md", this.outputPathTutorial + "step" + (this.stepsCount++) + ".md", { text: step.text, textAfter: step.textAfter, cdCommand: cdCommand, name : command.parameters[0]});
return null;
}

runCreateDevon4jProject(step: Step, command: Command): RunResult{
Expand Down Expand Up @@ -153,4 +179,20 @@ export class Katacoda extends Runner {

this.assetManager.registerFile(setupFile, "setup/setup.txt", "/root/setup", false);
}

private changeCurrentDir(targetDir:string):string{
if(this.currentDir == targetDir){
return "";
}
let dirUtils = new DirUtils();
let dir = dirUtils.getCdParam(this.currentDir, targetDir);

this.currentDir = targetDir;

//create template to change directory
let template = fs.readFileSync(path.join(this.getRunnerDirectory(),"templates", 'cd.md'), 'utf8');
return ejs.render(template, {dir: dir});
}


}
4 changes: 4 additions & 0 deletions runners/katacoda/templates/cd.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

Please change the folder to <%= dir; %>

`cd <%= dir; %>`{{execute}}
13 changes: 13 additions & 0 deletions runners/katacoda/templates/createDevon4jProject.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<%= text; %>

## Setting up your java project

<%= cdCommand; %>

Navigate to the 'workspaces/main/' folder in your devonfw installation directory.
`cd workspaces/main`{{execute}}

Now you can use devonfw to setup a java project for you by executing the following devon command.
`devon java create com.example.application.<%= name; %>`{{execute}}

<%= textAfter; %>
2 changes: 2 additions & 0 deletions runners/katacoda/templates/installDevonfwIde.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## devonfw setup

<%= cdCommand; %>

Create the directory where the devonfw ide will be installed.

`mkdir devonfw`{{execute}}
Expand Down
25 changes: 25 additions & 0 deletions spec/runners/katacoda/dirUtilsSpec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import 'jasmine';
import * as path from 'path';
import { DirUtils } from '../../../runners/katacoda/dirUtils';

describe("DirUtils", () => {
let target = new DirUtils();
describe("changeCurrentDir", () => {
it("is already in the right folder", () => {
expect(target.getCdParam(path.join('/root'), path.join('/root'))).toBe('');
});
it("changes directly to the child folder, because currentDir is the prefix of dir", () => {
expect(target.getCdParam(path.join('/root/devonfw'), path.join('/root/devonfw/setup'))).toBe(path.join('setup').replace("\\", "/"));
});
it("returns an absolute path, because both dirs don't have matching parent folders", () => {
expect(target.getCdParam(path.join('/setup'), path.join('/root/devonfw/setup'))).toBe(path.join('/root/devonfw/setup').replace("\\", "/"));
});
it("changes to parent folder before changing to child folder", () => {
expect(target.getCdParam(path.join('/root/devonfw'), path.join('/root/setup/folder0/folder1'))).toBe(path.join('../setup/folder0/folder1').replace("\\", "/"));
});
it("changes to parent folder before changing to child folder and one child folder has the same position and name", () => {
expect(target.getCdParam(path.join('/root/devonfw/folder/setup'), path.join('/root/devonfw/setup/setup'))).toBe(path.join('../../setup/setup').replace("\\", "/"));
});

});
});
11 changes: 11 additions & 0 deletions spec/support/jasmine.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"spec_dir": "build/spec",
"spec_files": [
"**/*[sS]pec.js"
],
"helpers": [
"helpers/**/*.js"
],
"stopSpecOnExpectationFailure": false,
"random": true
}