plugins { id 'refinery-frontend-conventions' } frontend { yarnGlobalInstallScript = "install -g yarn@${project.ext['frontend.yarn1Version']}" yarnInstallScript = "set version ${frontend.yarnVersion.get()} --only-if-needed" if (project.hasProperty('ci')) { installScript = 'install --immutable --inline-builds' } else { installScript = 'install' } } ext.frontedPropertiesFile = "${frontend.nodeInstallDirectory.get()}/frontend.properties" def String getFrontendProperty(String propertyName) { FileInputStream inputStream = null Properties props = new Properties() try { inputStream = new FileInputStream(frontedPropertiesFile) props.load(inputStream) } catch (FileNotFoundException | IOException e) { return null } finally { if (inputStream != null) { inputStream.close() } } return props.get(propertyName) } def String putFrontedProperty(String propertyName, String propertyValue) { FileInputStream inputStream = null Properties props = new Properties() try { inputStream = new FileInputStream(frontedPropertiesFile) props.load(inputStream) } catch (FileNotFoundException e) { // Use an empty Properties object instead } finally { if (inputStream != null) { inputStream.close() } } props.put(propertyName, propertyValue) FileOutputStream outputStream = null try { outputStream = new FileOutputStream(frontedPropertiesFile) props.store(outputStream, null) } catch (IOException e) { return true; } finally { if (outputStream != null) { outputStream.close() } } } tasks.named('installNode') { onlyIf { getFrontendProperty('installedNodeVersion') != frontend.nodeVersion.get() } doLast { putFrontedProperty('installedNodeVersion', frontend.nodeVersion.get()) } } tasks.named('installYarnGlobally') { onlyIf { getFrontendProperty('installedYarn1Version') != project.ext['frontend.yarn1Version'] } doLast { putFrontedProperty('installedYarn1Version', project.ext['frontend.yarn1Version']) } outputs.dir "${frontend.nodeInstallDirectory.get()}/lib/node_modules/yarn" } tasks.named('installYarn') { outputs.file ".yarn/releases/yarn-${frontend.yarnVersion.get()}.cjs" } tasks.named('installFrontend') { inputs.files('package.json', 'yarn.lock') outputs.files('.pnp.cjs', '.pnp.loader.mjs') } tasks.register('clobberFrontend', Delete) { delete frontend.nodeInstallDirectory.get() delete '.yarn/cache' delete '.yarn/install-state.gz' delete '.yarn/sdks' delete '.yarn/unplugged' delete '.pnp.cjs' delete '.pnp.loader.mjs' }