Skip to content

Commit a86236d

Browse files
Merge pull request #33 from oracle/issue_24_merge_improvements
Issue 24 merge improvements - 1
2 parents b7f7ef0 + 593a912 commit a86236d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1120
-332
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ oclif.manifest.json
1414
**/wallet
1515
/generated/*
1616
!/generated/.gitkeep*
17-
/templates/**/*/package-lock.json
17+
/templates/**/*/package-lock.json
18+
/templates/node-angular/.angular/*

doc/DATABASE_CONFIG.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
## How to Change Database Configuration
2+
3+
Your database configurations are stored in the `.env` file at the root of your project.
4+
5+
1. **Open the `.env` file.**
6+
2. **Modify the values** for `DB_USER`, `DB_PASSWORD`, and `CONNECT_STRING` with your new database credentials and connection string.
7+
```plaintext
8+
DB_USER=admin
9+
DB_PASSWORD=new_password
10+
CONNECT_STRING=your_new_connection_string
11+
```
12+
3. **For Cloud Wallet users**, if you have new wallet credentials, update `WALLET_PASSWORD` and `WALLET_LOCATION` accordingly.
13+
```plaintext
14+
WALLET_PASSWORD=new_wallet_password
15+
WALLET_LOCATION=./server/utils/db/new_wallet_directory
16+
```
17+
4. **Optional**: Update `HTTPS_PROXY` and `HTTPS_PROXY_PORT` if your application uses a proxy for database connections.
18+
19+
### Updating Wallet Database Connection
20+
21+
To change your wallet database connection:
22+
23+
1. Go to `server/utils/db`.
24+
2. Delete the folder named `wallet`.
25+
3. Decompress your new wallet there and rename it to `wallet`.
26+
4. Change the password of the database user to your password.
27+
5. In `server/utils/db/wallet/tnsnames.ora` file, the first paragraph will contain the information to create your `CONNECT_STRING`:
28+
```plaintext
29+
tcps://<host>:<port>/<service_name>
30+
```
31+
32+
### Apply Changes
33+
34+
For the changes to take effect, you need to restart your application.
35+
```bash
36+
npm run dev

doc/development/TEMPLATES.md

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# How to Create Templates
2+
3+
Here’s a brief overview of creating and setting up templates for your application projects:
4+
5+
**Starting Point:** The main file is located at `src/index.ts`. The starting point of the code is within the child class `Generate`, which inherits from `Command`. This class utilizes the [oclif](https://oclif.io/docs/commands) dependency, which requires a specific structure in the file.
6+
7+
## Setting Up Your Template
8+
9+
**User Interactions:** Through prompts powered by [inquirer](https://www.npmjs.com/package/inquirer), you will define your application's name, select a project template, and specify database connection preferences, these configurations will be saved in
10+
`configObject` and sent to `generateDatabaseApp(configObject)` to kickstart the application creation process.
11+
12+
```typescript
13+
// Ask the user to choose the template.
14+
const templateChoice = template === '' ? await select(
15+
{
16+
message: 'Which template would you like to use for your project?',
17+
choices: [
18+
// Template choices...
19+
],
20+
default: 'node-vanilla'
21+
},
22+
) : template;
23+
```
24+
25+
The `templateChoice` constant allows the user to select a template. You can add your template choices here.
26+
27+
28+
```typescript
29+
// Ask the user for the database connection type.
30+
const databaseConnectionType = await select(
31+
{
32+
message: 'Which database connection type would you like to choose?',
33+
choices: [
34+
// Database connection options...
35+
],
36+
default: 'walletPath'
37+
}
38+
);
39+
```
40+
41+
The `databaseConnectionType` variable prompts the user to choose a database connection type. You can add your connection types here.
42+
43+
```typescript
44+
// This represents the config object that will hold all the user-inputted information.
45+
let configObject;
46+
47+
if (databaseConnectionType === 'basic') {
48+
// Prompt for protocol, hostname, port, and service details...
49+
50+
// Configure for basic connection type.
51+
configObject = {
52+
appName,
53+
templateChoice: path.resolve(__dirname, '..', '..', 'templates', templateChoice),
54+
connectionString: generateConnectionString(protocol, hostname, port, serviceValue)
55+
};
56+
} else {
57+
// Prompt for cloud wallet path and password...
58+
59+
// Configure for wallet connection type.
60+
configObject = {
61+
appName,
62+
templateChoice: path.resolve(__dirname, '..', '..', 'templates', templateChoice),
63+
walletPath,
64+
walletPassword,
65+
};
66+
}
67+
```
68+
69+
## Generate Your Template
70+
71+
The second main file is located at `generators/index.ts` The starting point of the code is within the anonymous class, which inherits from `Generator`. This class utilizes the [Yeoman](https://yeoman.io/authoring/) dependency, which requires a specific structure in the file.
72+
73+
When creating templates, it is important to adhere to the following directory convention:
74+
75+
- Your template should reside within a folder named `templates`.
76+
- The specific template directory should have the name that corresponds to the value stored in `templateChoice`.
77+
- Inside your folder template you must have a file named `.gitignore.template` that will genarate a `.gitignore` file in your template
78+
79+
Ensure your template includes a `package.json` file with all necessary dependencies. When project generation, `npm install` will be run automatically to install these dependencies.
80+
81+
### Copied Files
82+
83+
- The `.env.example` is a template for creating a .env file. Copy it, replace placeholders with actual values.
84+
85+
- The `.env` is used to to configure the connection to the database and other services
86+
87+
- The `utils/db/config.cjs` loads environment variables from a `.env` file and saves the database configuration in a constant
88+
89+
- The `utils/db/index.cjs` sets up a database connection pool using OracleDB with configurations from `utils/db/config.cjs`
90+
91+
- The `utils/rest-serv/connection.cjs` exports a function that verifies database connectivity with the database configuration from `utils/db/index.cjs`
92+
93+
- The `routes/connection.cjs` sets up an Express router to serve an endpoint that reports the database connection status using the function from `utils/rest-serv/connection.cjs`.
94+
95+
- The `index.cjs` serves API requests and static files, with logging and CORS support, on port 3000.
96+
97+
98+
## Adding New Files
99+
100+
- Use the `this.fs.copy()` method for straightforward file copying from your template directory to the destination project.
101+
102+
- Use the `this.fs.copyTpl()` for files needing customization or dynamic content based on user input.

src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,11 @@ export default class Generate extends Command {
236236
value: 'node-jet',
237237
description: 'This creates an empty project with Oracle JET and Oracle database connection starter code.',
238238
},
239+
{
240+
name: 'node-angular',
241+
value: 'node-angular',
242+
description: 'This creates an empty project with Angular and Oracle database connection starter code.',
243+
},
239244
{
240245
name: 'node-react-todo',
241246
value: 'node-react-todo',

templates/app/utils/db/index.cjs

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
** All rights reserved
55
** Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
66
*/
7+
8+
// app/server/utils/db/config.cjs
79
const oracledb = require('oracledb');
810
const dbConfig = require('./config.cjs');
911

