Skip to content
This repository has been archived by the owner on Dec 18, 2021. It is now read-only.

Commit

Permalink
Merge pull request #530 from form8ion/alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
travi authored May 1, 2021
2 parents 66bde0e + 3bfd8c8 commit 6e56ba9
Show file tree
Hide file tree
Showing 19 changed files with 141 additions and 157 deletions.
1 change: 1 addition & 0 deletions .husky/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx --no-install commitlint --edit $1
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm test
1 change: 0 additions & 1 deletion .huskyrc.json

This file was deleted.

14 changes: 11 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
"test:integration:base": "DEBUG=any cucumber-js test/integration --profile base",
"test:integration:debug": "NODE_OPTIONS=--enable-source-maps DEBUG=test run-s test:integration",
"test:integration:wip": "run-s 'test:integration:base -- --profile wip'",
"test:integration:focus": "run-s 'test:integration:base -- --profile focus'"
"test:integration:focus": "run-s 'test:integration:base -- --profile focus'",
"prepare": "husky install"
},
"devDependencies": {
"@babel/register": "7.13.16",
Expand Down Expand Up @@ -82,6 +83,7 @@
},
"dependencies": {
"@form8ion/core": "^1.3.1",
"@form8ion/eslint": "1.0.0-alpha.4",
"@form8ion/husky": "1.2.0",
"@form8ion/javascript-core": "^2.9.2",
"@travi/cli-messages": "^1.0.4",
Expand Down
1 change: 0 additions & 1 deletion src/eslint/index.js

This file was deleted.

39 changes: 0 additions & 39 deletions src/eslint/lift-test.js

This file was deleted.

24 changes: 0 additions & 24 deletions src/eslint/lift.js

This file was deleted.

23 changes: 3 additions & 20 deletions src/lift-test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as huskyLifter from '@form8ion/husky';
import * as eslint from '@form8ion/eslint';
import deepmerge from 'deepmerge';
import sinon from 'sinon';
import any from '@travi/any';
import {assert} from 'chai';
import * as packageLifter from './package';
import * as eslintLifter from './eslint/lift';
import * as packageManagerResolver from './package-manager';
import lift from './lift';

Expand Down Expand Up @@ -34,7 +34,7 @@ suite('lift', () => {
sandbox = sinon.createSandbox();

sandbox.stub(packageLifter, 'default');
sandbox.stub(eslintLifter, 'default');
sandbox.stub(eslint, 'lift');
sandbox.stub(packageManagerResolver, 'default');
sandbox.stub(huskyLifter, 'lift');

Expand All @@ -53,7 +53,7 @@ suite('lift', () => {
nextSteps: eslintNextSteps,
devDependencies: eslintDevDependencies
};
eslintLifter.default.withArgs({configs: eslintConfigs, scope, projectRoot}).resolves(eslintLiftResults);
eslint.lift.withArgs({configs: eslintConfigs, projectRoot}).resolves(eslintLiftResults);

const liftResults = await lift({projectRoot, results, configs: {eslint: {scope}}});

Expand All @@ -66,21 +66,4 @@ suite('lift', () => {
)
);
});

test('that eslint-configs are not processed if configs are not provided', async () => {
const liftResults = await lift({projectRoot, results});

assert.deepEqual(liftResults, {});

assert.calledWith(
packageLifter.default,
deepmerge({projectRoot, scripts, tags, dependencies, devDependencies, packageManager}, huskyLiftResults)
);
});

test('that eslint-configs are not processed if config for eslint is not provided', async () => {
const liftResults = await lift({projectRoot, results, configs: any.simpleObject()});

assert.deepEqual(liftResults, {});
});
});
51 changes: 16 additions & 35 deletions src/lift.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,37 @@
import {info, warn} from '@travi/cli-messages';
import {info} from '@travi/cli-messages';
import deepmerge from 'deepmerge';
import {lift as liftHusky} from '@form8ion/husky';
import {lift as liftEslint} from '@form8ion/eslint';
import liftPackage from './package';
import liftEslint from './eslint';
import resolvePackageManager from './package-manager';

function configIsProvidedForEslint(configs) {
return configs && configs.eslint;
}

