Skip to content

Commit

Permalink
Merge pull request #5 from inthepocket/feature/pull-changes-from-base…
Browse files Browse the repository at this point in the history
…-branch

Feature/pull changes from base branch
  • Loading branch information
easybird authored Sep 17, 2018
2 parents fc951b3 + fe94f9f commit 0c26a33
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 88 deletions.
25 changes: 13 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,23 @@
"author": "In The Pocket <hello@inthepocket.com> (http://inthepocket.com)",
"license": "MIT",
"dependencies": {
"@babel/cli": "^7.0.0",
"@babel/core": "^7.0.0",
"@babel/plugin-proposal-class-properties": "^7.0.0",
"@babel/plugin-transform-modules-commonjs": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@babel/preset-react": "^7.0.0",
"all-contributors-cli": "^5.0.0",
"arrify": "^1.0.1",
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-cli": "^7.0.0-0",
"babel-eslint": "^9.0.0",
"babel-core": "^7.0.0-0",
"babel-jest": "^23.4.2",
"babel-plugin-external-helpers": "^6.22.0",
"babel-plugin-macros": "^2.3.0",
"babel-plugin-minify-dead-code-elimination": "^0.3.0",
"babel-plugin-minify-dead-code-elimination": "^0.4.0",
"babel-plugin-module-resolver": "^3.1.1",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-inline-environment-variables": "^0.3.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-plugin-transform-react-jsx": "^6.24.1",
"babel-plugin-transform-inline-environment-variables": "^0.4.0",
"babel-plugin-transform-react-remove-prop-types": "^0.4.13",
"babel-preset-env": "^1.6.1",
"babel-preset-react": "^6.24.1",
"browserslist": "^4.0.0",
"concurrently": "^3.5.1",
"cross-env": "^5.1.4",
Expand Down Expand Up @@ -78,8 +78,8 @@
"read-pkg-up": "^4.0.0",
"resolve": "^1.6.0",
"rimraf": "^2.6.2",
"rollup": "^0.63.0",
"rollup-plugin-babel": "^3.0.3",
"rollup": "^0.65.0",
"rollup-plugin-babel": "^4.0.0",
"rollup-plugin-commonjs": "^9.1.0",
"rollup-plugin-json": "^3.0.0",
"rollup-plugin-node-builtins": "^2.1.2",
Expand All @@ -88,6 +88,7 @@
"rollup-plugin-replace": "^2.0.0",
"rollup-plugin-size-snapshot": "^0.6.1",
"rollup-plugin-terser": "^1.0.1",
"semver": "^5.5.1",
"which": "^1.3.0",
"yargs-parser": "^10.0.0"
},
Expand Down
83 changes: 47 additions & 36 deletions src/config/babelrc.js
Original file line number Diff line number Diff line change
@@ -1,67 +1,78 @@
const browserslist = require('browserslist');
const browserslist = require('browserslist')
const semver = require('semver')

const { ifAnyDep, parseEnv, appDirectory } = require('../utils');
const {ifAnyDep, parseEnv, appDirectory, pkg} = require('../utils')

const isTest = (process.env.BABEL_ENV || process.env.NODE_ENV) === 'test';
const isPreact = parseEnv('BUILD_PREACT', false);
const isRollup = parseEnv('BUILD_ROLLUP', false);
const isUMD = process.env.BUILD_FORMAT === 'umd';
const isWebpack = parseEnv('BUILD_WEBPACK', false);
const treeshake = parseEnv('BUILD_TREESHAKE', isRollup || isWebpack);
const alias = parseEnv('BUILD_ALIAS', isPreact ? { react: 'preact' } : null);
const isTest = (process.env.BABEL_ENV || process.env.NODE_ENV) === 'test'
const isPreact = parseEnv('BUILD_PREACT', false)
const isRollup = parseEnv('BUILD_ROLLUP', false)
const isUMD = process.env.BUILD_FORMAT === 'umd'
const isWebpack = parseEnv('BUILD_WEBPACK', false)
const treeshake = parseEnv('BUILD_TREESHAKE', isRollup || isWebpack)
const alias = parseEnv('BUILD_ALIAS', isPreact ? {react: 'preact'} : null)

/**
* use the strategy declared by browserslist to load browsers configuration.
* fallback to the default if don't found custom configuration
* @see https://github.com/browserslist/browserslist/blob/master/node.js#L139
*/
const browsersConfig = browserslist.loadConfig({ path: appDirectory }) || [
const browsersConfig = browserslist.loadConfig({path: appDirectory}) || [
'ie 10',
'ios 7',
];
]

const envTargets = isTest
? { node: 'current' }
? {node: 'current'}
: isWebpack || isRollup
? { browsers: browsersConfig }
: { node: '4.5' };
const envOptions = { modules: false, loose: true, targets: envTargets };
? {browsers: browsersConfig}
: {node: getNodeVersion(pkg)}
const envOptions = {modules: false, loose: true, targets: envTargets}

