Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#208] Rename templates and skeleton folders #209

Merged
merged 6 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ The project has the following main files and folders:
β”œβ”€β”€ bin # the executable file for the CLI
β”‚ β”œβ”€β”€ dev # the executable file for the CLI in development mode
β”‚ └── run # the executable file for the CLI in production mode
β”œβ”€β”€ skeleton # the skeleton files for the project
β”‚ β”œβ”€β”€ addons # the skeleton files for common addons e.g. version control, CI/CD, etc.
β”‚ β”‚ β”œβ”€β”€ aws # the skeleton files for AWS modules
β”‚ β”‚ └── versionControl # the skeleton files for version control
β”‚ └── core # the skeleton folders
β”‚ β”œβ”€β”€ base # the skeleton files for the base folder
β”‚ └── shared # the skeleton files for the shared folder
β”œβ”€β”€ templates # the templates files for the project
β”‚ β”œβ”€β”€ addons # the templates files for common addons e.g. version control, CI/CD, etc.
β”‚ β”‚ β”œβ”€β”€ aws # the templates files for AWS modules
β”‚ β”‚ └── versionControl # the templates files for version control
β”‚ └── core # the templates folders
β”‚ β”œβ”€β”€ base # the templates files for the base folder
β”‚ └── shared # the templates files for the shared folder
β”œβ”€β”€ src # the source code of the CLI
β”‚ β”œβ”€β”€ commands # the commands of the CLI
β”‚ β”‚ β”œβ”€β”€ generate
Expand All @@ -78,13 +78,13 @@ The project has the following main files and folders:
```

> [!NOTE]\
> The `skeleton` folder and the `templates` folder are the two main folders that are used to generate the project files
> The `templates` folder and the `templates` folder are the two main folders that are used to generate the project files

- The `skeleton` folder contains the addon's files and folders ready to be directly copy-pasted into the generated project if the related addon has been selected. These files serve as a starting point or "skeleton" for the specific addon.
- The `templates` folder contains the addon's files and folders ready to be directly copy-pasted into the generated project if the related addon has been selected. These files serve as a starting point or "templates" for the specific addon.

- On the other hand, the `templates` folder houses the logic for determining which files need to be copied from the templates folder into the core project files. It includes instructions on what files should be formed based on the type of addon/module being added (common addons, AWS modules, or standard files).

In summary, while the `skeleton` folder provides the files and folders needed for the addon, the `templates` folder handles the dynamic copying and integration of those files within the core project structure.
In summary, while the `templates` folder provides the files and folders needed for the addon, the `templates` folder handles the dynamic copying and integration of those files within the core project structure.

### Add a new command

Expand All @@ -104,8 +104,8 @@ To add a new addon or module, follow these steps:

Inside the newly created addon/module folder, you can include the code required to generate the templates.

3. Navigate to the `skeleton` folder at the same level as the `src` folder in the project directory.
4. Add the skeleton folders/files for the addon/module that you are adding inside the corresponding folder in the `skeleton` directory.
3. Navigate to the `templates` folder at the same level as the `src` folder in the project directory.
4. Add the templates folders/files for the addon/module that you are adding inside the corresponding folder in the `templates` directory.

> [!NOTE]\
> Before adding a new addon/module, it is recommended to check the existing ones for reference.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"topics": {}
},
"scripts": {
"build": "shx rm -rf dist && tsc -b && shx cp -r skeleton dist",
"build": "shx rm -rf dist && tsc -b && shx cp -r templates dist",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"postpack": "shx rm -f oclif.manifest.json",
Expand Down
18 changes: 9 additions & 9 deletions src/commands/generate/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('Generator command', () => {
});

it('creates expected directories', () => {
const expectedDirectories = ['.github/', 'base/', 'shared/'];
const expectedDirectories = ['.github/', 'core/', 'shared/'];

expect(projectDir).toHaveDirectories(expectedDirectories);
});
Expand All @@ -41,10 +41,10 @@ describe('Generator command', () => {
const expectedFiles = [
'.gitignore',
'.tool-versions',
'base/main.tf',
'base/variables.tf',
'base/providers.tf',
'base/outputs.tf',
'core/main.tf',
'core/variables.tf',
'core/providers.tf',
'core/outputs.tf',
'shared/main.tf',
'shared/variables.tf',
'shared/providers.tf',
Expand Down Expand Up @@ -107,10 +107,10 @@ describe('Generator command', () => {
const expectedFiles = [
'.gitignore',
'.tool-versions',
'base/main.tf',
'base/variables.tf',
'base/providers.tf',
'base/outputs.tf',
'core/main.tf',
'core/variables.tf',
'core/providers.tf',
'core/outputs.tf',
];

expect(projectDir).toHaveFiles(expectedFiles);
Expand Down
10 changes: 5 additions & 5 deletions src/commands/generate/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Args, Command, ux } from '@oclif/core';
import { prompt } from 'inquirer';

import { remove } from '@/helpers/file';
import { postProcess } from '@/hooks/postProcess';
import { generateAwsTemplate } from '@/templates/addons/aws';
import { generateAwsTemplate } from '@/generators/addons/aws';
import {
applyVersionControl,
versionControlChoices,
} from '@/templates/addons/versionControl';
import { applyTerraformCore } from '@/templates/core';
} from '@/generators/addons/versionControl';
import { applyTerraformCore } from '@/generators/terraform';
import { remove } from '@/helpers/file';
import { postProcess } from '@/hooks/postProcess';

type GeneralOptions = {
projectName: string;
Expand Down
10 changes: 5 additions & 5 deletions src/commands/install/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('Install add-on command', () => {
it('creates expected directories', () => {
const expectedDirectories = [
'.github/',
'base/',
'core/',
'shared/',
'modules/',
];
Expand All @@ -53,10 +53,10 @@ describe('Install add-on command', () => {
const expectedFiles = [
'.gitignore',
'.tool-versions',
'base/main.tf',
'base/variables.tf',
'base/providers.tf',
'base/outputs.tf',
'core/main.tf',
'core/variables.tf',
'core/providers.tf',
'core/outputs.tf',
'shared/main.tf',
'shared/variables.tf',
'shared/providers.tf',
Expand Down
4 changes: 2 additions & 2 deletions src/commands/install/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Args, Flags, Command, ux } from '@oclif/core';

import { requireAwsModules } from '@/generators/addons/aws/dependencies';
import { awsModules } from '@/generators/terraform/types';
import { postProcess } from '@/hooks/postProcess';
import { requireAwsModules } from '@/templates/addons/aws/dependencies';
import { awsModules } from '@/templates/core/types';

import { GeneralOptions } from '../generate';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const AWS_DEFAULT_REGION = 'ap-southeast-1';
const AWS_SKELETON_PATH = `addons/aws`;
const AWS_TEMPLATE_PATH = `addons/aws`;
const AWS_SECURITY_GROUP_PATH = `modules/security_group`;
const AWS_SECURITY_GROUP_MAIN_PATH = `${AWS_SECURITY_GROUP_PATH}/main.tf`;
const AWS_SECURITY_GROUP_OUTPUTS_PATH = `${AWS_SECURITY_GROUP_PATH}/outputs.tf`;
const AWS_SECURITY_GROUP_VARIABLES_PATH = `${AWS_SECURITY_GROUP_PATH}/variables.tf`;

export {
AWS_DEFAULT_REGION,
AWS_SKELETON_PATH,
AWS_TEMPLATE_PATH,
AWS_SECURITY_GROUP_PATH,
AWS_SECURITY_GROUP_MAIN_PATH,
AWS_SECURITY_GROUP_OUTPUTS_PATH,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { prompt } from 'inquirer';

import { remove } from '@/helpers/file';
import { AwsOptions } from '@/templates/addons/aws';
import { AwsOptions } from '@/generators/addons/aws';
import {
applyTerraformAwsProvider,
applyAwsVpc,
} from '@/templates/addons/aws/modules';
import { applyTerraformCore } from '@/templates/core';
} from '@/generators/addons/aws/modules';
import { applyTerraformCore } from '@/generators/terraform';
import { remove } from '@/helpers/file';

import { isAwsModuleAdded, requireAwsModules } from './dependencies';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { ux } from '@oclif/core';
import { prompt } from 'inquirer';

import { containsContent, isExisting } from '@/helpers/file';
import { AwsOptions } from '@/templates/addons/aws';
import { AwsOptions } from '@/generators/addons/aws';
import {
applyAwsAlb,
applyAwsBastion,
Expand All @@ -14,14 +13,15 @@ import {
applyAwsSecurityGroup,
applyAwsSsm,
applyAwsVpc,
} from '@/templates/addons/aws/modules';
} from '@/generators/addons/aws/modules';
import { containsContent, isExisting } from '@/helpers/file';

import { INFRA_BASE_MAIN_PATH } from '../../core/constants';
import { INFRA_CORE_MAIN_PATH } from '../../terraform/constants';
import {
AwsModule,
AwsModuleName,
InstallationOptions,
} from '../../core/types';
} from '../../terraform/types';

const AWS_MODULES: Record<AwsModuleName | string, AwsModule> = {
vpc: {
Expand Down Expand Up @@ -98,7 +98,7 @@ const isAwsModuleAdded = (

const isModuleExisting = isExisting(module.path, projectName);
const isModuleAdded = containsContent(
INFRA_BASE_MAIN_PATH,
INFRA_CORE_MAIN_PATH,
module.mainContent,
projectName
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AwsOptions } from '@/generators/addons/aws';
import { applyTerraformCore } from '@/generators/terraform';
import { remove } from '@/helpers/file';
import { AwsOptions } from '@/templates/addons/aws';
import { applyTerraformCore } from '@/templates/core';

import applyAwsAlb, {
albModuleContent,
Expand Down Expand Up @@ -40,10 +40,10 @@ describe('ALB add-on', () => {

it('creates expected files', () => {
const expectedFiles = [
'base/main.tf',
'base/providers.tf',
'base/outputs.tf',
'base/variables.tf',
'core/main.tf',
'core/providers.tf',
'core/outputs.tf',
'core/variables.tf',
'modules/alb/main.tf',
'modules/alb/variables.tf',
];
Expand All @@ -52,19 +52,19 @@ describe('ALB add-on', () => {
});

it('adds ALB module to main.tf', () => {
expect(projectDir).toHaveContentInFile('base/main.tf', albModuleContent);
expect(projectDir).toHaveContentInFile('core/main.tf', albModuleContent);
});

it('adds ALB variables to variables.tf', () => {
expect(projectDir).toHaveContentInFile(
'base/variables.tf',
'core/variables.tf',
albVariablesContent
);
});

it('adds ALB outputs to outputs.tf', () => {
expect(projectDir).toHaveContentInFile(
'base/outputs.tf',
'core/outputs.tf',
albOutputsContent
);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { dedent } from 'ts-dedent';

import { appendToFile, copy } from '@/helpers/file';
import { AwsOptions } from '@/templates/addons/aws';
import { AwsOptions } from '@/generators/addons/aws';
import {
isAwsModuleAdded,
requireAwsModules,
} from '@/templates/addons/aws/dependencies';
} from '@/generators/addons/aws/dependencies';
import {
INFRA_BASE_MAIN_PATH,
INFRA_BASE_OUTPUTS_PATH,
INFRA_BASE_VARIABLES_PATH,
} from '@/templates/core/constants';
INFRA_CORE_MAIN_PATH,
INFRA_CORE_OUTPUTS_PATH,
INFRA_CORE_VARIABLES_PATH,
} from '@/generators/terraform/constants';
import { appendToFile, copy } from '@/helpers/file';

import {
AWS_SECURITY_GROUP_MAIN_PATH,
AWS_SECURITY_GROUP_OUTPUTS_PATH,
AWS_SKELETON_PATH,
AWS_TEMPLATE_PATH,
} from '../constants';

const albVariablesContent = dedent`
Expand Down Expand Up @@ -103,14 +103,14 @@ const applyAwsAlb = async (options: AwsOptions) => {
}
await requireAwsModules('alb', 'securityGroup', options);

