Skip to content

Commit c0cde64

Browse files
committed
feat(generate): remove use of lodash.pick
1 parent 64e4b9e commit c0cde64

5 files changed

Lines changed: 10 additions & 10 deletions

File tree

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
"chalk": "^4.1.0",
3232
"common-tags": "^1.8.0",
3333
"cosmiconfig": "^7.0.0",
34-
"lodash.pick": "^4.4.0",
3534
"staged-git-files": "^1.2.0",
3635
"tslib": "^2.1.0"
3736
},

src/commands/generate.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import fs from 'fs';
22
import path from 'path';
3-
import pick from 'lodash.pick';
43
import chalk from 'chalk';
54

65
import { cosmiconfig } from 'cosmiconfig';
76
import { Command, flags as flagTypes } from '@oclif/command';
87

9-
import { replaceIWA } from '../helpers';
8+
import { replaceIWA, getOverridesFromProcessEnv } from '../helpers';
109

1110
const explorer = cosmiconfig('iwa');
1211

@@ -48,7 +47,7 @@ class GenerateCommand extends Command {
4847
const cosmicDefaultData = cosmic.config.env.all || {};
4948
const cosmicData = cosmic.config.env[env];
5049

51-
const processOverrideData = pick(process.env, Object.keys(cosmicData));
50+
const processOverrideData = getOverridesFromProcessEnv(cosmicData);
5251
const iwaConfig = {
5352
...cosmicDefaultData,
5453
...cosmicData,

src/helpers.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,10 @@ export function hasIWAConfig(input: string) {
1616

1717
return match && match[0] !== '';
1818
}
19+
20+
export function getOverridesFromProcessEnv(cosmicData: { [key: string]: string }) {
21+
return Object.keys(cosmicData)
22+
.filter((key: string) => process.env[key])
23+
.map((key: string) => ({ [key]: process.env[key] }))
24+
.reduce((prev, curr) => ({ ...prev, ...curr }), {});
25+
}

test/commands/generate.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ describe('iwa generate', () => {
134134
const overrideValue = 'OVERRIDE_VALUE';
135135
process.env.KEY = overrideValue;
136136
await GenerateCommand.run(['./test/index.html', '-c', iwarcFile, '-e', 'production']);
137-
137+
138138
const result = fs.readFileSync(entryFilePath, {
139139
encoding: 'utf-8',
140140
});

yarn.lock

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3965,11 +3965,6 @@ lodash.kebabcase@^4.0.1:
39653965
resolved "https://registry.yarnpkg.com/lodash.kebabcase/-/lodash.kebabcase-4.1.1.tgz#8489b1cb0d29ff88195cceca448ff6d6cc295c36"
39663966
integrity sha1-hImxyw0p/4gZXM7KRI/21swpXDY=
39673967

3968-
lodash.pick@^4.4.0:
3969-
version "4.4.0"
3970-
resolved "https://registry.yarnpkg.com/lodash.pick/-/lodash.pick-4.4.0.tgz#52f05610fff9ded422611441ed1fc123a03001b3"
3971-
integrity sha1-UvBWEP/53tQiYRRB7R/BI6AwAbM=
3972-
39733968
lodash.set@^4.3.2:
39743969
version "4.3.2"
39753970
resolved "https://registry.yarnpkg.com/lodash.set/-/lodash.set-4.3.2.tgz#d8757b1da807dde24816b0d6a84bea1a76230b23"

0 commit comments

Comments
 (0)