Skip to content

Commit

Permalink
Prettier RN local-cli
Browse files Browse the repository at this point in the history
Reviewed By: yungsters

Differential Revision: D7962462

fbshipit-source-id: 0afe2092af8703895de91a6d1400315c3173aa6d
  • Loading branch information
elicwhite authored and facebook-github-bot committed May 11, 2018
1 parent 81f02e9 commit 0f70beb
Show file tree
Hide file tree
Showing 209 changed files with 3,170 additions and 2,074 deletions.
7 changes: 5 additions & 2 deletions __mocks__/beeper.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
'use strict';

'use strict';

// [email protected] has a return statement outside of a function
// and therefore doesn't parse. Let's mock it so that we can
// run the tests.
module.exports = function () {};
module.exports = function() {};
3 changes: 3 additions & 0 deletions bundle/__mocks__/sign.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/

'use strict';

function sign(source) {
Expand Down
19 changes: 14 additions & 5 deletions bundle/__tests__/filterPlatformAssetScales-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,23 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @emails oncall+javascript_foundation
*/

'use strict';

jest
.dontMock('../filterPlatformAssetScales')
.dontMock('../assetPathUtils');
jest.dontMock('../filterPlatformAssetScales').dontMock('../assetPathUtils');

const filterPlatformAssetScales = require('../filterPlatformAssetScales');

describe('filterPlatformAssetScales', () => {
it('removes everything but 2x and 3x for iOS', () => {
expect(filterPlatformAssetScales('ios', [1, 1.5, 2, 3, 4])).toEqual([1, 2, 3]);
expect(filterPlatformAssetScales('ios', [1, 1.5, 2, 3, 4])).toEqual([
1,
2,
3,
]);
expect(filterPlatformAssetScales('ios', [3, 4])).toEqual([3]);
});

Expand All @@ -28,6 +32,11 @@ describe('filterPlatformAssetScales', () => {
});

it('keeps all scales for unknown platform', () => {
expect(filterPlatformAssetScales('freebsd', [1, 1.5, 2, 3.7])).toEqual([1, 1.5, 2, 3.7]);
expect(filterPlatformAssetScales('freebsd', [1, 1.5, 2, 3.7])).toEqual([
1,
1.5,
2,
3.7,
]);
});
});
20 changes: 9 additions & 11 deletions bundle/__tests__/getAssetDestPathAndroid-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @emails oncall+javascript_foundation
*/

'use strict';

jest
.dontMock('../getAssetDestPathAndroid')
.dontMock('../assetPathUtils');
jest.dontMock('../getAssetDestPathAndroid').dontMock('../assetPathUtils');

const getAssetDestPathAndroid = require('../getAssetDestPathAndroid');

Expand All @@ -24,7 +24,9 @@ describe('getAssetDestPathAndroid', () => {

const expectDestPathForScaleToStartWith = (scale, path) => {
if (!getAssetDestPathAndroid(asset, scale).startsWith(path)) {
throw new Error(`asset for scale ${scale} should start with path '${path}'`);
throw new Error(
`asset for scale ${scale} should start with path '${path}'`,
);
}
};

Expand All @@ -43,7 +45,7 @@ describe('getAssetDestPathAndroid', () => {
};

expect(getAssetDestPathAndroid(asset, 1)).toBe(
'drawable-mdpi/app_test_icon.png'
'drawable-mdpi/app_test_icon.png',
);
});

Expand All @@ -54,9 +56,7 @@ describe('getAssetDestPathAndroid', () => {
httpServerLocation: '/assets/RKJSModules/Apps/AndroidSample/Assets',
};

expect(
getAssetDestPathAndroid(asset, 1).startsWith('assets_')
).toBeFalsy();
expect(getAssetDestPathAndroid(asset, 1).startsWith('assets_')).toBeFalsy();
});

it('should put non-drawable resources to `raw/`', () => {
Expand All @@ -66,8 +66,6 @@ describe('getAssetDestPathAndroid', () => {
httpServerLocation: '/assets/app/test',
};

expect(getAssetDestPathAndroid(asset, 1)).toBe(
'raw/app_test_video.mp4'
);
expect(getAssetDestPathAndroid(asset, 1)).toBe('raw/app_test_video.mp4');
});
});
2 changes: 2 additions & 0 deletions bundle/__tests__/getAssetDestPathIOS-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @emails oncall+javascript_foundation
*/

'use strict';

jest.dontMock('../getAssetDestPathIOS');
Expand Down
31 changes: 19 additions & 12 deletions bundle/assetPathUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow
*/

