Skip to content

Commit

Permalink
Permission denied - fix
Browse files Browse the repository at this point in the history
  • Loading branch information
williamniemiec committed Mar 27, 2022
1 parent 5e66685 commit f99d29c
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 4 deletions.
Binary file added dist/1.x/babel-transpiler-1.0.2.jar
Binary file not shown.
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.github.wniemiec-io-java</groupId>
<artifactId>babel-transpiler</artifactId>
<version>1.0.1</version>
<version>1.0.2</version>
<name>Babel transpiler</name>
<description>Babel transcription for JavaScript files.</description>
<url>https://github.com/wniemiec-io-java/babel-transpiler</url>
Expand Down Expand Up @@ -68,6 +68,12 @@
<artifactId>jar-file-manager</artifactId>
<version>LATEST</version>
</dependency>

<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
</dependency>
</dependencies>

<build>
Expand Down
43 changes: 41 additions & 2 deletions src/main/java/wniemiec/io/java/BabelTranspiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.nio.file.Path;
import java.util.List;
import java.util.function.Consumer;
import org.apache.commons.io.FileUtils;


/**
Expand Down Expand Up @@ -73,7 +74,7 @@ public List<String> fromCode(List<String> code) throws IOException {
}

setUpTerminal();
setUpBabelLocation();
setUpBabel();
setUpTempInputFile(code);
setUpTempOutputFile();
runBabel(tempFileInput);
Expand Down Expand Up @@ -117,8 +118,46 @@ private Path createTempOutFile() throws IOException {
return createTempJsFile("outputJsCode");
}

private void setUpBabel() throws IOException {
setUpBabelLocation();
compileBabel();
}

private void setUpBabelLocation() throws IOException {
babelLocation = babelScript.getLocation();
babelLocation = buildBabelTemporaryDirectory();

copyBabelToTempDirectory();
}

private void copyBabelToTempDirectory() throws IOException {
FileUtils.copyDirectory(babelScript.getLocation().toFile(), babelLocation.toFile());
}

private void compileBabel() throws IOException {
cleanBabel();

terminal.exec(
"npm",
"install",
"--prefix",
babelLocation.toAbsolutePath().toString()
);
}

private void cleanBabel() throws IOException {
FileUtils.deleteDirectory(getBabelBinLocation().toFile());
}

private Path getBabelBinLocation() {
return babelLocation.resolve("node_modules").resolve(".bin");
}

private Path buildBabelTemporaryDirectory() {
return getTemporaryDirectory().resolve(babelScript.getFolderName());
}

private Path getTemporaryDirectory() {
return Path.of(System.getProperty("java.io.tmpdir"));
}

private void runBabel(Path jsFile) throws IOException {
Expand Down
15 changes: 14 additions & 1 deletion src/main/java/wniemiec/io/java/BabelTranspilerScript.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,24 @@ class BabelTranspilerScript {
// Attributes
//-------------------------------------------------------------------------
private Path location;
private static final String FOLDER_NAME;


//-------------------------------------------------------------------------
// Initialization block
//-------------------------------------------------------------------------
static {
FOLDER_NAME = "babel";
}


//-------------------------------------------------------------------------
// Getters
//-------------------------------------------------------------------------
public String getFolderName() {
return FOLDER_NAME;
}

public Path getLocation() throws IOException {
if (location == null) {
location = initializeLocation();
Expand All @@ -33,7 +46,7 @@ private Path initializeLocation() throws IOException {

return baseDir
.resolve("javascript")
.resolve("babel");
.resolve(FOLDER_NAME);
}

private static Path buildBaseDir() throws IOException {
Expand Down
14 changes: 14 additions & 0 deletions src/main/javascript/babel/ex.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Pen {
constructor(name, color, price){
this.name = name;
this.color = color;
this.price = price;
}

showPrice(){
console.log(`Price of ${this.name} is ${this.price}`);
}
}

const pen1 = new Pen("Marker", "Blue", "$3");
pen1.showPrice();

0 comments on commit f99d29c

Please sign in to comment.