aboutsummaryrefslogtreecommitdiffstats
path: root/buildSrc/src/main/groovy/refinery-frontend-worktree.gradle
diff options
context:
space:
mode:
Diffstat (limited to 'buildSrc/src/main/groovy/refinery-frontend-worktree.gradle')
-rw-r--r--buildSrc/src/main/groovy/refinery-frontend-worktree.gradle96
1 files changed, 96 insertions, 0 deletions
diff --git a/buildSrc/src/main/groovy/refinery-frontend-worktree.gradle b/buildSrc/src/main/groovy/refinery-frontend-worktree.gradle
new file mode 100644
index 00000000..e1324746
--- /dev/null
+++ b/buildSrc/src/main/groovy/refinery-frontend-worktree.gradle
@@ -0,0 +1,96 @@
1plugins {
2 id 'refinery-frontend-conventions'
3}
4
5frontend {
6 yarnGlobalInstallScript = "install -g yarn@${project.ext['frontend.yarn1Version']}"
7 yarnInstallScript = "set version ${frontend.yarnVersion.get()} --only-if-needed"
8 if (project.hasProperty('ci')) {
9 installScript = 'install --immutable --inline-builds'
10 } else {
11 installScript = 'install'
12 }
13}
14
15ext.frontedPropertiesFile = "${frontend.nodeInstallDirectory.get()}/frontend.properties"
16
17def String getFrontendProperty(String propertyName) {
18 FileInputStream inputStream = null
19 Properties props = new Properties()
20 try {
21 inputStream = new FileInputStream(frontedPropertiesFile)
22 props.load(inputStream)
23 } catch (FileNotFoundException | IOException e) {
24 return null
25 } finally {
26 if (inputStream != null) {
27 inputStream.close()
28 }
29 }
30 return props.get(propertyName)
31}
32
33def String putFrontedProperty(String propertyName, String propertyValue) {
34 FileInputStream inputStream = null
35 Properties props = new Properties()
36 try {
37 inputStream = new FileInputStream(frontedPropertiesFile)
38 props.load(inputStream)
39 } catch (FileNotFoundException e) {
40 // Use an empty Properties object instead
41 } finally {
42 if (inputStream != null) {
43 inputStream.close()
44 }
45 }
46 props.put(propertyName, propertyValue)
47 FileOutputStream outputStream = null
48 try {
49 outputStream = new FileOutputStream(frontedPropertiesFile)
50 props.store(outputStream, null)
51 } catch (IOException e) {
52 return true;
53 } finally {
54 if (outputStream != null) {
55 outputStream.close()
56 }
57 }
58}
59
60tasks.named('installNode') {
61 onlyIf {
62 getFrontendProperty('installedNodeVersion') != frontend.nodeVersion.get()
63 }
64 doLast {
65 putFrontedProperty('installedNodeVersion', frontend.nodeVersion.get())
66 }
67}
68
69tasks.named('installYarnGlobally') {
70 onlyIf {
71 getFrontendProperty('installedYarn1Version') != project.ext['frontend.yarn1Version']
72 }
73 doLast {
74 putFrontedProperty('installedYarn1Version', project.ext['frontend.yarn1Version'])
75 }
76 outputs.dir "${frontend.nodeInstallDirectory.get()}/lib/node_modules/yarn"
77}
78
79tasks.named('installYarn') {
80 outputs.file ".yarn/releases/yarn-${frontend.yarnVersion.get()}.cjs"
81}
82
83tasks.named('installFrontend') {
84 inputs.files('package.json', 'yarn.lock')
85 outputs.files('.pnp.cjs', '.pnp.loader.mjs')
86}
87
88tasks.register('clobberFrontend', Delete) {
89 delete frontend.nodeInstallDirectory.get()
90 delete '.yarn/cache'
91 delete '.yarn/install-state.gz'
92 delete '.yarn/sdks'
93 delete '.yarn/unplugged'
94 delete '.pnp.cjs'
95 delete '.pnp.loader.mjs'
96}