@@ -4,8 +4,159 @@ plugins {
44
55 alias(libs.plugins.compose.compiler) apply false
66 alias(libs.plugins.jetbrainsCompose) apply false
7+
8+ id(" com.github.node-gradle.node" ) version " 7.1.0"
9+ id(" java" )
710}
811
912// Set the build directory to not /build to prevent accidental deletion through the clean action
1013// Can be deleted after the migration to Gradle is complete
11- layout.buildDirectory = file(" .build" )
14+ layout.buildDirectory = file(" .build" )
15+
16+ repositories {
17+ mavenCentral()
18+ }
19+
20+ dependencies {
21+ implementation(" com.google.code.gson:gson:2.10.1" ) // For JSON parsing
22+ }
23+
24+ configure< com.github.gradle.node.NodeExtension > {
25+ version.set(" 20.10.0" )
26+ npmVersion.set(" 10.2.3" )
27+ download.set(true )
28+ workDir.set(file(" ${project.projectDir} /.build/nodejs" ))
29+ npmWorkDir.set(file(" ${project.projectDir} /.build/npm" ))
30+ }
31+
32+ // tasks.register("testNodeSetup") {
33+ // description = "Test that Node.js plugin is working"
34+ // dependsOn("nodeSetup") // This task is provided by the plugin
35+ // doLast {
36+ // println("Node.js plugin setup completed successfully!")
37+ // }
38+ // }
39+ //
40+ // // Create a test package.json and run npm commands
41+ // tasks.register("createTestPackage") {
42+ // description = "Create a test package.json for Processing"
43+ // doLast {
44+ // val packageJson = file("package.json")
45+ // if (!packageJson.exists()) {
46+ // packageJson.writeText("""
47+ // {
48+ // "name": "processing4-test",
49+ // "version": "1.0.0",
50+ // "description": "Node.js integration test for Processing 4",
51+ // "scripts": {
52+ // "test": "echo 'Node.js integration with Processing 4 is working!'",
53+ // "build": "echo 'Building assets for Processing...'",
54+ // "clean": "echo 'Cleaning build artifacts...'"
55+ // },
56+ // "devDependencies": {}
57+ // }
58+ // """.trimIndent())
59+ // println("Created test package.json")
60+ // } else {
61+ // println("package.json already exists")
62+ // }
63+ // }
64+ // }
65+ //
66+ // // Test npm commands
67+ // tasks.register("testNpmCommands") {
68+ // description = "Test npm commands with Processing"
69+ // dependsOn("createTestPackage", "npmInstall")
70+ // doLast {
71+ // println("NPM integration test completed!")
72+ // }
73+ // }
74+
75+ tasks.register(" createJsStructure" ) {
76+ description = " Create directory structure for JavaScript files"
77+ doLast {
78+ val jsDir = file(" src/main/js" )
79+ jsDir.mkdirs()
80+ println (" Created directory: ${jsDir.absolutePath} " )
81+ }
82+ }
83+
84+ // Enhanced package.json creation with dependencies
85+ tasks.register(" createTestPackage" ) {
86+ description = " Create a test package.json for Processing"
87+ dependsOn(" createJsStructure" )
88+ doLast {
89+ val packageJson = file(" package.json" )
90+ if (! packageJson.exists()) {
91+ packageJson.writeText("""
92+ {
93+ "name": "processing4-test",
94+ "version": "1.0.0",
95+ "description": "Node.js integration test for Processing 4",
96+ "main": "src/main/js/index.js",
97+ "scripts": {
98+ "test": "node src/main/js/test.js",
99+ "build": "echo 'Building assets for Processing...'",
100+ "clean": "echo 'Cleaning build artifacts...'"
101+ },
102+ "dependencies": {
103+ "lodash": "^4.17.21"
104+ },
105+ "devDependencies": {}
106+ }
107+ """ .trimIndent())
108+ println (" Created test package.json with lodash dependency" )
109+ } else {
110+ println (" package.json already exists" )
111+ }
112+ }
113+ }
114+
115+ // Install npm dependencies
116+ tasks.register(" installNodeDeps" ) {
117+ description = " Install Node.js dependencies"
118+ dependsOn(" createTestPackage" , " npmInstall" )
119+ doLast {
120+ println (" Node.js dependencies installed successfully!" )
121+ }
122+ }
123+
124+ // Test basic Node.js functionality
125+ tasks.register(" testNodeSetup" ) {
126+ description = " Test that Node.js plugin is working"
127+ dependsOn(" nodeSetup" )
128+ doLast {
129+ println (" Node.js plugin setup completed successfully!" )
130+ }
131+ }
132+
133+ // Test npm commands
134+ tasks.register(" testNpmCommands" ) {
135+ description = " Test npm commands with Processing"
136+ dependsOn(" installNodeDeps" )
137+ doLast {
138+ println (" NPM integration test completed!" )
139+ }
140+ }
141+
142+ // Test Node.js function calls from Java
143+ tasks.register<JavaExec >(" testNodeIntegration" ) {
144+ description = " Test Node.js integration with Java/Processing code"
145+ dependsOn(" compileJava" , " installNodeDeps" )
146+
147+ classpath = sourceSets.main.get().runtimeClasspath
148+ mainClass.set(" processing.test.NodeIntegrationTest" )
149+
150+ doFirst {
151+ println (" Testing Node.js integration with Processing..." )
152+ }
153+ }
154+
155+ // Compile and test everything
156+ tasks.register(" testAll" ) {
157+ description = " Run all tests for Node.js integration"
158+ dependsOn(" testNodeSetup" , " testNpmCommands" , " testNodeIntegration" )
159+ doLast {
160+ println (" All integration tests completed successfully!" )
161+ }
162+ }
0 commit comments