Skip to content

Commit

Permalink
feat: added addEnvironment to ConfigBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
jpina1-godaddy committed Jan 13, 2025
1 parent ee81693 commit 4e86643
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 1 deletion.
19 changes: 19 additions & 0 deletions packages/create-gasket-app/lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,25 @@ export interface ConfigBuilder<Config> {
*/
addPlugin(pluginImport: string, pluginName: string): void;

/**
* addEnvironment - Add environments to the gasket file and use the value in the plugins array
* @param {string} key - name of the environment - `local.analyze`
* @param {object} value - configuration for the environment - `{
* dynamicPlugins: [
* '@gasket/plugin-analyze',
* ]
* }`
* @example
* environments: {
* 'local.analyze': {
* dynamicPlugins: [
* '@gasket/plugin-analyze',
* ]
* }
* },
*/
addEnvironment(key:string, value: object): void;

/**
* addImport - Add a non-plugin import to the gasket file
* @param {string} importName - name of the import used as a value - `import fs...`
Expand Down
23 changes: 23 additions & 0 deletions packages/create-gasket-app/lib/scaffold/config-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,29 @@ export class ConfigBuilder {
this.add('pluginImports', { [pluginImport]: pluginName });
}

/**
* addEnvironment - Add environments to the gasket file and use the value in the plugins array
* @param {string} key - name of the environment - `local.analyze`
* @param {object} value - configuration for the environment - `{
* dynamicPlugins: [
* '@gasket/plugin-analyze',
* ]
* }`
* @example
* environments: {
* 'local.analyze': {
* dynamicPlugins: [
* '@gasket/plugin-analyze',
* ]
* }
* },
*/
addEnvironment(key, value) {
this.add(`environments`, {
[key]: value
});
}

/**
* addImport - Add a non-plugin import to the gasket file
* @param {string} importName - name of the import used as a value - `import fs...`
Expand Down
2 changes: 1 addition & 1 deletion packages/create-gasket-app/lib/scaffold/create-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export function makeCreateContext(argv = [], options = {}) {
/**
* Input context which will be appended by prompts and passed to create hooks
* @type {import('../internal').PartialCreateContext}
*/
*/
const context = new CreateContext({
destOverride: true,
cwd,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,4 +511,32 @@ describe('ConfigBuilder', () => {
expect(warnings).toHaveLength(1);
});
});


describe('.addEnvironment', () => {
let gasketConfig;
beforeEach(() => {
gasketConfig = new ConfigBuilder();
});

it('adds an environment to gasketConfig', () => {
gasketConfig.addEnvironment('test.env', { test: 'config ' });
expect(gasketConfig.fields.environments).toEqual({ 'test.env': { test: 'config ' } });
});

it('adds values to an environment in gasketConfig', () => {
gasketConfig.addEnvironment('test.env', { test: 'config ' });
gasketConfig.addEnvironment('test.env', { test2: 'config 2' });
expect(gasketConfig.fields.environments).toEqual({ 'test.env': { test: 'config ', test2: 'config 2' } });
});

it('adds multiple environments to gasketConfig', () => {
gasketConfig.addEnvironment('test.env', { test: 'config ' });
gasketConfig.addEnvironment('prod.env', { prod: 'config ' });
expect(gasketConfig.fields.environments).toEqual({
'test.env': { test: 'config ' },
'prod.env': { prod: 'config ' }
});
});
});
});

0 comments on commit 4e86643

Please sign in to comment.