-
-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from noppoMan/add-module-exporter
add module-exporter
- Loading branch information
Showing
5 changed files
with
186 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,114 @@ | ||
const fs = require('fs-promise'); | ||
const co = require('co'); | ||
const _copydir = require('copy-dir'); | ||
const mkdirp = require('mkdirp-promise'); | ||
const _ = require('lodash'); | ||
|
||
_.templateSettings.interpolate = /{{([\s\S]+?)}}/g; | ||
|
||
var currentAWSDKVersion = { | ||
major: "0", | ||
minor: "3" | ||
}; | ||
|
||
const Template = { | ||
_tpls: { | ||
license: require('fs').readFileSync(__dirname+"/templates/LICENSE"), | ||
|
||
packageSwift: require('fs').readFileSync(__dirname+"/templates/Package.swift"), | ||
|
||
readme: require('fs').readFileSync(__dirname+"/templates/README.md") | ||
}, | ||
|
||
render(name, params) { | ||
var compiled = _.template(Template._tpls[name]); | ||
return compiled(params); | ||
} | ||
} | ||
|
||
function copydir(from, to) { | ||
return new Promise(function(resolve, reject){ | ||
_copydir(from, to, (err) => { | ||
if(err) { | ||
return reject(err); | ||
} | ||
resolve(); | ||
}); | ||
}); | ||
} | ||
|
||
const dest = process.argv[2]; | ||
|
||
if(_.isEmpty(dest)) { | ||
console.error("Please specify destination<directory> as a first argument"); | ||
process.exit(1); | ||
} | ||
|
||
function toClassCase(str) { | ||
const find = /(\-\w)/g; | ||
const convert = function(matches){ | ||
return matches[1].toUpperCase(); | ||
}; | ||
str = str.replace(find, convert); | ||
return str.charAt(0).toUpperCase() + str.slice(1);; | ||
} | ||
|
||
function moduleNamefy(name) { | ||
return `SwiftAWS${toClassCase(name)}`; | ||
} | ||
|
||
fs.exists = function(path){ | ||
return new Promise(function(resolve){ | ||
fs.stat(path) | ||
.then(function(){ | ||
resolve(true); | ||
}) | ||
.catch(function(){ | ||
resolve(false); | ||
}); | ||
}) | ||
} | ||
|
||
co(function *() { | ||
const servicePath = __dirname + "/../Sources/AWSSDKSwift/Services"; | ||
const middlewarePath = __dirname + "/../Sources/AWSSDKSwift/Middlewares"; | ||
const entries = yield fs.readdir(servicePath); | ||
for(var index in entries){ | ||
var path = entries[index]; | ||
var src = servicePath+"/"+path; | ||
var repoPath = dest+"/"+path; | ||
var sourceDestPath = repoPath+"/Sources"; | ||
|
||
yield mkdirp(repoPath); | ||
yield mkdirp(sourceDestPath); | ||
|
||
// create files | ||
yield fs.writeFile(repoPath+"/Package.swift", Template.render("packageSwift", { | ||
name: moduleNamefy(path) | ||
})); | ||
|
||
yield fs.writeFile(repoPath+"/LICENSE", Template.render("license")); | ||
|
||
yield fs.writeFile(repoPath+"/README.md", Template.render("readme", { | ||
repositoryName: path, | ||
version: currentAWSDKVersion | ||
})); | ||
|
||
yield fs.writeFile(repoPath+"/.gitignore", [ | ||
".DS_Store", | ||
"/.build", | ||
"/Packages", | ||
"/*.xcodeproj" | ||
].join("\n")); | ||
|
||
yield copydir(src, sourceDestPath); | ||
|
||
if (yield fs.exists(`${middlewarePath}/${path}`)) { | ||
yield copydir(`${middlewarePath}/${path}`, sourceDestPath); | ||
} | ||
} | ||
}) | ||
.catch(function(error){ | ||
console.error(error); | ||
process.exit(1); | ||
}); |
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,19 @@ | ||
{ | ||
"name": "module-exporter", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "main.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"co": "^4.6.0", | ||
"copy-dir": "^0.3.0", | ||
"fs-promise": "^2.0.3", | ||
"lodash": "^4.17.4", | ||
"mkdirp-promise": "^5.0.1" | ||
} | ||
} |
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,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2017 Yuki Takei(noppoMan) | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,10 @@ | ||
// swift-tools-version:3.1 | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "{{name}}", | ||
dependencies: [ | ||
.Package(url: "https://github.com/noppoMan/aws-sdk-swift-core.git", majorVersion: 0, minor: 2) | ||
] | ||
) |
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,22 @@ | ||
# {{repositoryName}} | ||
|
||
An AWS {{repositoryName}} type safe client for Swift (This is part of [aws-sdk-swift](https://github.com/noppoMan/aws-sdk-swift)) | ||
|
||
## Documentation | ||
|
||
Visit the aws-sdk-swift [documentation](http://htmlpreview.github.io/?https://github.com/noppoMan/aws-sdk-swift-doc/blob/master/docs/index.html) for instructions and browsing api references. | ||
|
||
## Installation | ||
|
||
### Package.swift | ||
|
||
```swift | ||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "MyAWSApp", | ||
dependencies: [ | ||
.Package(url: "https://github.com/swift-aws/{{repositoryName}}.git", majorVersion: 0, minor: {{version.minor}}) | ||
] | ||
) | ||
``` |