copy(`${AWS_SKELETON_PATH}/modules/alb`, 'modules/alb', options.projectName);
appendToFile(INFRA_BASE_MAIN_PATH, albModuleContent, options.projectName);
copy(`${AWS_TEMPLATE_PATH}/modules/alb`, 'modules/alb', options.projectName);
appendToFile(INFRA_CORE_MAIN_PATH, albModuleContent, options.projectName);
appendToFile(
INFRA_BASE_VARIABLES_PATH,
INFRA_CORE_VARIABLES_PATH,
albVariablesContent,
options.projectName
);
appendToFile(INFRA_BASE_OUTPUTS_PATH, albOutputsContent, options.projectName);
appendToFile(INFRA_CORE_OUTPUTS_PATH, albOutputsContent, options.projectName);
appendToFile(
AWS_SECURITY_GROUP_MAIN_PATH,
albSGMainContent,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AwsOptions } from '@/generators/addons/aws';
import { applyTerraformCore } from '@/generators/terraform';
import { remove } from '@/helpers/file';
import { AwsOptions } from '@/templates/addons/aws';
import { applyTerraformCore } from '@/templates/core';

import applyAwsBastion, {
bastionModuleContent,
Expand Down Expand Up @@ -39,10 +39,10 @@ describe('Bastion add-on', () => {

it('creates expected files', () => {
const expectedFiles = [
'base/main.tf',
'base/providers.tf',
'base/outputs.tf',
'base/variables.tf',
'core/main.tf',
'core/providers.tf',
'core/outputs.tf',
'core/variables.tf',
'modules/bastion/main.tf',
'modules/bastion/variables.tf',
];
Expand All @@ -52,14 +52,14 @@ describe('Bastion add-on', () => {

it('adds bastion module to main.tf', () => {
expect(projectDir).toHaveContentInFile(
'base/main.tf',
'core/main.tf',
bastionModuleContent
);
});

it('adds bastion variables to variables.tf', () => {
expect(projectDir).toHaveContentInFile(
'base/variables.tf',
'core/variables.tf',
bastionVariablesContent
);
});
Expand Down
Loading