From 5351ac8c314d9793b837aed32273ec9b8edeb871 Mon Sep 17 00:00:00 2001 From: julienmege Date: Mon, 19 Feb 2018 18:46:36 +0100 Subject: [PATCH 1/3] feat/Create gradle page plugin --- build.gradle | 50 ------------------- buildSrc/build.gradle | 9 ++++ buildSrc/src/main/groovy/NpmPagePlugin.groovy | 16 ++++++ buildSrc/src/main/groovy/PagePlugin.groovy | 46 +++++++++++++++++ .../src/main/groovy/ReactPagePlugin.groovy | 17 +++++++ page-hello-world-react/build.gradle | 1 + page-hello-world-react/package-lock.json | 6 +++ page-hello-world/build.gradle | 1 + settings.gradle | 1 + 9 files changed, 97 insertions(+), 50 deletions(-) delete mode 100644 build.gradle create mode 100644 buildSrc/build.gradle create mode 100644 buildSrc/src/main/groovy/NpmPagePlugin.groovy create mode 100644 buildSrc/src/main/groovy/PagePlugin.groovy create mode 100644 buildSrc/src/main/groovy/ReactPagePlugin.groovy create mode 100644 page-hello-world-react/build.gradle create mode 100644 page-hello-world/build.gradle diff --git a/build.gradle b/build.gradle deleted file mode 100644 index a596754b3..000000000 --- a/build.gradle +++ /dev/null @@ -1,50 +0,0 @@ - -plugins { - id "com.moowork.node" version "1.2.0" -} - -def currentDir = project.projectDir - -subprojects { - apply plugin: 'com.moowork.node' - apply plugin: 'distribution' - - node { - version = '8.9.4' - npmVersion = '5.6.0' - download = true - - workDir = file("${currentDir}/.gradle/nodejs") - npmWorkDir = file("${currentDir}/.gradle/npm") - } - - tasks.npm_install.configure { - inputs.files('package.json', 'package-lock.json') - outputs.dirs('node_modules') - } - - def buildNpm = task buildNpm(type: NpmTask, dependsOn: npm_install) { - args = ['run', 'build'] - inputs.files('package.json', 'package-lock.json') - inputs.dir('src') - } - - tasks.distZip.dependsOn buildNpm - - def cleanNpm = task cleanNpm { - doFirst { - delete 'dist' - } - } - - tasks.clean.dependsOn cleanNpm - - distributions{ - main { - contents { - from('resources') { into '/' } - from('dist') { into '/resources' } - } - } - } -} diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle new file mode 100644 index 000000000..58f2826be --- /dev/null +++ b/buildSrc/build.gradle @@ -0,0 +1,9 @@ +repositories { + mavenLocal() + maven { url 'http://repositories.rd.lan/maven/releases/' } + maven { url 'https://plugins.gradle.org/m2/' } +} + +dependencies { + compile 'com.moowork.gradle:gradle-node-plugin:1.2.0' +} \ No newline at end of file diff --git a/buildSrc/src/main/groovy/NpmPagePlugin.groovy b/buildSrc/src/main/groovy/NpmPagePlugin.groovy new file mode 100644 index 000000000..e6ac61b3d --- /dev/null +++ b/buildSrc/src/main/groovy/NpmPagePlugin.groovy @@ -0,0 +1,16 @@ +import org.gradle.api.Plugin +import org.gradle.api.Project + +class NpmPagePlugin extends PagePlugin { + + def implementDistribution(Project project){ + project.distributions{ + main { + contents { + from('resources') { into '/' } + from('dist') { into '/resources' } + } + } + } + } +} diff --git a/buildSrc/src/main/groovy/PagePlugin.groovy b/buildSrc/src/main/groovy/PagePlugin.groovy new file mode 100644 index 000000000..6c3ae572a --- /dev/null +++ b/buildSrc/src/main/groovy/PagePlugin.groovy @@ -0,0 +1,46 @@ +import org.gradle.api.Plugin +import org.gradle.api.Project + +abstract class PagePlugin implements Plugin { + + @Override + void apply(Project project) { + project.plugins.apply('com.moowork.node') + project.plugins.apply('distribution') + def currentDir = project.rootProject.projectDir + + project.node { + version = '8.9.4' + npmVersion = '5.6.0' + download = true + + workDir = project.file("${currentDir}/.gradle/nodejs") + npmWorkDir = project.file("${currentDir}/.gradle/npm") + } + + project.tasks.npm_install.configure { + inputs.files('package.json', 'package-lock.json') + outputs.dirs('node_modules') + } + + def buildNpm = project.task( [type: com.moowork.gradle.node.npm.NpmTask, dependsOn: project.tasks.npm_install] ,'buildNpm') { + args = ['run', 'build'] + inputs.files('package.json', 'package-lock.json') + inputs.dir('src') + } + + project.tasks.distZip.dependsOn buildNpm + + def cleanNpm = project.task([:], 'cleanNpm') { + doFirst { + project.delete 'dist' + } + } + + project.tasks.clean.dependsOn cleanNpm + + implementDistribution(project); + } + + abstract implementDistribution(Project project); +} diff --git a/buildSrc/src/main/groovy/ReactPagePlugin.groovy b/buildSrc/src/main/groovy/ReactPagePlugin.groovy new file mode 100644 index 000000000..967e21ffa --- /dev/null +++ b/buildSrc/src/main/groovy/ReactPagePlugin.groovy @@ -0,0 +1,17 @@ +import org.gradle.api.Plugin +import org.gradle.api.Project + +class ReactPagePlugin extends PagePlugin { + + def implementDistribution(Project project){ + project.distributions{ + main { + contents { + from('resources') { into '/' } + from('build') { into '/resources' } + } + } + } + } + +} diff --git a/page-hello-world-react/build.gradle b/page-hello-world-react/build.gradle new file mode 100644 index 000000000..77ac499f9 --- /dev/null +++ b/page-hello-world-react/build.gradle @@ -0,0 +1 @@ +apply plugin : ReactPagePlugin \ No newline at end of file diff --git a/page-hello-world-react/package-lock.json b/page-hello-world-react/package-lock.json index b1d04f410..eeafe5bb0 100644 --- a/page-hello-world-react/package-lock.json +++ b/page-hello-world-react/package-lock.json @@ -6161,6 +6161,12 @@ "xml-char-classes": "1.0.0" } }, + "ncp": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ncp/-/ncp-2.0.0.tgz", + "integrity": "sha1-GVoh1sRuNh0vsSgbo4uR6d9727M=", + "dev": true + }, "negotiator": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.1.tgz", diff --git a/page-hello-world/build.gradle b/page-hello-world/build.gradle new file mode 100644 index 000000000..fab460db1 --- /dev/null +++ b/page-hello-world/build.gradle @@ -0,0 +1 @@ +apply plugin : NpmPagePlugin \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 7dfa5d195..07164d8c8 100644 --- a/settings.gradle +++ b/settings.gradle @@ -7,6 +7,7 @@ pluginManagement { } include 'page-hello-world' +include 'page-hello-world-react' rootProject.name = 'bonita-web-pages' From ae36fb2edb3947b0656e707613d3fbb3a72283a8 Mon Sep 17 00:00:00 2001 From: julienmege Date: Tue, 20 Feb 2018 14:27:17 +0100 Subject: [PATCH 2/3] fix page build and and fix deploy into an LA --- buildSrc/src/main/groovy/ReactPagePlugin.groovy | 5 ++++- page-hello-world-react/package-lock.json | 6 ------ page-hello-world-react/package.json | 1 + page-hello-world-react/public/index.html | 1 + page-hello-world-react/resources/page.properties | 5 +++++ page-hello-world/resources/page.properties | 2 +- page-hello-world/src/index.html | 11 ++++++----- 7 files changed, 18 insertions(+), 13 deletions(-) create mode 100644 page-hello-world-react/resources/page.properties diff --git a/buildSrc/src/main/groovy/ReactPagePlugin.groovy b/buildSrc/src/main/groovy/ReactPagePlugin.groovy index 967e21ffa..84a050427 100644 --- a/buildSrc/src/main/groovy/ReactPagePlugin.groovy +++ b/buildSrc/src/main/groovy/ReactPagePlugin.groovy @@ -8,7 +8,10 @@ class ReactPagePlugin extends PagePlugin { main { contents { from('resources') { into '/' } - from('build') { into '/resources' } + from('build') { + exclude 'distributions' + into '/resources' + } } } } diff --git a/page-hello-world-react/package-lock.json b/page-hello-world-react/package-lock.json index eeafe5bb0..b1d04f410 100644 --- a/page-hello-world-react/package-lock.json +++ b/page-hello-world-react/package-lock.json @@ -6161,12 +6161,6 @@ "xml-char-classes": "1.0.0" } }, - "ncp": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ncp/-/ncp-2.0.0.tgz", - "integrity": "sha1-GVoh1sRuNh0vsSgbo4uR6d9727M=", - "dev": true - }, "negotiator": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.1.tgz", diff --git a/page-hello-world-react/package.json b/page-hello-world-react/package.json index a3a693209..621cfa062 100644 --- a/page-hello-world-react/package.json +++ b/page-hello-world-react/package.json @@ -2,6 +2,7 @@ "name": "page-hello-world-react", "version": "0.1.0", "private": true, + "homepage": ".", "dependencies": { "react": "^16.2.0", "react-dom": "^16.2.0", diff --git a/page-hello-world-react/public/index.html b/page-hello-world-react/public/index.html index 736e61ce6..d0114a9e0 100644 --- a/page-hello-world-react/public/index.html +++ b/page-hello-world-react/public/index.html @@ -3,6 +3,7 @@ + Hello World with React diff --git a/page-hello-world-react/resources/page.properties b/page-hello-world-react/resources/page.properties new file mode 100644 index 000000000..86affe8e2 --- /dev/null +++ b/page-hello-world-react/resources/page.properties @@ -0,0 +1,5 @@ +name=custompage_helloWorldReact +displayName=hello world react +description=simple hello world page using react +resources=[] +contentType=page diff --git a/page-hello-world/resources/page.properties b/page-hello-world/resources/page.properties index 45b35f358..ae65f754a 100644 --- a/page-hello-world/resources/page.properties +++ b/page-hello-world/resources/page.properties @@ -1,4 +1,4 @@ -name=custompage_hello_world +name=custompage_helloWorld displayName=hello world description=simple hello world page resources=[] diff --git a/page-hello-world/src/index.html b/page-hello-world/src/index.html index 7b27918c4..26877ea71 100644 --- a/page-hello-world/src/index.html +++ b/page-hello-world/src/index.html @@ -8,11 +8,12 @@ -
-

Hello, world!

-

...

-

Learn more

+
+
+

Hello, world!

+

...

+

Learn more

+
- \ No newline at end of file From f6a5f84f425d815521c56a8053ec8597e2c778a7 Mon Sep 17 00:00:00 2001 From: julienmege Date: Tue, 20 Feb 2018 17:32:35 +0100 Subject: [PATCH 3/3] merge Node and React plugin --- build.gradle | 11 +++++++ ...ePlugin.groovy => BonitaPagePlugin.groovy} | 32 ++++++++++++++----- .../groovy/BonitaPagePluginExtension.groovy | 5 +++ buildSrc/src/main/groovy/NpmPagePlugin.groovy | 16 ---------- .../src/main/groovy/ReactPagePlugin.groovy | 20 ------------ page-hello-world-react/build.gradle | 1 - page-hello-world-react/package.json | 2 +- page-hello-world/build.gradle | 1 - 8 files changed, 41 insertions(+), 47 deletions(-) create mode 100644 build.gradle rename buildSrc/src/main/groovy/{PagePlugin.groovy => BonitaPagePlugin.groovy} (51%) create mode 100644 buildSrc/src/main/groovy/BonitaPagePluginExtension.groovy delete mode 100644 buildSrc/src/main/groovy/NpmPagePlugin.groovy delete mode 100644 buildSrc/src/main/groovy/ReactPagePlugin.groovy delete mode 100644 page-hello-world-react/build.gradle delete mode 100644 page-hello-world/build.gradle diff --git a/build.gradle b/build.gradle new file mode 100644 index 000000000..3e3c129f9 --- /dev/null +++ b/build.gradle @@ -0,0 +1,11 @@ + +subprojects { + apply plugin: BonitaPagePlugin + + bonitaPage { + nodeVersion = '8.9.4' + npmVersion = '5.6.0' + frontendBuildDir = 'dist' + } + +} \ No newline at end of file diff --git a/buildSrc/src/main/groovy/PagePlugin.groovy b/buildSrc/src/main/groovy/BonitaPagePlugin.groovy similarity index 51% rename from buildSrc/src/main/groovy/PagePlugin.groovy rename to buildSrc/src/main/groovy/BonitaPagePlugin.groovy index 6c3ae572a..5aabe5ee7 100644 --- a/buildSrc/src/main/groovy/PagePlugin.groovy +++ b/buildSrc/src/main/groovy/BonitaPagePlugin.groovy @@ -1,46 +1,62 @@ import org.gradle.api.Plugin import org.gradle.api.Project -abstract class PagePlugin implements Plugin { +class BonitaPagePlugin implements Plugin { @Override void apply(Project project) { + def extension = project.extensions.create('bonitaPage', BonitaPagePluginExtension) project.plugins.apply('com.moowork.node') project.plugins.apply('distribution') def currentDir = project.rootProject.projectDir + project.node { - version = '8.9.4' - npmVersion = '5.6.0' download = true workDir = project.file("${currentDir}/.gradle/nodejs") npmWorkDir = project.file("${currentDir}/.gradle/npm") } + project.afterEvaluate { + project.node { + version = extension.nodeVersion + npmVersion = extension.npmVersion + } + } + project.tasks.npm_install.configure { inputs.files('package.json', 'package-lock.json') outputs.dirs('node_modules') } - def buildNpm = project.task( [type: com.moowork.gradle.node.npm.NpmTask, dependsOn: project.tasks.npm_install] ,'buildNpm') { + def buildPage = project.task([type: com.moowork.gradle.node.npm.NpmTask, dependsOn: project.tasks.npm_install], 'buildPage') { args = ['run', 'build'] inputs.files('package.json', 'package-lock.json') inputs.dir('src') } - project.tasks.distZip.dependsOn buildNpm + project.tasks.distZip.dependsOn buildPage def cleanNpm = project.task([:], 'cleanNpm') { doFirst { - project.delete 'dist' + project.delete extension.frontendBuildDir } } project.tasks.clean.dependsOn cleanNpm - implementDistribution(project); + project.distributions { + main { + contents { + from('resources') { into '/' } + from({ extension.frontendBuildDir }) { + into '/resources' + } + } + } + } + } - abstract implementDistribution(Project project); } diff --git a/buildSrc/src/main/groovy/BonitaPagePluginExtension.groovy b/buildSrc/src/main/groovy/BonitaPagePluginExtension.groovy new file mode 100644 index 000000000..8e7646478 --- /dev/null +++ b/buildSrc/src/main/groovy/BonitaPagePluginExtension.groovy @@ -0,0 +1,5 @@ +class BonitaPagePluginExtension { + String nodeVersion + String npmVersion + String frontendBuildDir +} \ No newline at end of file diff --git a/buildSrc/src/main/groovy/NpmPagePlugin.groovy b/buildSrc/src/main/groovy/NpmPagePlugin.groovy deleted file mode 100644 index e6ac61b3d..000000000 --- a/buildSrc/src/main/groovy/NpmPagePlugin.groovy +++ /dev/null @@ -1,16 +0,0 @@ -import org.gradle.api.Plugin -import org.gradle.api.Project - -class NpmPagePlugin extends PagePlugin { - - def implementDistribution(Project project){ - project.distributions{ - main { - contents { - from('resources') { into '/' } - from('dist') { into '/resources' } - } - } - } - } -} diff --git a/buildSrc/src/main/groovy/ReactPagePlugin.groovy b/buildSrc/src/main/groovy/ReactPagePlugin.groovy deleted file mode 100644 index 84a050427..000000000 --- a/buildSrc/src/main/groovy/ReactPagePlugin.groovy +++ /dev/null @@ -1,20 +0,0 @@ -import org.gradle.api.Plugin -import org.gradle.api.Project - -class ReactPagePlugin extends PagePlugin { - - def implementDistribution(Project project){ - project.distributions{ - main { - contents { - from('resources') { into '/' } - from('build') { - exclude 'distributions' - into '/resources' - } - } - } - } - } - -} diff --git a/page-hello-world-react/build.gradle b/page-hello-world-react/build.gradle deleted file mode 100644 index 77ac499f9..000000000 --- a/page-hello-world-react/build.gradle +++ /dev/null @@ -1 +0,0 @@ -apply plugin : ReactPagePlugin \ No newline at end of file diff --git a/page-hello-world-react/package.json b/page-hello-world-react/package.json index 621cfa062..146a3c676 100644 --- a/page-hello-world-react/package.json +++ b/page-hello-world-react/package.json @@ -10,7 +10,7 @@ }, "scripts": { "start": "react-scripts start", - "build": "react-scripts build", + "build": "react-scripts build && mv build dist || move build dist", "test": "react-scripts test --env=jsdom", "eject": "react-scripts eject" }, diff --git a/page-hello-world/build.gradle b/page-hello-world/build.gradle deleted file mode 100644 index fab460db1..000000000 --- a/page-hello-world/build.gradle +++ /dev/null @@ -1 +0,0 @@ -apply plugin : NpmPagePlugin \ No newline at end of file