Skip to content

Commit

Permalink
Maybe this is working now
Browse files Browse the repository at this point in the history
  • Loading branch information
scroix committed Apr 1, 2024
1 parent b7764b2 commit b93a3f0
Showing 1 changed file with 39 additions and 24 deletions.
63 changes: 39 additions & 24 deletions nodel-webui-js/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,31 @@ def gruntFile = file('Gruntfile.js')

def filesChanged = false

tasks.register('checkFilesChanged', Task) {
doLast {
def nodeModulesDir = file("${projectDir}/node_modules")
if (!nodeModulesDir.exists()) {
filesChanged = true
} else {
def srcDirModified = srcDir.exists() && srcDir.lastModified() > nodeModulesDir.lastModified()
def packageJsonModified = packageJson.exists() && packageJson.lastModified() > nodeModulesDir.lastModified()
def packageLockJsonModified = packageLockJson.exists() && packageLockJson.lastModified() > nodeModulesDir.lastModified()
def gruntFileModified = gruntFile.exists() && gruntFile.lastModified() > nodeModulesDir.lastModified()

filesChanged = srcDirModified || packageJsonModified || packageLockJsonModified || gruntFileModified
}
static def checkFilesChanged(Project project) {
def nodeModulesDir = project.file("${project.projectDir}/node_modules")
def srcDir = project.file('src')
def packageJson = project.file('package.json')
def packageLockJson = project.file('package-lock.json')
def gruntFile = project.file('Gruntfile.js')

if (!nodeModulesDir.exists()) {
// println "node_modules directory does not exist. Setting filesChanged to true."
return true
} else {
def srcDirModified = srcDir.exists() && srcDir.lastModified() > nodeModulesDir.lastModified()
def packageJsonModified = packageJson.exists() && packageJson.lastModified() > nodeModulesDir.lastModified()
def packageLockJsonModified = packageLockJson.exists() && packageLockJson.lastModified() > nodeModulesDir.lastModified()
def gruntFileModified = gruntFile.exists() && gruntFile.lastModified() > nodeModulesDir.lastModified()

def filesChanged = srcDirModified || packageJsonModified || packageLockJsonModified || gruntFileModified

// println "srcDirModified: ${srcDirModified}"
// println "packageJsonModified: ${packageJsonModified}"
// println "packageLockJsonModified: ${packageLockJsonModified}"
// println "gruntFileModified: ${gruntFileModified}"
// println "filesChanged: ${filesChanged}"

return filesChanged
}
}

Expand All @@ -86,29 +98,32 @@ tasks.named('clean', Delete) {
}

tasks.register('installGruntCli', NpmTask) {
dependsOn checkFilesChanged
def shouldInstall = checkFilesChanged(project)

if (shouldInstall) {
dependsOn clean
}

args = ['install', 'grunt-cli', '--save-dev', '--legacy-peer-deps']

inputs.property('filesChanged', filesChanged)
inputs.property('filesChanged', shouldInstall)
outputs.dir('node_modules')

onlyIf { filesChanged }

if (filesChanged) {
dependsOn clean
}
onlyIf { shouldInstall }
}

tasks.register('gruntRun', NpxTask) {
def shouldInstall = checkFilesChanged(project)


dependsOn 'installGruntCli'
command = "grunt"
args = ["build"]
inputs.property('filesChanged', shouldInstall)
inputs.dir("node_modules")
outputs.dir("build/grunt")

inputs.property('filesChanged', filesChanged)
outputs.dir("dist")

onlyIf { filesChanged }
onlyIf { shouldInstall }
}

tasks.register('checkDistDirectory', Task) {
Expand Down

0 comments on commit b93a3f0

Please sign in to comment.