module.exports = {
module.exports = () => ({
presets: [
[require.resolve('babel-preset-env'), envOptions],
ifAnyDep(['react', 'preact'], require.resolve('babel-preset-react')),
[require.resolve('@babel/preset-env'), envOptions],
ifAnyDep(
['react', 'preact'],
[
require.resolve('@babel/preset-react'),
{pragma: isPreact ? 'React.h' : undefined},
],
),
].filter(Boolean),
plugins: [
require.resolve('babel-plugin-macros'),
isRollup ? require.resolve('babel-plugin-external-helpers') : null,
// we're actually not using JSX at all, but I'm leaving this
// in here just in case we ever do (this would be easy to miss).
alias
? [
require.resolve('babel-plugin-module-resolver'),
{ root: ['./src'], alias },
]
: null,
isPreact
? [
require.resolve('babel-plugin-transform-react-jsx'),
{ pragma: 'React.h' },
]
require.resolve('babel-plugin-module-resolver'),
{root: ['./src'], alias},
]
: null,
[
require.resolve('babel-plugin-transform-react-remove-prop-types'),
isPreact ? { removeImport: true } : { mode: 'unsafe-wrap' },
isPreact ? {removeImport: true} : {mode: 'unsafe-wrap'},
],
isUMD
? require.resolve('babel-plugin-transform-inline-environment-variables')
: null,
// TODO: use loose mode when upgrading to babel@7
require.resolve('babel-plugin-transform-class-properties'),
require.resolve('babel-plugin-transform-object-rest-spread'),
[require.resolve('@babel/plugin-proposal-class-properties'), {loose: true}],
require.resolve('babel-plugin-minify-dead-code-elimination'),
treeshake
? null
: require.resolve('babel-plugin-transform-es2015-modules-commonjs'),
: require.resolve('@babel/plugin-transform-modules-commonjs'),
].filter(Boolean),
};
})

function getNodeVersion({engines: {node: nodeVersion = '8'} = {}}) {
const oldestVersion = semver
.validRange(nodeVersion)
.replace(/[>=<|]/g, ' ')
.split(' ')
.filter(Boolean)
.sort(semver.compare)[0]
if (!oldestVersion) {
throw new Error(
`Unable to determine the oldest version in the range in your package.json at engines.node: "${nodeVersion}". Please attempt to make it less ambiguous.`,
)
}
return oldestVersion
}
10 changes: 5 additions & 5 deletions src/scripts/__tests__/__snapshots__/travis-after-success.js.snap
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`travis-after-success calls concurrently with both scripts when on travis 1`] = `npx travis-deploy-once@4`;
exports[`travis-after-success calls concurrently with both scripts when on travis 1`] = `npx travis-deploy-once@5`;

exports[`travis-after-success calls concurrently with both scripts when on travis 2`] = `concurrently --prefix [{name}] --names codecov,release --prefix-colors bgBlue.bold.reset,bgGreen.bold.reset "echo installing codecov && npx -p codecov@3 -c 'echo running codecov && codecov'" "echo installing semantic-release && npx -p semantic-release@15 -c 'echo running semantic-release && semantic-release'"`;

exports[`travis-after-success does not do autorelease script when running on travis but in a pull request 1`] = `npx travis-deploy-once@4`;
exports[`travis-after-success does not do autorelease script when running on travis but in a pull request 1`] = `npx travis-deploy-once@5`;

exports[`travis-after-success does not do autorelease script when running on travis but in a pull request 2`] = `concurrently --prefix [{name}] --names codecov --prefix-colors bgBlue.bold.reset "echo installing codecov && npx -p codecov@3 -c 'echo running codecov && codecov'"`;

exports[`travis-after-success does not do the autorelease script when the version is different 1`] = `npx travis-deploy-once@4`;
exports[`travis-after-success does not do the autorelease script when the version is different 1`] = `npx travis-deploy-once@5`;

exports[`travis-after-success does not do the autorelease script when the version is different 2`] = `concurrently --prefix [{name}] --names codecov --prefix-colors bgBlue.bold.reset "echo installing codecov && npx -p codecov@3 -c 'echo running codecov && codecov'"`;

exports[`travis-after-success does not do the codecov script when opted out 1`] = `npx travis-deploy-once@4`;
exports[`travis-after-success does not do the codecov script when opted out 1`] = `npx travis-deploy-once@5`;

exports[`travis-after-success does not do the codecov script when opted out 2`] = `concurrently --prefix [{name}] --names release --prefix-colors bgBlue.bold.reset "echo installing semantic-release && npx -p semantic-release@15 -c 'echo running semantic-release && semantic-release'"`;

