This repository has been archived by the owner on May 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnpmInstall.gradle
48 lines (39 loc) · 2.22 KB
/
npmInstall.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Adds optional dev convenience: adjusts the regular 'npmInstall' gradle task with two improvements:
// - NSI allows npm-linked local development (https://www.npmjs.com/package/npm-safe-install)
// - faster gradle up-to-date check during build (only checks content of package.json and package-lock.json,
// and a marker file for whether node_module exists as a regular or NSI-linked version. Runs NSI if it's linked.
// Does not check the entire node_modules subtree).
// These are not supplied from react4xp, they are just names used for buildtime housekeeping:
def markerName = "node_modules/react4xp/npmInstalled.marker"
if (project.ext.react4xp.NPMLINKED == true) {
task nsiInstall(type: NodeTask) {
doFirst {
println "react4xp build mode is set to '${project.ext.react4xp.BUILD_ENV}':\nOVERRIDING VANILLA npmInstall IN FAVOR OF node-safe-install (nsi) for retaining 'npm link' symlinks. For easy (POSIX) symlinking to npm-react4xp, stand in this projects root directory and run getlinks.sh with a relative link to a local npm-react4xp directory."
}
script = file("node_modules/npm-safe-install/out/cli.js") // npm-safe-install comes with react4xp@^0.2.0
doLast {
def marker = new File(markerName)
new File(marker.getParent()).mkdirs()
marker.text = """
Marker file, indicating that the **nsiInstall** gradle task (yes, NSI - node-safe-install) has been run in this subproject - retaining any locally linked react4xp packages in node_module.
"""
}
}
nsiInstall.inputs.files('package.json', 'package-lock.json', 'build.gradle')
nsiInstall.outputs.file('package-lock.json')
nsiInstall.outputs.file file(markerName)
npmInstall.enabled = false
npmInstall.dependsOn nsiInstall
} else {
npmInstall.enabled = true
npmInstall.inputs.files('package.json', 'package-lock.json', 'build.gradle')
npmInstall.outputs.file('package-lock.json')
npmInstall.outputs.file file(markerName)
npmInstall.doLast {
def marker = new File(markerName)
new File(marker.getParent()).mkdirs()
marker.text = """
Marker file, indicating that the npmInstall gradle task has been run in this subproject - faster than traversing the entire node_modules tree for changes.
"""
}
}