Skip to content
This repository has been archived by the owner on May 19, 2023. It is now read-only.

Commit

Permalink
Initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmick committed Mar 23, 2016
1 parent 5149667 commit 93fe2ca
Show file tree
Hide file tree
Showing 11 changed files with 131,890 additions and 91 deletions.
65 changes: 47 additions & 18 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,43 +16,72 @@ module.exports = function(grunt) {
all: [
'Gruntfile.js',
'tasks/*.js',
'<%= nodeunit.tests %>'
'<%= nodeunit.tests %>',
],
options: {
jshintrc: '.jshintrc'
jshintrc: '.jshintrc',
}
},

// Before generating any new files, remove any previously-created files.
clean: {
tests: ['tmp']
tests: ['tmp'],
},

// Configuration to be run (and then tested).
react_native: {
default_options: {
ios: {
options: {
minify: false,
verbose: false,
watch: false,
},
files: {
'tmp/default_options': ['test/fixtures/testing', 'test/fixtures/123']
}
src: 'test/fixtures/index.ios.js',
dst: 'tmp/dev/index.ios.bundle',
},
custom_options: {
ios_release: {
options: {
separator: ': ',
punctuation: ' !!!'
minify: true,
platform: 'ios',
verbose: false,
watch: false,
},
files: {
'tmp/custom_options': ['test/fixtures/testing', 'test/fixtures/123']
}
}
src: 'test/fixtures/index.ios.js',
dst: 'tmp/release/index.ios.bundle',
},
android: {
options: {
minify: false,
verbose: false,
watch: false,
},
src: 'test/fixtures/index.android.js',
dst: 'tmp/dev/index.android.bundle',
},
android_release: {
options: {
minify: true,
platform: 'android',
verbose: false,
watch: false,
},
src: 'test/fixtures/index.android.js',
dst: 'tmp/release/index.android.bundle',
},
watch: {
options: {
verbose: false,
watch: true,
},
src: 'test/fixtures/',
},
},


// Unit tests.
nodeunit: {
tests: ['test/*_test.js']
}

tests: ['test/*_test.js'],
},
});

