Skip to content
This repository has been archived by the owner on Apr 21, 2024. It is now read-only.

(@mikojs/configs) Add lerna command with flow #514

Merged
merged 11 commits into from
Jan 16, 2020
15 changes: 9 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ defaults: &defaults

restore-cache: &restore-cache
keys:
- dependencies-{{ checksum "yarn.lock" }}-949d2d61
- dependencies-949d2d61
- dependencies-{{ checksum "yarn.lock" }}-f54ec6eb
- dependencies-f54ec6eb

save-cache: &save-cache
paths:
- node_modules
- flow-typed/npm
- ~/.flow-typed
key: dependencies-{{ checksum "yarn.lock" }}-949d2d61
key: dependencies-{{ checksum "yarn.lock" }}-f54ec6eb

install: &install
name: Install packages
Expand All @@ -34,11 +34,14 @@ jobs:
- save_cache: *save-cache

- run:
name: Check code style
name: Flow
command: |
yarn flow-typed:all
yarn configs lint .
yarn flow
yarn configs exec lerna:flow

- run:
name: Check code style
command: yarn configs lint .

- run:
name: Test
Expand Down
10 changes: 1 addition & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ WATCH=""
install-all:
@yarn install
@yarn lerna bootstrap
@yarn patch-package
@make babel-all

flow-typed-all:
Expand All @@ -23,13 +22,6 @@ else
@$(call babel-build, $(WATCH), --since $(BRANCH))
endif

flow:
ifeq ($(shell printenv CI), true)
@yarn lerna exec "flow --quiet && flow stop" --stream --concurrency 1
else
@yarn lerna exec "flow --quiet" --stream --concurrency 1 --since $(BRANCH)
endif

release:
@yarn lerna-changelog && \
echo "\nContinue with any keyword or exit with 'ctrl + c'..." && \
Expand All @@ -41,7 +33,7 @@ release:
@open https://github.com/mikojs/core/releases

clean:
@yarn lerna exec "rm -rf lib flow-typed/npm" \
@yarn lerna exec "rm -rf lib flow-typed/npm"
@yarn lerna exec "rm -rf .flowconfig" \
--ignore @mikojs/eslint-config-base \
--ignore @mikojs/koa-graphql \
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"scripts": {
"clean": "make clean",
"dev": "make babel-changed WATCH=-w",
"flow": "make flow",
"flow-typed:all": "make flow-typed-all",
"install:all": "make install-all",
"prod": "NODE_ENV=production make babel-all",
Expand Down Expand Up @@ -35,7 +34,6 @@
"lerna": "^3.20.2",
"lerna-changelog": "^1.0.0",
"lint-staged": "^9.5.0",
"patch-package": "^6.2.0",
"prettier": "^1.19.1",
"prettier-package-json": "^2.1.3",
"react": "^16.12.0",
Expand All @@ -49,7 +47,7 @@
},
"husky": {
"hooks": {
"pre-commit": "make babel-changed && configs lint-staged && yarn flow",
"pre-commit": "make babel-changed && configs lint-staged && configs exec lerna:flow --changed",
"post-merge": "make babel-all",
"post-checkout": "make babel-changed BRANCH=master"
}
Expand Down
3 changes: 2 additions & 1 deletion packages/configs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
},
"devDependencies": {
"flow-bin": "^0.115.0",
"flow-typed": "^2.6.2"
"flow-typed": "^2.6.2",
"git-branch": "^2.0.1"
},
"keywords": ["configs", "mikojs"],
"publishConfig": {
Expand Down
82 changes: 82 additions & 0 deletions packages/configs/src/__tests__/withLerna.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// @flow

import withLerna from '../withLerna';

describe('with lerna', () => {
describe.each(Object.keys(withLerna).map((key: string) => [key]))(
'%s',
(configName: string | 'exec' | 'babel' | 'server') => {
test.each(Object.keys(withLerna[configName]).map((key: string) => [key]))(
'%s',
(eventName: string) => {
switch (eventName) {
case 'config':
if (configName === 'exec') {
delete process.env.CI;
expect(withLerna[(configName: 'exec')].config({})).toEqual({
lerna: {
flow: [
'lerna',
'exec',
'"flow --quiet"',
'--stream',
'--concurrency',
'1',
],
},
});
}
break;

case 'run':
if (
configName === 'exec' ||
configName === 'babel' ||
configName === 'server'
)
expect(withLerna[configName].run([])).toEqual(
configName === 'exec'
? []
: ['--config-file', '../../babel.config.js'],
);
break;

default:
expect(withLerna[configName][eventName]([])).toEqual(
configName === 'exec' ? ['git-branch'] : ['-W'],
);
break;
}
},
);
},
);

describe('exec', () => {
test.each`
isChanged
${true}
${false}
`(
'run with --changed = $isChanged',
({ isChanged }: {| isChanged: boolean |}) => {
expect(
withLerna.exec.run([!isChanged ? '--test' : '--changed'])[0],
).toBe(!isChanged ? '--test' : '--since');
},
);

test.each`
isCi
${true}
${false}
`('config with ci = $isCi', ({ isCi }: {| isCi: boolean |}) => {
if (isCi) process.env.CI = 'true';
else delete process.env.CI;

expect(withLerna.exec.config({}).lerna.flow[2]).toBe(
isCi ? '"flow --quiet && flow stop"' : '"flow --quiet"',
);
});
});
});
5 changes: 5 additions & 0 deletions packages/configs/src/utils/__tests__/generateFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ describe('generate files', () => {
cliFunc: {
alias: emptyFunction.thatReturnsArgument,
},
jest: {
configsFiles: {
prettier: false,
},
},
},
filepath: path.resolve(process.cwd(), './.catrc.js'),
});
Expand Down
100 changes: 74 additions & 26 deletions packages/configs/src/withLerna.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,80 @@
// @flow

