Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ Options:
--namespace <namespace> (Windows only!) The namespace for the Windows module
(Default: The name as PascalCase)
--platforms <platforms> Platforms the library will be created for. (comma separated; default: `ios,android,windows`)
--github-account <github_account> The github account where the library is hosted (Default: `github_account`)
--author-name <name> The author's name (Default: `Your Name`)
--author-email <email> The author's email (Default: `yourname@email.com`)
--license <license> The license type of this library (Default: `Apache-2.0`)
```

## Programmatic usage
Expand All @@ -69,6 +73,10 @@ createLibrary({
platforms: Array, /* Platforms the library will be created for. (Default: ['ios', 'android', 'windows']) */
packageIdentifier: String, /* (Android only!) The package name for the Android module (Default: com.reactlibrary) */
namespace: String, /* (Windows only!) The namespace for the Windows module (Default: The package identifier as PascalCase, which is `Com.Reactlibrary`) */
githubAccount: String, /* The github account where the library is hosted (Default: `github_account`) */
authorName: String, /* The author's name (Default: `Your Name`) */
authorEmail: String, /* The author's email (Default: `yourname@email.com`) */
license: String, /* The license type of this library (Default: `Apache-2.0`) */
}
```

Expand Down
24 changes: 24 additions & 0 deletions command.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ module.exports = {
const namespace = options.namespace;
const platforms = (options.platforms) ? options.platforms.split(',') : options.platforms;
const overridePrefix = options.overridePrefix;
const githubAccount = options.githubAccount;
const authorName = options.authorName;
const authorEmail = options.authorEmail;
const license = options.license;

const beforeCreation = Date.now();
createLibrary({
Expand All @@ -24,6 +28,10 @@ module.exports = {
platforms,
namespace,
overridePrefix,
githubAccount,
authorName,
authorEmail,
license
}).then(() => {
console.log(`
${emoji.get('books')} Created library ${name} in \`./${name}\`.
Expand Down Expand Up @@ -60,5 +68,21 @@ ${emoji.get('arrow_right')} To get started type \`cd ./${name}\` and run \`npm
command: '--platforms <platforms>',
description: 'Platforms the library will be created for. (comma separated; default: `ios,android,windows`)',
default: 'ios,android,windows',
}, {
command: '--github-account [githubAccount]',
description: 'The github account where the library is hosted (Default: `github_account`)',
default: 'github_account',
}, {
command: '--author-name [authorName]',
description: 'The author\'s name (Default: `Your Name`)',
default: 'Your Name',
}, {
command: '--author-email [authorEmail]',
description: 'The author\'s email (Default: `yourname@email.com`)',
default: 'yourname@email.com',
}, {
command: '--license [license]',
description: 'The license type (Default: `Apache-2.0`)',
default: 'Apache-2.0',
}]
};
12 changes: 12 additions & 0 deletions lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ const DEFAULT_MODULE_PREFIX = 'react-native';
const DEFAULT_PACKAGE_IDENTIFIER = 'com.reactlibrary';
const DEFAULT_PLATFORMS = ['android', 'ios', 'windows'];
const DEFAULT_OVERRIDE_PREFIX = false;
const DEFAULT_GITHUB_ACCOUNT = 'github_account'
const DEFAULT_AUTHOR_NAME = 'Your Name'
const DEFAULT_AUTHOR_EMAIL = 'yourname@email.com'
const DEFAULT_LICENSE = 'Apache-2.0'

module.exports = ({
namespace,
Expand All @@ -21,6 +25,10 @@ module.exports = ({
packageIdentifier = DEFAULT_PACKAGE_IDENTIFIER,
platforms = DEFAULT_PLATFORMS,
overridePrefix = DEFAULT_OVERRIDE_PREFIX,
githubAccount = DEFAULT_GITHUB_ACCOUNT,
authorName = DEFAULT_AUTHOR_NAME,
authorEmail = DEFAULT_AUTHOR_EMAIL,
license = DEFAULT_LICENSE,
}) => {
if (!overridePrefix) {
if (hasPrefix(name)) {
Expand Down Expand Up @@ -64,6 +72,10 @@ module.exports = ({
packageIdentifier,
namespace: namespace || pascalCase(name).split(/(?=[A-Z])/).join('.'),
platforms,
githubAccount,
authorName,
authorEmail,
license,
};

const filename = path.join(name, template.name(args));
Expand Down
93 changes: 91 additions & 2 deletions templates/android.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = platform => [{
name: () => `${platform}/build.gradle`,
content: () => `
content: ({ packageIdentifier }) => `
buildscript {
repositories {
jcenter()
Expand All @@ -14,6 +14,7 @@ buildscript {
}

apply plugin: 'com.android.library'
apply plugin: 'maven'

android {
compileSdkVersion 23
Expand Down Expand Up @@ -43,6 +44,77 @@ repositories {
dependencies {
compile 'com.facebook.react:react-native:+'
}

def configureReactNativePom(def pom) {
def packageJson = new groovy.json.JsonSlurper().parseText(file('../package.json').text)

pom.project {
name packageJson.title
artifactId packageJson.name
version = packageJson.version
group = "${packageIdentifier}"
description packageJson.description
url packageJson.repository.baseUrl

licenses {
license {
name packageJson.license
url packageJson.repository.baseUrl + '/blob/master/' + packageJson.licenseFilename
distribution 'repo'
}
}

developers {
developer {
id packageJson.author.username
name packageJson.author.name
}
}
}
}

afterEvaluate { project ->

task androidJavadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += files(android.bootClasspath)
classpath += files(project.getConfigurations().getByName('compile').asList())
include '**/*.java'
}

task androidJavadocJar(type: Jar, dependsOn: androidJavadoc) {
classifier = 'javadoc'
from androidJavadoc.destinationDir
}

task androidSourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.srcDirs
include '**/*.java'
}

android.libraryVariants.all { variant ->
def name = variant.name.capitalize()
task "jar$\{name\}"(type: Jar, dependsOn: variant.javaCompile) {
from variant.javaCompile.destinationDir
}
}

artifacts {
archives androidSourcesJar
archives androidJavadocJar
}

task installArchives(type: Upload) {
configuration = configurations.archives
repositories.mavenDeployer {
// Deploy to react-native-event-bridge/maven, ready to publish to npm
repository url: "file://$\{projectDir\}/../android/maven"

configureReactNativePom pom
}
}
}
`,
}, {
name: () => `${platform}/src/main/AndroidManifest.xml`,
Expand Down Expand Up @@ -108,4 +180,21 @@ public class ${name}Package implements ReactPackage {
return Collections.emptyList();
}
}`,
}];
}, {
name: () => `${platform}/README.md`,
content: () => `
README
======

If you want to publish the lib as a maven dependency, follow these steps before publishing a new version to npm:

1. Be sure to have the Android [SDK](https://developer.android.com/studio/index.html) and [NDK](https://developer.android.com/ndk/guides/index.html) installed
2. Be sure to have a \`local.properties\` file in this folder that points to the Android SDK and NDK
\`\`\`
ndk.dir=/Users/{username}/Library/Android/sdk/ndk-bundle
sdk.dir=/Users/{username}/Library/Android/sdk
\`\`\`
3. Delete the \`maven\` folder
4. Run \`sudo ./gradlew installArchives\`
5. Verify that latest set of generated files is in the maven folder with the correct version number
`}];
17 changes: 14 additions & 3 deletions templates/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ ${name};
},
}, {
name: () => 'package.json',
content: ({ moduleName, platforms }) => {
content: ({ moduleName, platforms, githubAccount, authorName, authorEmail, license }) => {
let dependencies = `
"react": "16.0.0-alpha.6",
"react-native": "^0.44.1"`;
Expand All @@ -85,17 +85,28 @@ ${name};
return `
{
"name": "${moduleName}",
"title": "${moduleName.split('-').map(word => word[0].toUpperCase() + word.substr(1)).join(' ')}",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if we need this property here or if we could prepare this in the templates/android.js file instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I placed it into package.json on purpose. It may only be used by the Android maven config at this time, but for the sake of consistency I think it's good to have it here so that all config values that feed into the maven config can be changed in one place.

"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \\"Error: no test specified\\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/${githubAccount}/${moduleName}.git",
"baseUrl": "https://github.com/${githubAccount}/${moduleName}"
},
"keywords": [
"react-native"
],
"author": "",
"license": "",
"author": {
"name": "${authorName}",
"email": "${authorEmail}"
},
"license": "${license}",
"licenseFilename": "LICENSE",
"readmeFilename": "README.md",
"peerDependencies": {
${dependencies}
},
Expand Down