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