import { type configsType, type objConfigType } from './types';
import configs from './configs';

export default Object.keys(configs).reduce(
(result: configsType, key: $Keys<typeof configs>): configsType => {
const newConfig: objConfigType = {
install: (install: $ReadOnlyArray<string>) => [...install, '-W'],
};
import gitBranch from 'git-branch';

switch (key) {
case 'babel':
case 'server':
newConfig.run = (argv: $ReadOnlyArray<string>) => [
...argv,
'--config-file',
'../../babel.config.js',
];
break;

default:
break;
}
import configs from './configs';

return {
...result,
[key]: newConfig,
};
const newConfigs = {
babel: {
install: (install: $ReadOnlyArray<string>): $ReadOnlyArray<string> => [
...install,
'-W',
],
run: (argv: $ReadOnlyArray<string>): $ReadOnlyArray<string> => [
...argv,
'--config-file',
'../../babel.config.js',
],
},
{},
server: {
run: (argv: $ReadOnlyArray<string>): $ReadOnlyArray<string> => [
...argv,
'--config-file',
'../../babel.config.js',
],
},
exec: {
install: (install: $ReadOnlyArray<string>): $ReadOnlyArray<string> => [
...install,
'git-branch',
],
run: (argv: $ReadOnlyArray<string>): $ReadOnlyArray<string> =>
argv.reduce(
(newArgv: $ReadOnlyArray<string>, argvStr: string) => [
...newArgv,
...(argvStr === '--changed'
? ['--since', gitBranch.sync().replace(/Branch: /, '')]
: [argvStr]),
],
[],
),
config: (config: {}): {
lerna: {
flow: $ReadOnlyArray<string>,
},
} => ({
...config,
lerna: {
flow: [
'lerna',
'exec',
`"flow --quiet${process.env.CI ? ' && flow stop' : ''}"`,
'--stream',
'--concurrency',
'1',
],
},
}),
},
};

export default Object.keys(configs).reduce(
(
result: {
[string]: {
install: (install: $ReadOnlyArray<string>) => $ReadOnlyArray<string>,
},
...typeof newConfigs,
},
key: $Keys<typeof configs>,
) =>
Object.keys(result).includes(key)
? result
: {
...result,
[key]: {
install: (install: $ReadOnlyArray<string>) => [...install, '-W'],
},
},
newConfigs,
);
14 changes: 0 additions & 14 deletions patches/get-port+5.1.0.patch

This file was deleted.