exports[`travis-after-success does not do the codecov script when there is no coverage directory 1`] = `npx travis-deploy-once@4`;
exports[`travis-after-success does not do the codecov script when there is no coverage directory 1`] = `npx travis-deploy-once@5`;

exports[`travis-after-success does not do the codecov script when there is no coverage directory 2`] = `concurrently --prefix [{name}] --names release --prefix-colors bgBlue.bold.reset "echo installing semantic-release && npx -p semantic-release@15 -c 'echo running semantic-release && semantic-release'"`;

Expand Down
37 changes: 18 additions & 19 deletions src/scripts/build/babel.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
const path = require('path');
const spawn = require('cross-spawn');
const rimraf = require('rimraf');
const {
hasPkgProp, fromRoot, resolveBin, hasFile,
} = require('../../utils');
const path = require('path')
const spawn = require('cross-spawn')
const rimraf = require('rimraf')
const {hasPkgProp, fromRoot, resolveBin, hasFile} = require('../../utils')

const args = process.argv.slice(2);
const here = p => path.join(__dirname, p);
const args = process.argv.slice(2)
const here = p => path.join(__dirname, p)

const useBuiltinConfig = !args.includes('--presets') && !hasFile('.babelrc') && !hasPkgProp('babel');
const useBuiltinConfig =
!args.includes('--presets') && !hasFile('.babelrc') && !hasPkgProp('babel')
const config = useBuiltinConfig
? ['--presets', here('../../config/babelrc.js')]
: [];
: []

const ignore = args.includes('--ignore')
? []
: ['--ignore', '__tests__,__mocks__'];
: ['--ignore', '__tests__,__mocks__']

const copyFiles = args.includes('--no-copy-files') ? [] : ['--copy-files'];
const copyFiles = args.includes('--no-copy-files') ? [] : ['--copy-files']

const useSpecifiedOutDir = args.includes('--out-dir');
const outDir = useSpecifiedOutDir ? [] : ['--out-dir', 'dist'];
const useSpecifiedOutDir = args.includes('--out-dir')
const outDir = useSpecifiedOutDir ? [] : ['--out-dir', 'dist']

if (!useSpecifiedOutDir && !args.includes('--no-clean')) {
rimraf.sync(fromRoot('dist'));
rimraf.sync(fromRoot('dist'))
}

const result = spawn.sync(
resolveBin('babel-cli', { executable: 'babel' }),
resolveBin('@babel/cli', {executable: 'babel'}),
[...outDir, ...copyFiles, ...ignore, ...config, 'src'].concat(args),
{ stdio: 'inherit' },
);
{stdio: 'inherit'},
)

process.exit(result.status);
process.exit(result.status)
33 changes: 17 additions & 16 deletions src/scripts/travis-after-success.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
const spawn = require('cross-spawn');
const spawn = require('cross-spawn')
const {
resolveBin,
getConcurrentlyArgs,
hasFile,
pkg,
parseEnv,
} = require('../utils');
} = require('../utils')

console.log('installing and running travis-deploy-once');
const deployOnceResults = spawn.sync('npx', ['travis-deploy-once@4']);
console.log('installing and running travis-deploy-once')
const deployOnceResults = spawn.sync('npx', ['travis-deploy-once@5'])
if (deployOnceResults.status === 0) {
runAfterSuccessScripts();
runAfterSuccessScripts()
} else {
process.exit(deployOnceResults.status);
process.exit(deployOnceResults.status)
}

// eslint-disable-next-line complexity
function runAfterSuccessScripts() {
const autorelease = pkg.version === '0.0.0-semantically-released'
&& parseEnv('TRAVIS', false)
&& process.env.TRAVIS_BRANCH === 'master'
&& !parseEnv('TRAVIS_PULL_REQUEST', false);
const autorelease =
pkg.version === '0.0.0-semantically-released' &&
parseEnv('TRAVIS', false) &&
process.env.TRAVIS_BRANCH === 'master' &&
!parseEnv('TRAVIS_PULL_REQUEST', false)

const reportCoverage = hasFile('coverage') && !parseEnv('SKIP_CODECOV', false);
const reportCoverage = hasFile('coverage') && !parseEnv('SKIP_CODECOV', false)

if (!autorelease && !reportCoverage) {
console.log(
'No need to autorelease or report coverage. Skipping travis-after-success script...',
);
)
} else {
const result = spawn.sync(
resolveBin('concurrently'),
Expand All @@ -40,11 +41,11 @@ function runAfterSuccessScripts() {
? "echo installing semantic-release && npx -p semantic-release@15 -c 'echo running semantic-release && semantic-release'"
: null,
},
{ killOthers: false },
{killOthers: false},
),
{ stdio: 'inherit' },
);
{stdio: 'inherit'},
)

process.exit(result.status);
process.exit(result.status)
}
}

0 comments on commit 0c26a33

Please sign in to comment.