export default async function ({
projectRoot,
configs,
results: {scripts, tags, eslintConfigs, dependencies, devDependencies, packageManager: manager}
}) {
info('Lifting JavaScript-specific details');

const packageManager = await resolvePackageManager({projectRoot, packageManager: manager});
const huskyResults = await liftHusky({projectRoot, packageManager});

if (configIsProvidedForEslint(configs)) {
const {
nextSteps,
devDependencies: eslintDevDependencies
} = await liftEslint({configs: eslintConfigs, scope: configs.eslint.scope, projectRoot});

await liftPackage(
deepmerge(
{
projectRoot,
scripts,
tags,
dependencies,
devDependencies,
packageManager,
eslintDevDependencies
},
huskyResults
)
);

return {nextSteps};
}

if (eslintConfigs) warn('Config for ESLint not provided. Skipping ESLint configuration');
const {
nextSteps,
devDependencies: eslintDevDependencies
} = await liftEslint({projectRoot, configs: eslintConfigs});

await liftPackage(
deepmerge(
{projectRoot, scripts, tags, dependencies, devDependencies, packageManager},
{
projectRoot,
scripts,
tags,
dependencies,
devDependencies,
packageManager,
eslintDevDependencies
},
huskyResults
)
);

return {};
return {nextSteps};
}
28 changes: 24 additions & 4 deletions test/integration/features/eslint-configs.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,34 @@ Feature: ESLint Configs

Scenario: No existing config
Given no existing eslint config file is present
And "npm" is the package manager
And husky is not installed
And an "npm" lockfile exists
And husky v5 is installed
When the scaffolder results are processed
Then no eslint config file exists

Scenario: existing yaml config
Given an existing eslint config file is present
And "npm" is the package manager
And husky is not installed
And an "npm" lockfile exists
And husky v5 is installed
When the scaffolder results are processed
Then the yaml eslint config file contains the expected config

Scenario: existing yaml config and shareable configs to add
Given an existing eslint config file is present
And an "npm" lockfile exists
And husky v5 is installed
And additional shareable configs are provided
When the scaffolder results are processed
Then the yaml eslint config file contains the expected config
And the next-steps are provided
And dependencies are defined for the additional configs

Scenario: existing yaml config and complex shareable configs to add
Given an existing eslint config file is present
And an "npm" lockfile exists
And husky v5 is installed
And complex additional shareable configs are provided
When the scaffolder results are processed
Then the yaml eslint config file contains the expected config
And the next-steps are provided
And dependencies are defined for the additional configs
8 changes: 4 additions & 4 deletions test/integration/features/husky.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ Feature: Husky

Scenario: Husky v5 installed, v4 config
Given husky v5 is installed
And "npm" is the package manager
And an "npm" lockfile exists
And husky config is in v4 format
When the scaffolder results are processed
Then husky is configured for "npm"
And the v4 config is removed

Scenario: Husky v5 installed, v4 config
Given husky v5 is installed
And "yarn" is the package manager
And an "yarn" lockfile exists
And husky config is in v4 format
When the scaffolder results are processed
Then husky is configured for "yarn"
Expand All @@ -34,14 +34,14 @@ Feature: Husky

Scenario: Husky v5 installed, v5 config
Given husky v5 is installed
And "npm" is the package manager
And an "npm" lockfile exists
And husky config is in v5 format
When the scaffolder results are processed
Then the next-steps do not include a warning about the husky config

Scenario: Husky v4 installed, v4 config
Given husky v4 is installed
And "npm" is the package manager
And an "npm" lockfile exists
And husky config is in v4 format
When the scaffolder results are processed
Then the next-steps do not include a warning about the husky config
4 changes: 2 additions & 2 deletions test/integration/features/package-properties.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ Feature: Package Properties

Scenario: Tags results when no existing keywords
Given there are no existing keywords
And "npm" is the package manager
And an "npm" lockfile exists
And tags are provided in the results
And husky is not installed
When the scaffolder results are processed
Then keywords from the results exist

Scenario: Tags results when some keywords exist
Given there are existing keywords
And "npm" is the package manager
And an "npm" lockfile exists
And tags are provided in the results
And husky is not installed
When the scaffolder results are processed
Expand Down
6 changes: 3 additions & 3 deletions test/integration/features/scripts.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@ Feature: Scripts

Scenario: No Additional Scripts from Results
Given no additional scripts are included in the results
And "npm" is the package manager
And an "npm" lockfile exists
And husky is not installed
When the scaffolder results are processed
Then the existing scripts still exist
And no extra scripts were added

Scenario: Additional Scripts Are Present in Results
Given additional scripts are included in the results
And "npm" is the package manager
And an "npm" lockfile exists
And husky is not installed
When the scaffolder results are processed
Then the existing scripts still exist
And the additional scripts exist

Scenario: Duplicate Scripts Are Present in Results
Given additional scripts that duplicate existing scripts are included in the results
And "npm" is the package manager
And an "npm" lockfile exists
And husky is not installed
When the scaffolder results are processed
Then the additional scripts exist
Loading

0 comments on commit 6e56ba9

Please sign in to comment.