Skip to content

Commit

Permalink
update init script
Browse files Browse the repository at this point in the history
  • Loading branch information
realtux committed Jun 14, 2024
1 parent 01b505d commit 21e5562
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 12 deletions.
1 change: 0 additions & 1 deletion .npmignore

This file was deleted.

80 changes: 78 additions & 2 deletions bin/scripts/init.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,79 @@
export default () => {
console.log('initing');
import fs from 'node:fs/promises';
import { glob } from 'glob';
import { fileURLToPath } from 'node:url';
import path from 'node:path';
import { execSync } from 'node:child_process';

export default async () => {
console.log('starting initialization...');

let initiator = fileURLToPath(import.meta.url);
let root_dir = path.resolve(path.dirname(initiator), '../..');

let project_path = process.argv[3] || '';

if (project_path) {
project_path = './' + project_path
.replace(/^[\/\.]+/, '')
.replace(/\/+$/, '');
} else {
project_path = '.';
}

await fs.mkdir(project_path, { recursive: true });

let files = await glob(`${root_dir}/var/template/*`, { dot: true });
let ignore = ['node_modules', '.env'];

console.log('creating project files...');

for (const file of files) {
const stat = await fs.stat(file);
const is_dir = stat.isDirectory();
const filename = file.split('/').slice(-1)[0];

if (ignore.includes(filename)) {
continue;
}

if (is_dir) {
await fs.cp(
file,
`${project_path}/${filename}`,
{
recursive: true
}
);
} else {
await fs.copyFile(file, `${project_path}/${filename}`);
}
}

await fs.copyFile(`${project_path}/.env.sample`, `${project_path}/.env`)

// update package.json
let package_json = JSON.parse(await fs.readFile(`${project_path}/package.json`));

// ensure user gets latest version
package_json.dependencies['@exajs/core'] = 'latest';

// drop the extra watch, this is for dev only
package_json.scripts.watch = package_json.scripts.watch.replace(' --watch ../..', '');

await fs.writeFile(`${project_path}/package.json`, JSON.stringify(package_json, null, 4));

console.log('running npm install...');

// npm install
process.chdir(project_path);
execSync('npm i', { stdio: 'inherit' });

console.log('creating a new git repo...');

// git init
execSync('git init', { stdio: 'inherit' });

// done
console.log('-------');
console.log('installation complete, run `npm run watch` to start your application');
}
16 changes: 9 additions & 7 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { glob } from 'glob';

import { fileURLToPath } from 'node:url';
import { DateTime } from 'luxon';
import { dirname } from 'node:path';

export default new class {

Expand All @@ -25,21 +26,22 @@ export default new class {
async start(file) {
const is_console = process.argv[2] === 'console';

console.time('startup took');
// console.time('startup took');


console.log();
console.log(`${chalk.yellow('exa.js')} by tux - v0.0.1`);
console.log('---------------------------');
console.log(`ts: ${DateTime.now()}`)
console.log(`${chalk.yellow('exa.js')} by tux - v0.0.4`);
console.log('-----------------------------');
console.log(`${chalk.green(DateTime.now().toISO())}`);
console.log('-----------------------------');

try {
/**
* set up the project root directory, necessary to discover and
* initiate various userland code
*/
let initiating_file = fileURLToPath(new URL(file));
let root_dir = initiating_file.split('/').slice(0, -1).join('/');
let initiating_file = fileURLToPath(file);
let root_dir = dirname(initiating_file);

await init_config(root_dir);

Expand Down Expand Up @@ -88,7 +90,7 @@ export default new class {
console.log(e.stack);
}

console.timeEnd('startup took');
// console.timeEnd('startup took');
}

}
10 changes: 8 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## exa.js by [tux](https://github.com/realtux)
exa.js is a minimal node.js backend framework that has a strong focus on simplicity, modularity, and convention over configuration.
exa.js is a minimal node.js backend framework that has a strong focus on simplicity, modularity, and convention over configuration.

#### motivation
as if the javascript ecosystem needs another framework... i get it, but please know that this project is the culmination of ~10 years of professional development trying to understand what i/people really need in a framework. this project is the consolidated and cleaned up version of about 30 projects worth of boilerplate patchwork that has been unevenly iterated on and used in some form during this time. i'm certain you'll find use for it, and i certainly will.

---

Expand All @@ -8,8 +11,11 @@ exa.js is a minimal node.js backend framework that has a strong focus on simplic
# initialize
npx @exajs/core init

# start
# start dev with auto reload
npm run watch

# start normal
npm start
```
this will create the exa.js template project structure in the current directory. a brief description of this template is below.

Expand Down

0 comments on commit 21e5562

Please sign in to comment.