Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#31: implement tool commandlet for node package manager #205

Closed
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
9c42390
commandletNpmSetup
ndemirca Feb 5, 2024
1bddaca
implemented npm but not working yet
ndemirca Feb 6, 2024
213b24e
added npm into ide properties
ndemirca Feb 6, 2024
ab3db40
removed typo
ndemirca Feb 6, 2024
ad60f5d
finished hardcoded implementation
ndemirca Feb 7, 2024
d0da86a
added methods
ndemirca Feb 7, 2024
cd3445f
expanded npm class implementation
ndemirca Feb 8, 2024
8594dec
removed unnecessary code
ndemirca Feb 13, 2024
577cbd8
Merge branch 'main' of https://github.com/devonfw/IDEasy into feature…
ndemirca Feb 13, 2024
20b6ce1
finished npm Commandlet
ndemirca Feb 14, 2024
68e620d
added asciidoc documentation to npm
ndemirca Feb 15, 2024
350b842
Merge branch 'main' into feature/31-Implement-ToolCommandlet-for-Node…
hohwille Feb 19, 2024
e4929c7
Add first implementation
MustaphaOuchen Feb 22, 2024
9e2b836
Add javadoc
MustaphaOuchen Feb 23, 2024
ce0437f
Add javadoc
MustaphaOuchen Feb 23, 2024
58ddaab
Merge branch 'feature/208-MockOutToolRepoRefactorTestInfra' of https:…
MustaphaOuchen Feb 23, 2024
b698aa8
Using target path instead of ressource path to make sure one-to-one c…
MustaphaOuchen Feb 23, 2024
c2497df
Add JavaDoc and mac mock program
MustaphaOuchen Feb 23, 2024
a4ccac0
Add support for multiple dependencies while testing
MustaphaOuchen Feb 23, 2024
953f728
Minor changes
MustaphaOuchen Feb 23, 2024
b568555
Modify mock programs for testing
MustaphaOuchen Feb 26, 2024
a1f7759
Refactored example JmcTest
MustaphaOuchen Feb 26, 2024
d8ee801
Add possibility to set execution path by using the context
MustaphaOuchen Feb 26, 2024
8315810
Merge branch 'main' into feature/208-MockOutToolRepoRefactorTestInfra
MustaphaOuchen Feb 26, 2024
5959f79
Merge branch 'main' into feature/31-Implement-ToolCommandlet-for-Node…
ndemirca Feb 27, 2024
9dae683
Merge remote-tracking branch 'origin/main' into feature/208-MockOutTo…
MustaphaOuchen Feb 27, 2024
6a89529
Reenable test after related issue 228 has been merged
MustaphaOuchen Feb 27, 2024
8735efd
Replace ternary with regular if
MustaphaOuchen Feb 27, 2024
40235df
Add missing javadoc
MustaphaOuchen Feb 27, 2024
6b81cdf
Add missing javadoc
MustaphaOuchen Feb 27, 2024
e9cec8a
remove unnecessary semicolon
MustaphaOuchen Feb 27, 2024
2912ea3
Fix spelling typo
MustaphaOuchen Feb 27, 2024
73e4d13
Minor test changes
MustaphaOuchen Feb 27, 2024
c0399aa
Refactoring FileExtractor class for more modularity
MustaphaOuchen Feb 27, 2024
a59bb6a
Merge branch 'feature/208-MockOutToolRepoRefactorTestInfra' into feat…
ndemirca Feb 27, 2024
f646b4d
first unittest npm
ndemirca Feb 29, 2024
800ae29
added unittests for npm
ndemirca Mar 1, 2024
8546e4e
changed script to a bash script
ndemirca Mar 1, 2024
db02956
reverted imports
ndemirca Mar 1, 2024
440eea7
updated test data
ndemirca Mar 1, 2024
a46bb26
Merge branch 'main' into feature/31-Implement-ToolCommandlet-for-Node…
ndemirca Mar 5, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.devonfw.tools.ide.tool.kotlinc.KotlincNative;
import com.devonfw.tools.ide.tool.mvn.Mvn;
import com.devonfw.tools.ide.tool.node.Node;
import com.devonfw.tools.ide.tool.npm.Npm;
import com.devonfw.tools.ide.tool.oc.Oc;
import com.devonfw.tools.ide.tool.quarkus.Quarkus;
import com.devonfw.tools.ide.tool.terraform.Terraform;
Expand Down Expand Up @@ -69,6 +70,7 @@ public CommandletManagerImpl(IdeContext context) {
add(new Helm(context));
add(new Java(context));
add(new Node(context));
add(new Npm(context));
add(new Mvn(context));
add(new GcViewer(context));
add(new Gradle(context));
Expand Down
15 changes: 3 additions & 12 deletions cli/src/main/java/com/devonfw/tools/ide/io/FileAccessImpl.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
package com.devonfw.tools.ide.io;

import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.*;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpClient.Redirect;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.file.FileSystemException;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.PosixFilePermission;
import java.nio.file.attribute.PosixFilePermissions;
Expand Down Expand Up @@ -543,7 +534,7 @@ private void unpack(Path file, Path targetDir, Function<InputStream, ArchiveInpu
mkdirs(entryPath.getParent());
Files.copy(ais, entryPath);
}
if (isTar) {
if (isTar && !this.context.getSystemInfo().isWindows()) {
Set<PosixFilePermission> permissions = PosixFilePermissions.fromString(permissionStr);
Files.setPosixFilePermissions(entryPath, permissions);
}
Expand Down
58 changes: 58 additions & 0 deletions cli/src/main/java/com/devonfw/tools/ide/tool/npm/Npm.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.devonfw.tools.ide.tool.npm;

import java.nio.file.Path;
import java.util.Set;

import com.devonfw.tools.ide.common.Tag;
import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.io.FileAccess;
import com.devonfw.tools.ide.tool.LocalToolCommandlet;
import com.devonfw.tools.ide.tool.ToolCommandlet;
import com.devonfw.tools.ide.tool.node.Node;

/**
* {@link ToolCommandlet} for <a href="https://nodejs.org/">node</a>.
*/

public class Npm extends LocalToolCommandlet {

/**
* The constructor.
*
* @param context the {@link IdeContext}.
*/
public Npm(IdeContext context) {

super(context, "npm", Set.of(Tag.JAVA_SCRIPT, Tag.RUNTIME));
}

@Override
public boolean install(boolean silent) {

getCommandlet(Node.class).install();
return super.doInstall(silent);
}

@Override
public void postInstall() {

super.postInstall();

FileAccess fileAccess = context.getFileAccess();
Path nodeHomePath = this.context.getSoftwarePath().resolve("node/");
Path npmBinBath = nodeHomePath.resolve("node_modules/npm/bin/");
String npm = "npm";
String npx = "npx";
String cmd = ".cmd";

fileAccess.delete(nodeHomePath.resolve(npm));
fileAccess.delete(nodeHomePath.resolve(npm + cmd));
fileAccess.delete(nodeHomePath.resolve(npx));
fileAccess.delete(nodeHomePath.resolve(npx + cmd));

fileAccess.copy(npmBinBath.resolve(npm), nodeHomePath.resolve(npm));
fileAccess.copy(npmBinBath.resolve(npm + cmd), nodeHomePath.resolve(npm + cmd));
fileAccess.copy(npmBinBath.resolve(npx), nodeHomePath.resolve(npx));
fileAccess.copy(npmBinBath.resolve(npx + cmd), nodeHomePath.resolve(npx + cmd));
}
}
1 change: 1 addition & 0 deletions cli/src/main/resources/nls/Ide.properties
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ cmd-list-editions=List the available editions of the selected tool.
cmd-list-versions=List the available versions of the selected tool.
cmd-mvn=Tool commandlet for Maven (Build-Tool)
cmd-node=Tool commandlet for Node.js (JavaScript runtime)
cmd-npm=Tool commandlet for Npm
cmd-oc=Tool commandlet for Openshift CLI (Kubernetes Management Tool)
cmd-quarkus=Tool commandlet for Quarkus (Framework for cloud-native apps)
cmd-set-edition=Set the edition of the selected tool.
Expand Down
1 change: 1 addition & 0 deletions cli/src/main/resources/nls/Ide_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ cmd-list-editions=Listet die verfügbaren Editionen des selektierten Werkzeugs a
cmd-list-versions=Listet die verfügbaren Versionen des selektierten Werkzeugs auf.
cmd-mvn=Werkzeug Kommando für Maven (Build-Werkzeug)
cmd-node=Werkzeug Kommando für Node.js (JavaScript Laufzeitumgebung)
cmd-npm=Werkzeug Kommando für Npm
cmd-oc=Werkzeug Kommando für Openshift CLI (Kubernetes Management Tool)
cmd-quarkus=Werkzeug Kommando für Quarkus (Framework für Cloud-native Anwendungen)
cmd-set-edition=Setzt die Edition des selektierten Werkzeugs.
Expand Down
7 changes: 7 additions & 0 deletions cli/src/test/java/com/devonfw/tools/ide/tool/npm/NpmTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.devonfw.tools.ide.tool.npm;

import com.devonfw.tools.ide.context.AbstractIdeContextTest;

public class NpmTest extends AbstractIdeContextTest {

}
1 change: 1 addition & 0 deletions documentation/IDEasy-usage.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ include::cli.asciidoc[leveloffset=2]

include::docker-desktop-alternative.asciidoc[leveloffset=3]
include::jmc.asciidoc[leveloffset=3]
include::npm.asciidoc[leveloffset=3]

<<<<

Expand Down
21 changes: 21 additions & 0 deletions documentation/npm.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
:toc:
toc::[]

= npm

The `npm` commandlet allows to install, configure, and launch https://www.npmjs.com/[npm]. Calling `devon npm «args»` is more or less the same as calling `npm «args»` but with the benefit that the version of npm preferred by your project is used (and will be installed if not yet available).

The arguments (`devon npm «args»`) are explained by the following table:

.Usage of `devon npm`
[options="header"]
|=======================
|*Argument(s)* |*Meaning*
| |run default build, link:configuration.asciidoc[configurable] via `NPM_BUILD_OPTS`
|`setup` |setup NPM (install and verify), link:configuration.asciidoc[configurable] via `NPM_VERSION`
|`get-version` |print the version of your current project
|`set-version «nv» [«cv»]` |set the version of your current project to `«nv»` (assuming your current version is `«cv»`)
|`check-top-level-project` |check if you are running on a top-level project or fail if in a module or no NPM project at all
|`release` |Start a clean deploy release build, link:configuration.asciidoc[configurable] via `NPM_RELEASE_OPTS`
|`«args»` |run NPM with the given arguments (`«args»`)
|=======================
Loading