-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
820 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.n |
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 |
---|---|---|
|
@@ -3,4 +3,40 @@ assetman | |
|
||
Haxe library used to generate ninja file. | ||
|
||
The goal is to scan the directories, and using the rules, generate a ninja.build | ||
|
||
Rules | ||
----- | ||
|
||
You can create rules, that will be reused later | ||
|
||
rule('convert2').command("cp $in $out"); | ||
rule('convert').command("cp $in $out"); | ||
rule('atlas').command("cat $in > $name"); | ||
|
||
`$in` and `$out` are default from ninja, but here, `$name` is a variable that will be set later when rule is used | ||
|
||
Patterns | ||
-------- | ||
|
||
Pattern are use to apply rule to file sets | ||
|
||
var pattern = '**/*.png'; | ||
// build [email protected]: convert2 ../src/foo.psd | ||
single(pattern).to("[email protected]").usingRule('convert2'); | ||
// build foo.png: convert ../src/foo.psd | ||
single(pattern).toExt('.png').usingRule('convert'); | ||
var atlasName = 'atlas'; | ||
// build atlas.png atlas.csv: atlas foo.png [email protected] | ||
// name = atlas | ||
bundle('images/*.png') | ||
.fromBuild(true) | ||
.to([atlasName + '.png', atlasName + '.csv']) | ||
.assign('name', atlasName) | ||
.usingRule('atlas'); | ||
|
||
|
||
Acknowledgment | ||
-------------- | ||
|
||
This library was heavily inspired by https://github.com/tylorr/assetman |
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,36 @@ | ||
|
||
import assetman.Builder; | ||
|
||
class CustomBuilder extends Builder { | ||
public function new() { | ||
super(); | ||
} | ||
|
||
function configure() { | ||
rule('convert2').command("cp $in $out"); | ||
rule('convert').command("cp $in $out"); | ||
rule('atlas').command("cat $in > $name.png"); | ||
var pattern = '**/*.png'; | ||
// build [email protected]: convert2 ../src/foo.psd | ||
single(pattern).to("[email protected]").usingRule('convert2'); | ||
// build foo.png: convert ../src/foo.psd | ||
single(pattern).toExt('.png').usingRule('convert'); | ||
var atlasName = 'atlas'; | ||
// build atlas.png atlas.csv: atlas foo.png [email protected] | ||
// name = atlas | ||
bundle('images/*.png') | ||
.fromBuild(true) | ||
.to([atlasName + '.png']) | ||
.assign('name', atlasName) | ||
.usingRule('atlas'); | ||
} | ||
} | ||
|
||
class Main { | ||
|
||
|
||
static function main() { | ||
var builder = new CustomBuilder(); | ||
builder.generate("../test"); | ||
} | ||
} |
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,11 @@ | ||
## Neko | ||
-main Main | ||
-cp src | ||
-lib assetman | ||
-neko assetman.n | ||
|
||
--next | ||
|
||
-main CompareEcho | ||
-lib assetman | ||
-neko compare_echo.n |
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,73 @@ | ||
|
||
import sys.FileSystem; | ||
import hx.files.Dir; | ||
import haxe.io.Path; | ||
|
||
class CompareEcho { | ||
|
||
|
||
static function main() { | ||
|
||
var args = Sys.args(); | ||
|
||
var current_directory : String; | ||
if(args.length >= 3) { | ||
current_directory = args[2]; | ||
} else { | ||
current_directory = FileSystem.absolutePath(""); | ||
} | ||
|
||
trace( Sys.args().join('\n') ); | ||
|
||
// construct search patterns | ||
var patterns = args[0].split(' ').map(function(a){return a;}); | ||
var pattern = patterns.length > 1 ? '{' + patterns.join(',') + '}' : patterns[0]; | ||
|
||
trace('Pattern ${pattern} with cw'); | ||
// collect files that match pattern | ||
var dir = Dir.of(current_directory); | ||
var files = dir.findFiles(pattern).map( | ||
function(a) { | ||
return relativePath( FileSystem.absolutePath(current_directory), a.path.getAbsolutePath() ); | ||
}); | ||
files.sort( Reflect.compare ); | ||
var files_as_text = files.join('\n'); | ||
|
||
trace(files_as_text); | ||
|
||
// update file list in output if they don't match | ||
var outpath = args[1]; | ||
var write_file : Bool = true; | ||
|
||
if( sys.FileSystem.exists( outpath )){ | ||
var oldfiles = sys.io.File.getContent( outpath ); | ||
write_file = oldfiles != files_as_text; | ||
} | ||
|
||
if(write_file){ | ||
sys.io.File.saveContent(outpath, files_as_text); | ||
} | ||
} | ||
|
||
static function relativePath(relativeTo: String, path: String) { | ||
// make both absolute | ||
path = Path.removeTrailingSlashes(FileSystem.absolutePath(path)); | ||
relativeTo = Path.removeTrailingSlashes(FileSystem.absolutePath(relativeTo)); | ||
var aPath = path.split('/'); | ||
var aRelativeTo = relativeTo.split('/'); | ||
// find shared part of path | ||
var matchesUpToIndex = 0; | ||
|
||
for(i in 0...aRelativeTo.length) { | ||
if(aPath[i] == aRelativeTo[i]) { | ||
matchesUpToIndex = i; | ||
} else { | ||
break; | ||
} | ||
} | ||
|
||
return [for(_ in 0...(aRelativeTo.length - 1) - matchesUpToIndex) '..'] | ||
.concat(aPath.slice(matchesUpToIndex + 1)) | ||
.join('/'); | ||
} | ||
} |
Oops, something went wrong.