Skip to content
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
1 change: 1 addition & 0 deletions docker/docker-compose.mongodb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ services:
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: example
LARASCRIPT_DEFAULT_CREDENTIALS: mongodb://root:example@localhost:27017/app?authSource=admin
volumes:
- mongodb_data:/data/db
networks:
Expand Down
1 change: 1 addition & 0 deletions docker/docker-compose.postgres.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ services:
POSTGRES_DB: app
POSTGRES_USER: root
POSTGRES_PASSWORD: example
LARASCRIPT_DEFAULT_CREDENTIALS: postgres://root:example@localhost:5432/app
volumes:
- postgres_data:/var/lib/postgresql/data
networks:
Expand Down
61 changes: 61 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,67 @@ For comprehensive guides and detailed explanations of Larascript Node's features
- Code generation templates
- Comprehensive testing suite (Jest)

## Quick Setup (~5 minutes)

Follow these steps to quickly set up your project:

1. **Create a new repository**:

Use the following link to create a new repository with Larascript as the template:

https://github.com/new?template_name=larascript-framework&template_owner=ben-shepherd

2. **Install dependencies**:

Once you've cloned your new repository, run the following command in your project directory:

```
yarn install
```

This will install all the necessary dependencies for your project.

3. **Start Database Containers**:

To set up your database environment, run:

```
yarn db:up
```

This command will start the necessary database containers for your project.

4. **Run the setup command (optional)**:

If you want to populate the .env file with configured settings, use:

```
yarn setup
```

This step is optional but can be helpful for quickly configuring your environment.

5. **Run database migrations**:

To set up your database schema, run:

```
yarn dev migrate:up
```

This command will apply all pending database migrations.

6. **Start developing**:

To start your development server, use:

```
yarn dev
```

This will launch your application in development mode.


## Larascript Node in Action: Real-World Code Examples

Below are some examples of how you can use Larascript Node.
Expand Down
2 changes: 1 addition & 1 deletion src/core/domains/migrations/services/MigrationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class MigrationService implements IMigrationService {
async getMigrationDetails({ group, filterByFileName }: IMigrationServiceOptions): Promise<MigrationDetail[]> {
const result: MigrationDetail[] = [];

const migrationFileNames = await this.fileService.getMigrationFileNames();
const migrationFileNames = this.fileService.getMigrationFileNames();

for(const fileName of migrationFileNames) {
const migration = await this.fileService.getImportMigrationClass(fileName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ISetupCommand } from '@src/core/domains/setup/interfaces/ISetupCommand'
import { IPackageJsonService } from '@src/core/interfaces/IPackageJsonService';
import PackageJsonService from '@src/core/services/PackageJsonService';

class SetupDockerDatabases implements IAction {
class SetupDockerDatabaseScripts implements IAction {

packageJson: IPackageJsonService;

Expand All @@ -32,25 +32,43 @@ class SetupDockerDatabases implements IAction {
*/
async updatePackageJsonUpScript(dbType: string) {
const packageJson = await this.packageJson.getJson();
let composeScriptsToInclude = '';

const appendDbType = (db: string) => `-f docker-compose.${db}.yml `;
let dockerComposeNames: string[] = [];

if(dbType === 'all') {
Object.keys(DatabaseConfig.providers).forEach((type) => {
composeScriptsToInclude += appendDbType(type);
})
dockerComposeNames = ['network', ...Object.keys(DatabaseConfig.providers)];
}
else {
composeScriptsToInclude = appendDbType(dbType);
dockerComposeNames = ['network', dbType];
}

packageJson.scripts.up = `docker-compose -f docker-compose.base.yml ${composeScriptsToInclude} up -d`;
packageJson.scripts.down = `docker-compose -f docker-compose.base.yml ${composeScriptsToInclude} down`;
const dbUp = this.buildDockerComposeString(dockerComposeNames, 'up --build -d');
const dbDown = this.buildDockerComposeString(dockerComposeNames, 'down');

packageJson.scripts['db:up'] = dbUp;
packageJson.scripts['db:down'] = dbDown;

await this.packageJson.writeFileContents(JSON.stringify(packageJson, null, 2));
}


/**
*
* @param dockerComposeNames Example: ['network', 'mongodb', 'postgres']
* @param dockerParameters Example: up --build -d
* @returns
*/
private buildDockerComposeString(dockerComposeNames: string[], dockerParameters: string) {

const baseCommand = 'cd ./docker && docker-compose {dockerComposeNames} {dockerParameters}'
let composeScriptsStr = '';

dockerComposeNames.forEach((type: string) => {
composeScriptsStr += `-f docker-compose.${type}.yml `;
})

return baseCommand.replace('{dockerComposeNames}', composeScriptsStr).replace('{dockerParameters}', dockerParameters)
}

}

export default SetupDockerDatabases
export default SetupDockerDatabaseScripts
4 changes: 2 additions & 2 deletions src/core/domains/setup/utils/buildQuestionDTOs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import CopyEnvExampleAction from "@src/core/domains/setup/actions/CopyEnvExample
import EnableExpress from "@src/core/domains/setup/actions/EnableExpress";
import GenerateJwtSecretAction from "@src/core/domains/setup/actions/GenerateJwtSecretAction";
import SetupDefaultDatabase from "@src/core/domains/setup/actions/SetupDefaultDatabase";
import SetupDockerDatabases from "@src/core/domains/setup/actions/SetupDockerDatabases";
import SetupDockerDatabaseScripts from "@src/core/domains/setup/actions/SetupDockerDatabaseScripts";
import { QuestionIDs } from "@src/core/domains/setup/consts/QuestionConsts";
import QuestionDTO from "@src/core/domains/setup/DTOs/QuestionDTO";

Expand Down Expand Up @@ -32,7 +32,7 @@ const buildQuestionDTOs = (): QuestionDTO[] => {
previewText: 'Choose Database Provider to Use',
defaultValue: 'all',
acceptedAnswers: acceptedAnswersDatabases,
actionCtors: [SetupDockerDatabases, SetupDefaultDatabase]
actionCtors: [SetupDockerDatabaseScripts, SetupDefaultDatabase]
}),
new QuestionDTO({
id: QuestionIDs.selectDefaultDb,
Expand Down
8 changes: 4 additions & 4 deletions src/core/domains/setup/utils/defaultCredentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import path from "path"
*/
const extractDefaultMongoDBCredentials = () => {
try {
const dockerComposePath = path.resolve('@src/../', 'docker-compose.mongodb.yml')
const dockerComposePath = path.resolve('@src/../', 'docker/docker-compose.mongodb.yml')
const contents = fs.readFileSync(dockerComposePath, 'utf8')

const pattern = /MONGODB_URI=(.+)/
const pattern = /LARASCRIPT_DEFAULT_CREDENTIALS:\s?(.+)/
const match = pattern.exec(contents)

if (match?.[1]) {
Expand All @@ -29,10 +29,10 @@ const extractDefaultMongoDBCredentials = () => {
*/
const extractDefaultPostgresCredentials = () => {
try {
const dockerComposePath = path.resolve('@src/../', 'docker-compose.postgres.yml')
const dockerComposePath = path.resolve('@src/../', 'docker/docker-compose.postgres.yml')
const contents = fs.readFileSync(dockerComposePath, 'utf8')

const pattern = /POSTGRES_URI=(.+)/
const pattern = /LARASCRIPT_DEFAULT_CREDENTIALS:\s?(.+)/
const match = pattern.exec(contents)

if (match?.[1]) {
Expand Down