// Actually load this plugin's task(s).
Expand All @@ -65,7 +94,7 @@ module.exports = function(grunt) {

// Whenever the "test" task is run, first clean the "tmp" dir, then run this
// plugin's task(s), then test the result.
grunt.registerTask('test', ['clean', 'react_native', 'nodeunit']);
grunt.registerTask('test', ['clean', 'react_native:ios', 'react_native:ios_release', 'react_native:android', 'react_native:android_release', 'nodeunit']);

// By default, lint and run all tests.
grunt.registerTask('default', ['jshint', 'test']);
Expand Down
76 changes: 44 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,58 +25,62 @@ In your project's Gruntfile, add a section named `react_native` to the data obje
```js
grunt.initConfig({
react_native: {
options: {
// Task-specific options go here.
},
your_target: {
// Target-specific file lists and/or options go here.
options: {
// Target-specific options go here.
}
// Target-specific files go here.
},
},
});
```

### Options

#### options.separator
Type: `String`
Default value: `', '`
#### options.minify
Type: `Boolean`
Default value: `false`

A string value that is used to do something with whatever.
Setting to true will minify the resulting bundle.

#### options.punctuation
#### options.platform
Type: `String`
Default value: `'.'`
Default value: The task's (target) name

A string value that is used to do something else with whatever else.
Which platform the bundle is made for.

### Usage Examples
#### options.verbose
Type: `Boolean`
Default value: `false`

#### Default Options
In this example, the default options are used to do something with whatever. So if the `testing` file has the content `Testing` and the `123` file had the content `1 2 3`, the generated result would be `Testing, 1 2 3.`
Verbose mode.

```js
grunt.initConfig({
react_native: {
options: {},
files: {
'dest/default_options': ['src/testing', 'src/123'],
},
},
});
```
#### options.watch
Type: `Boolean`
Default value: `false`

#### Custom Options
In this example, custom options are used to do something else with whatever else. So if the `testing` file has the content `Testing` and the `123` file had the content `1 2 3`, the generated result in this case would be `Testing: 1 2 3 !!!`
Watch mode, this will launch the react native packager server for development.

### Usage Examples

```js
grunt.initConfig({
react_native: {
options: {
separator: ': ',
punctuation: ' !!!',
ios: {
options: {
minify: false,
verbose: false,
watch: false,
},
src: 'src/index.ios.js',
dst: 'build/index.ios.bundle',
},
files: {
'dest/default_options': ['src/testing', 'src/123'],
watch: {
options: {
verbose: false,
watch: true,
},
src: 'src/', // The directory to watch and serve
},
},
});
Expand All @@ -86,4 +90,12 @@ grunt.initConfig({
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/).

## Release History
_(Nothing yet)_

### V 0.1.0 Initial Release

Supports :
* Bundle task
* Watch task

To do :
* Manage assets destination
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "grunt-react-native-wrapper",
"name": "grunt-react-native",
"description": "A grunt plugin for launching the React Native packager and bundle your files for relase",
"version": "0.1.0",
"homepage": "https://github.com/alexmick/grunt-react-native",
Expand Down Expand Up @@ -27,10 +27,12 @@
"test": "grunt test"
},
"devDependencies": {
"grunt-contrib-jshint": "^0.9.2",
"grunt": "~0.4.5",
"grunt-contrib-clean": "^0.5.0",
"grunt-contrib-jshint": "^0.9.2",
"grunt-contrib-nodeunit": "^0.3.3",
"grunt": "~0.4.5"
"react": "^0.14.7",
"react-native": "^0.22.2"
},
"keywords": [
"gruntplugin"
Expand Down
66 changes: 36 additions & 30 deletions tasks/react_native.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,49 @@

'use strict';

module.exports = function(grunt) {
var childProcess = require('child_process');
var path = require('path');

// Please see the Grunt documentation for more information regarding task
// creation: http://gruntjs.com/creating-tasks
module.exports = function(grunt) {

grunt.registerMultiTask('react_native', 'A grunt plugin for launching the React Native packager and bundle your files for relase', function() {
// Merge task-specific and/or target-specific options with these defaults.
var options = this.options({
punctuation: '.',
separator: ', '
minify: false,
platform: this.target,
verbose: false,
watch: false,
});

// Iterate over all specified file groups.
this.files.forEach(function(f) {
// Concat specified files.
var src = f.src.filter(function(filepath) {
// Warn on and remove invalid source files (if nonull was set).
if (!grunt.file.exists(filepath)) {
grunt.log.warn('Source file "' + filepath + '" not found.');
return false;
} else {
return true;
}
}).map(function(filepath) {
// Read file source.
return grunt.file.read(filepath);
}).join(grunt.util.normalizelf(options.separator));

// Handle options.
src += options.punctuation;

// Write the destination file.
grunt.file.write(f.dest, src);

// Print a success message.
grunt.log.writeln('File "' + f.dest + '" created.');
});
var cli = 'node ./node_modules/react-native/local-cli/cli.js ';
var args = ' --reset-cache '; // workaround https://github.com/facebook/react-native/issues/4968
if (options.verbose) {
args += '--verbose ';
}
if (options.minify) {
args += '--dev false ';
}

if (options.watch) {
// The . here is crucial to fix issue https://github.com/facebook/react-native/issues/4968
args += '--projectRoots .,' + this.data.src;

grunt.log.debug("Running : " + cli + 'start' + args);
childProcess.execSync(cli + 'start' + args, { stdio: 'inherit' });
} else {
// Make sur output dir exists as react-native won't create it
var output_dir = path.dirname(this.data.dst);
if (!grunt.file.exists(output_dir)) {
grunt.file.mkdir(output_dir);
}

args += '--entry-file ' + this.data.src;
args += ' --bundle-output ' + this.data.dst;
args += ' --platform ' + options.platform;

grunt.log.debug("Running : " + cli + 'bundle' + args);
childProcess.execSync(cli + 'bundle' + args, { stdio: 'inherit' });
}
});

};
Loading

0 comments on commit 93fe2ca

Please sign in to comment.