-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* extract a separate install task * make plugin self-contained: no external package.json and script files necessary anymore * only depend on systemjs-builder and command-line-args
- Loading branch information
1 parent
04f2622
commit 539aa9d
Showing
8 changed files
with
154 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
dependencies { | ||
compile 'com.moowork.gradle:gradle-node-plugin:0.11' | ||
|
||
compile project(':cat-gradle-utils') | ||
} |
10 changes: 7 additions & 3 deletions
10
...dle-systemjs-plugin/src/main/groovy/cc/catalysts/gradle/systemjs/SystemjsExtension.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...js-plugin/src/main/groovy/cc/catalysts/gradle/systemjs/task/InstallSystemjsBuilder.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package cc.catalysts.gradle.systemjs.task | ||
|
||
import cc.catalysts.gradle.systemjs.SystemjsExtension | ||
import cc.catalysts.gradle.systemjs.SystemjsPlugin | ||
import com.moowork.gradle.node.task.NpmTask | ||
import org.gradle.execution.commandline.TaskConfigurationException | ||
|
||
import java.nio.file.Files | ||
import java.nio.file.StandardCopyOption | ||
|
||
/** | ||
* @author Thomas Scheinecker, Catalysts GmbH | ||
*/ | ||
class InstallSystemjsBuilder extends NpmTask { | ||
public InstallSystemjsBuilder() { | ||
this.group = 'Cat-Boot' | ||
this.description = 'Prepares the systemjs builder' | ||
|
||
project.afterEvaluate({ | ||
SystemjsExtension config = SystemjsExtension.get(project) | ||
|
||
outputs.upToDateWhen { | ||
return config | ||
.getPackageJson() | ||
.equals(config.getPackageJsonFile()) | ||
} | ||
|
||
setWorkingDir(config.nodeModulesDir) | ||
setNpmCommand('install') | ||
|
||
outputs.dir(new File(config.nodeModulesDir, 'node_modules')) | ||
}) | ||
} | ||
|
||
private void writePackageJson() { | ||
SystemjsExtension config = SystemjsExtension.get(project) | ||
File packageJsonFile = config.getPackageJsonFile() | ||
|
||
config.getPackageJson() | ||
.toFile(packageJsonFile) | ||
|
||
if (!packageJsonFile.exists()) { | ||
throw new TaskConfigurationException(path, "Couldn't create ${packageJsonFile}!", null) | ||
} | ||
|
||
logger.lifecycle("Successfully created ${packageJsonFile}") | ||
} | ||
|
||
private void writeSystemjsBundleScript() { | ||
File nodeModulesDir = SystemjsExtension.get(project).nodeModulesDir | ||
|
||
|
||
InputStream systemjsBundleScriptSource = SystemjsPlugin.classLoader.getResourceAsStream('cat-gradle/systemjs/systemjs-bundle.es6') | ||
|
||
File systemjsBundleScript = new File(nodeModulesDir, 'systemjs-bundle.es6') | ||
Files.copy(systemjsBundleScriptSource, systemjsBundleScript.toPath(), StandardCopyOption.REPLACE_EXISTING) | ||
|
||
if (!systemjsBundleScript.exists()) { | ||
throw new TaskConfigurationException(path, "Couldn't create ${systemjsBundleScript}!", null) | ||
} | ||
|
||
logger.lifecycle("Successfully created ${systemjsBundleScript}") | ||
} | ||
|
||
@Override | ||
void exec() { | ||
writePackageJson(); | ||
writeSystemjsBundleScript(); | ||
super.exec() | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
cat-gradle-systemjs-plugin/src/main/resources/cat-gradle/systemjs/systemjs-bundle.es6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
'use strict'; | ||
|
||
var path = require('path'); | ||
var commandLineArgs = require('command-line-args'); | ||
|
||
var cli = commandLineArgs([ | ||
{name: 'project.version', type: String}, | ||
{name: 'source.dir', type: String}, | ||
{name: 'include.path', type: String}, | ||
{name: 'destination.dir', type: String}, | ||
{name: 'bundle.name', type: String}, | ||
{name: 'no-color', type: Boolean}, | ||
{name: 'color', type: Boolean}, | ||
{name: 'cwd', type: String} | ||
]); | ||
|
||
var options = cli.parse(); | ||
|
||
var SystemJsBuilder = require('systemjs-builder'); | ||
|
||
var systemJsBuilderOptions = { | ||
minify: false, | ||
sourceMaps: false | ||
}; | ||
|
||
|
||
function buildBundle(options) { | ||
var sourceDir = path.relative(process.cwd(), options['source.dir']); | ||
var systemJsBuilder = new SystemJsBuilder(sourceDir); | ||
|
||
systemJsBuilder.config({ | ||
meta: {} | ||
}); | ||
|
||
var sourcePath = path.relative(process.cwd(), options['source.dir'] + '/' + options['include.path']); | ||
var bundleFile = path.relative(process.cwd(), options['destination.dir'] + '/' + options['bundle.name'] + '.js'); | ||
return systemJsBuilder | ||
.bundle('[./' + sourcePath + ']', | ||
bundleFile, | ||
systemJsBuilderOptions) | ||
.then(function (result) { | ||
console.log('Sucessfully created bundles for modules:'); | ||
result.modules.forEach(function (module) { | ||
console.log(module); | ||
}); | ||
console.log('Bundle file was saved to', bundleFile); | ||
}); | ||
} | ||
|
||
buildBundle(options) | ||
.then(null, console.error.bind(console)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters