diff --git a/README.md b/README.md index 01ca238..b2d935c 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,10 @@ Options: --namespace (Windows only!) The namespace for the Windows module (Default: The name as PascalCase) --platforms Platforms the library will be created for. (comma separated; default: `ios,android,windows`) + --github-account The github account where the library is hosted (Default: `github_account`) + --author-name The author's name (Default: `Your Name`) + --author-email The author's email (Default: `yourname@email.com`) + --license The license type of this library (Default: `Apache-2.0`) ``` ## Programmatic usage @@ -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`) */ } ``` diff --git a/command.js b/command.js index a1b629f..814c37f 100644 --- a/command.js +++ b/command.js @@ -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({ @@ -24,6 +28,10 @@ module.exports = { platforms, namespace, overridePrefix, + githubAccount, + authorName, + authorEmail, + license }).then(() => { console.log(` ${emoji.get('books')} Created library ${name} in \`./${name}\`. @@ -60,5 +68,21 @@ ${emoji.get('arrow_right')} To get started type \`cd ./${name}\` and run \`npm command: '--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', }] }; diff --git a/lib.js b/lib.js index ed846bc..e74ebc4 100644 --- a/lib.js +++ b/lib.js @@ -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, @@ -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)) { @@ -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)); diff --git a/templates/android.js b/templates/android.js index e22b577..8fa18aa 100644 --- a/templates/android.js +++ b/templates/android.js @@ -1,6 +1,6 @@ module.exports = platform => [{ name: () => `${platform}/build.gradle`, - content: () => ` + content: ({ packageIdentifier }) => ` buildscript { repositories { jcenter() @@ -14,6 +14,7 @@ buildscript { } apply plugin: 'com.android.library' +apply plugin: 'maven' android { compileSdkVersion 23 @@ -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`, @@ -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 +`}]; diff --git a/templates/general.js b/templates/general.js index 2185a56..a4a05d0 100644 --- a/templates/general.js +++ b/templates/general.js @@ -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"`; @@ -85,17 +85,28 @@ ${name}; return ` { "name": "${moduleName}", + "title": "${moduleName.split('-').map(word => word[0].toUpperCase() + word.substr(1)).join(' ')}", "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} },