Skip to content
This repository has been archived by the owner on May 9, 2022. It is now read-only.

Commit

Permalink
Merge branch '#45/simplify_node_modules'
Browse files Browse the repository at this point in the history
* #45/simplify_node_modules:
  #45: npm scripts npmLink and npmUnlink handles all crosslinking, and is integrated with gradle task npmInstall, so it's better to use that than 'npm i'
  Readme: clean command
  #45: untested, improve versionAndPublish by adding opportunity for manually verifying the levels and interdependencies
  #45: untested, but versionAndPublish task sequence is tightened and documented.
  #45 cleanup: remove some deprecated build steps
  #45: packages/* refactored, so far seems to work: gradlew build, clean, lint and test
  #45: packages/constants refactored, so far seems to work: gradlew build, clean, lint and test
  #45: Project root level takes over node_modules, sets up symlinks in packages/*. Packages should not run npm install during development - always run gradle npmInstall from the root and keep the root's package.json up to date with all the dependencies: {} under packages/* (dependencies should be both places - but not DEVdependencies). Also, keep the root's package.json up to date with all the DEVdependencies that are used under packages/* (DEVdependencies needed by packages/* should not be declared in the package.json under the specific packages/*, but in the root's package.json).
  #45: needed remake after clean. Working with making npm run test:raw work
  #45: appears to work
  #45: upgrade mocha. Still doesnt work.
  #45: trying to make buildcomponents package use dependencies from root node_modules.
  NPM update
  • Loading branch information
espen42 committed Mar 18, 2021
2 parents b3ce7fd + 797edd3 commit 7edd05e
Show file tree
Hide file tree
Showing 36 changed files with 9,847 additions and 44,817 deletions.
9 changes: 9 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es6"
},
"presets": [
["@babel/preset-env"]
]
}
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,10 @@
**/*.css.map


# Node modules
# Node modules folders
**/node_modules/
# Node modules symlinks
**/node_modules

# Visual studio code project files
**/bin/
Expand Down
3 changes: 3 additions & 0 deletions .mocharc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"require": " @babel/register"
}
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
12.21.0
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ From the project root, handles the entire file structure: triggers the same task

- `gradlew cleanNpm`: delete node_modules/ folders in all packages. Cancels the linked mode (see `npmLink` below).

- `gradlew cleanBuilt`: delete build/ folders in all packages
- `gradlew clean`: delete build/ folders in all packages

- `gradlew npmLink`: enter development linked mode: same as running [npm link](https://docs.npmjs.com/cli/link.html) in each package, but also linking up the internal dependencies between the packages. Use the cleanNpm gradle task (above) to exit linked mode. A corresponding script, `getlinks.sh`, can be run by relative path from a parent project's root folder (e.g. `sh ../../react4xp-npm/getlinks.sh`) to hook up the same links below that project's node_modules/. Sorry, no windows script yet (but it should be easy to reverse-engineer).

Expand Down
109 changes: 30 additions & 79 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,69 +16,20 @@ allprojects {
}
}


project.ext.SUBPROJS_TO_IGNORE = [
'packages'
]
configure(subprojects.findAll {!project.ext.SUBPROJS_TO_IGNORE.contains(it.name)}) {
apply plugin: "com.moowork.node" // version "1.3.1"

task cleanNpm(type: Delete) {
delete 'node_modules'
}


def slash = File.separator
project.ext.PROJDIR = "${project.buildDir.toString()}${slash}${slash}${slash}".replace("${slash}build${slash}${slash}", '')

def markerName = "${project.ext.PROJDIR}node_modules${slash}react4xp${slash}npmInstalled.marker"
def linkMarkerName = "${project.ext.PROJDIR}node_modules${slash}react4xp${slash}npmLinked.marker"

task nsiInstall(type:NpmTask) {
args=['run', 'nsi:install']
doLast {
def marker = new File(linkMarkerName)
new File(marker.getParent()).mkdirs()
marker.text = """
Marker file, indicating that node_module is locally linked - faster than traversing the entire node_modules tree for changes.
"""
println "Created: $linkMarkerName"
}
}
nsiInstall.inputs.files('package.json', 'package-lock.json')
nsiInstall.outputs.file('package-lock.json')
nsiInstall.outputs.file file(linkMarkerName)

if (new File(linkMarkerName).exists()) {
println "$linkMarkerName found!"
npmInstall.enabled = false
npmInstall.dependsOn nsiInstall

} else {
// println "$linkMarkerName not found."
npmInstall.enabled = true
npmInstall.inputs.files('package.json', 'package-lock.json')
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.
"""
}
}


task cleanBuilt(type: Delete) {}
task npmClean(type: Delete) {
delete 'node_modules'
}
task clean(type: Delete) {}

task compileJS(type: NpmTask) {}
compileJS.inputs.file('package.json')
compileJS.inputs.dir('src')
compileJS.dependsOn ":packages:${project.name}:npmInstall"


task build {}
Expand All @@ -87,55 +38,55 @@ Marker file, indicating that the npmInstall gradle task has been run in this sub
task lint(type: NpmTask) {
args=['run', 'lint']
}
lint.inputs.file('package.json')
lint.inputs.dir('src')
lint.outputs.dir('src')
lint.dependsOn ":packages:${project.name}:npmInstall"
build.shouldRunAfter ":packages:${project.name}:lint"


task npmLink(type: NpmTask) {
args=['link']
doLast {
def marker = new File(linkMarkerName)
new File(marker.getParent()).mkdirs()
marker.text = """
Marker file, indicating that node_module is locally linked - faster than traversing the entire node_modules tree for changes.
"""
println "Created: $linkMarkerName"
}
}
npmLink.dependsOn lint


task test(type: NpmTask) {}
test.inputs.files('package.json')
test.inputs.dir('src')
test.inputs.dir('test')
// test.dependsOn ":packages:${project.name}:npmClean"
test.dependsOn ":packages:${project.name}:npmInstall"
test.dependsOn ":packages:${project.name}:lint"
test.dependsOn ":packages:${project.name}:npmLink"
test.dependsOn build
npmInstall.shouldRunAfter npmClean
lint.shouldRunAfter npmInstall
npmLink.shouldRunAfter lint
build.shouldRunAfter npmLink
// build.dependsOn npmInstall

npmInstall.enabled = false
}


def slash = File.separator
def markerName = ".${slash}node_modules${slash}react4xp${slash}npmInstalled.txt"
npmInstall.inputs.files('package.json', 'package-lock.json')
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 = """

task npmDoInstall(type: NpmTask) {
args=['install']

inputs.files('package.json', 'package-lock.json', 'build.gradle')
outputs.file('package-lock.json')
outputs.file file(markerName)

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 the root project - faster than traversing the entire node_modules tree for changes.
"""
}
}

task npmPreInstall(type: NpmTask) {
args=['run', 'npmUnlink']
}
task npmPostInstall(type: NpmTask) {
args=['run', 'npmLink']
}

npmInstall.enabled = false;
npmInstall.dependsOn npmPostInstall
npmPostInstall.dependsOn npmDoInstall
npmDoInstall.dependsOn npmPreInstall


///////////////////////////////////////////////////

Expand Down
Loading

0 comments on commit 7edd05e

Please sign in to comment.