Expand All @@ -17,12 +18,18 @@ import type {PackagerAsset} from '../../Libraries/Image/AssetRegistry';
*/
function getAndroidAssetSuffix(scale: number): string {
switch (scale) {
case 0.75: return 'ldpi';
case 1: return 'mdpi';
case 1.5: return 'hdpi';
case 2: return 'xhdpi';
case 3: return 'xxhdpi';
case 4: return 'xxxhdpi';
case 0.75:
return 'ldpi';
case 1:
return 'mdpi';
case 1.5:
return 'hdpi';
case 2:
return 'xhdpi';
case 3:
return 'xxhdpi';
case 4:
return 'xxxhdpi';
}
throw new Error('no such scale');
}
Expand All @@ -45,8 +52,8 @@ function getAndroidResourceFolderName(asset: PackagerAsset, scale: number) {
var suffix = getAndroidAssetSuffix(scale);
if (!suffix) {
throw new Error(
'Don\'t know which android drawable suffix to use for asset: ' +
JSON.stringify(asset)
"Don't know which android drawable suffix to use for asset: " +
JSON.stringify(asset),
);
}
const androidFolder = 'drawable-' + suffix;
Expand All @@ -57,9 +64,9 @@ function getAndroidResourceIdentifier(asset: PackagerAsset) {
var folderPath = getBasePath(asset);
return (folderPath + '/' + asset.name)
.toLowerCase()
.replace(/\//g, '_') // Encode folder structure in file name
.replace(/([^a-z0-9_])/g, '') // Remove illegal chars
.replace(/^assets_/, ''); // Remove "assets_" prefix
.replace(/\//g, '_') // Encode folder structure in file name
.replace(/([^a-z0-9_])/g, '') // Remove illegal chars
.replace(/^assets_/, ''); // Remove "assets_" prefix
}

function getBasePath(asset: PackagerAsset) {
Expand All @@ -74,5 +81,5 @@ module.exports = {
getAndroidAssetSuffix: getAndroidAssetSuffix,
getAndroidResourceFolderName: getAndroidResourceFolderName,
getAndroidResourceIdentifier: getAndroidResourceIdentifier,
getBasePath: getBasePath
getBasePath: getBasePath,
};
7 changes: 2 additions & 5 deletions bundle/buildBundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow
*/

Expand Down Expand Up @@ -117,11 +118,7 @@ async function buildBundle(
});

// When we're done saving bundle output and the assets, we're done.
const assets = await saveAssets(
outputAssets,
args.platform,
args.assetsDest,
);
const assets = await saveAssets(outputAssets, args.platform, args.assetsDest);

server.end();

Expand Down
3 changes: 3 additions & 0 deletions bundle/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/

'use strict';

const buildBundle = require('./buildBundle');
Expand Down
76 changes: 51 additions & 25 deletions bundle/bundleCommandLineArgs.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,68 +3,94 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/

'use strict';

module.exports = [
{
command: '--entry-file <path>',
description: 'Path to the root JS file, either absolute or relative to JS root',
}, {
description:
'Path to the root JS file, either absolute or relative to JS root',
},
{
command: '--platform [string]',
description: 'Either "ios" or "android"',
default: 'ios',
}, {
},
{
command: '--transformer [string]',
description: 'Specify a custom transformer to be used',
}, {
},
{
command: '--dev [boolean]',
description: 'If false, warnings are disabled and the bundle is minified',
parse: (val) => val === 'false' ? false : true,
parse: val => (val === 'false' ? false : true),
default: true,
}, {
},
{
command: '--minify [boolean]',
description: 'Allows overriding whether bundle is minified. This defaults to ' +
description:
'Allows overriding whether bundle is minified. This defaults to ' +
'false if dev is true, and true if dev is false. Disabling minification ' +
'can be useful for speeding up production builds for testing purposes.',
parse: (val) => val === 'false' ? false : true,
}, {
parse: val => (val === 'false' ? false : true),
},
{
command: '--bundle-output <string>',
description: 'File name where to store the resulting bundle, ex. /tmp/groups.bundle',
}, {
description:
'File name where to store the resulting bundle, ex. /tmp/groups.bundle',
},
{
command: '--bundle-encoding [string]',
description: 'Encoding the bundle should be written in (https://nodejs.org/api/buffer.html#buffer_buffer).',
description:
'Encoding the bundle should be written in (https://nodejs.org/api/buffer.html#buffer_buffer).',
default: 'utf8',
}, {
},
{
command: '--max-workers [number]',
description: 'Specifies the maximum number of workers the worker-pool ' +
description:
'Specifies the maximum number of workers the worker-pool ' +
'will spawn for transforming files. This defaults to the number of the ' +
'cores available on your machine.',
parse: (workers: string) => Number(workers),
}, {
},
{
command: '--sourcemap-output [string]',
description: 'File name where to store the sourcemap file for resulting bundle, ex. /tmp/groups.map',
}, {
description:
'File name where to store the sourcemap file for resulting bundle, ex. /tmp/groups.map',
},
{
command: '--sourcemap-sources-root [string]',
description: 'Path to make sourcemap\'s sources entries relative to, ex. /root/dir',
}, {
description:
"Path to make sourcemap's sources entries relative to, ex. /root/dir",
},
{
command: '--sourcemap-use-absolute-path',
description: 'Report SourceMapURL using its full path',
default: false,
}, {
},
{
command: '--assets-dest [string]',
description: 'Directory name where to store assets referenced in the bundle',
}, {
description:
'Directory name where to store assets referenced in the bundle',
},
{
command: '--verbose',
description: 'Enables logging',
default: false,
}, {
},
{
command: '--reset-cache',
description: 'Removes cached files',
default: false,
}, {
},
{
command: '--read-global-cache',
description: 'Try to fetch transformed JS code from the global cache, if configured.',
description:
'Try to fetch transformed JS code from the global cache, if configured.',
default: false,
},
];
8 changes: 6 additions & 2 deletions bundle/getAssetDestPathAndroid.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow
*/

Expand All @@ -15,8 +16,11 @@ const path = require('path');
import type {PackagerAsset} from '../../Libraries/Image/AssetRegistry';

function getAssetDestPathAndroid(asset: PackagerAsset, scale: number): string {
const androidFolder = assetPathUtils.getAndroidResourceFolderName(asset, scale);
const fileName = assetPathUtils.getAndroidResourceIdentifier(asset);
const androidFolder = assetPathUtils.getAndroidResourceFolderName(
asset,
scale,
);
const fileName = assetPathUtils.getAndroidResourceIdentifier(asset);
return path.join(androidFolder, fileName + '.' + asset.type);
}

Expand Down
1 change: 1 addition & 0 deletions bundle/getAssetDestPathIOS.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow
*/

Expand Down
Loading

0 comments on commit 0f70beb

Please sign in to comment.