@@ -12,19 +14,37 @@ oracledb.autoCommit = true;
1214

1315
class DBConnector {
1416
constructor() {
15-
this.pool = oracledb.createPool({
16-
...dbConfig,
17-
poolMax: 10,
18-
poolMin: 10
19-
});
17+
this.pool = null;
18+
}
19+
20+
async createPool() {
21+
if (!this.pool) {
22+
try {
23+
this.pool = await oracledb.createPool({
24+
...dbConfig,
25+
poolMax: 10,
26+
poolMin: 10
27+
});
28+
console.log('Connection pool created successfully.');
29+
} catch (error) {
30+
console.error('Error creating connection pool:', error);
31+
throw error;
32+
}
33+
}
2034
}
2135

22-
getConnection(options = {}) {
23-
const pool = oracledb.getPool();
24-
return pool.getConnection({
25-
...dbConfig,
26-
...options
27-
});
36+
async getConnection(options = {}) {
37+
await this.createPool();
38+
try {
39+
const connection = await this.pool.getConnection({
40+
...dbConfig,
41+
...options
42+
});
43+
return connection;
44+
} catch (error) {
45+
console.error('Error getting connection:', error);
46+
throw error;
47+
}
2848
}
2949
}
3050

templates/app/utils/rest-services/connection.cjs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
** All rights reserved
55
** Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
66
*/
7-
const db = require( '../db/index.cjs' );
7+
8+
const db = require('../db/index.cjs');
89

910
exports.getStatus = async function () {
1011
const connection = await db.getConnection();
11-
const result = await connection.execute( 'select 1 from dual' );
12+
const result = await connection.execute('select 1 from dual');
1213
await connection.close();
1314

1415
return {
1516
status: 'ok',
16-
}
17+
};
1718
};
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/* eslint-env node */
2+
3+
module.exports = {
4+
root: true,
5+
env: {
6+
browser: true,
7+
es2020: true
8+
},
9+
extends: [
10+
'eslint:recommended',
11+
],
12+
rules: {
13+
'semi': [
14+
'warn',
15+
'always'
16+
],
17+
'quotes': [
18+
'warn',
19+
'single'
20+
],
21+
'array-bracket-spacing': [
22+
'warn',
23+
'always',
24+
{
25+
singleValue: true,
26+
objectsInArrays: true,
27+
arraysInArrays: true
28+
}
29+
],
30+
'space-in-parens': [
31+
'warn',
32+
'always'
33+
],
34+
'computed-property-spacing': [
35+
'warn',
36+
'always'
37+
],
38+
'object-curly-spacing': [
39+
'warn',
40+
'always'
41+
],
42+
43+
'no-console': [
44+
'error',
45+
{
46+
allow: [
47+
'error',
48+
'warn',
49+
]
50+
}
51+
],
52+
},
53+
ignorePatterns: [
54+
'dist/**/*',
55+
'node_modules/**/*',
56+
]
57+
};
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# See http://help.github.com/ignore-files/ for more about ignoring files.
2+
3+
# Compiled output
4+
/dist
5+
/tmp
6+
/out-tsc
7+
/bazel-out
8+
/dist-ssr
9+
10+
# Node
11+
/node_modules
12+
npm-debug.log
13+
yarn-error.log
14+
yarn-debug.log*
15+
pnpm-debug.log*
16+
lerna-debug.log*
17+
18+
# IDEs and editors
19+
.idea/
20+
.project
21+
.classpath
22+
.c9/
23+
*.launch
24+
.settings/
25+
*.sublime-workspace
26+
*.local
27+
28+
# Visual Studio Code
29+
.vscode/*
30+
!.vscode/settings.json
31+
!.vscode/tasks.json
32+
!.vscode/launch.json
33+
!.vscode/extensions.json
34+
35+
# Miscellaneous
36+
/.angular/cache
37+
.sass-cache/
38+
/connect.lock
39+
/coverage
40+
/libpeerconnection.log
41+
testem.log
42+
/typings
43+
/server/utils/db/wallet
44+
45+
# System files
46+
.DS_Store
47+
Thumbs.db
48+
49+
# Logs
50+
logs
51+
*.log
52+
53+
# Environment variables
54+
/.env
55+
/.env.*
56+
!/.env.example
57+
!/.env.*.example
58+
59+
# Editor directories and files
60+
.history/*

templates/node-angular/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
> NOTE: The applications generated by this package should not be deployed using privileged database accounts. In turn, Oracle recommends for them to be deployed using the least privileged account possible.
2+
3+
# NodeAngular
4+
5+
This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 17.3.0.
6+
7+
## Development server
8+
9+
Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The application will automatically reload if you change any of the source files.
10+
11+
## Code scaffolding
12+
13+
Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`.
14+
15+
## Build
16+
17+
Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory.
18+
19+
## Running unit tests
20+
21+
Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io).
22+
23+
## Running end-to-end tests
24+
25+
Run `ng e2e` to execute the end-to-end tests via a platform of your choice. To use this command, you need to first add a package that implements end-to-end testing capabilities.
26+
27+
## Further help
28+
29+
To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page.

0 commit comments

Comments
 (0)