mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 23:00:34 +00:00
feat(server): move all cli commands codebase to be TS based.
This commit is contained in:
@@ -1,51 +0,0 @@
|
|||||||
const Knex = require('knex');
|
|
||||||
const { knexSnakeCaseMappers } = require('objection');
|
|
||||||
const color = require('colorette');
|
|
||||||
const config = require('./config');
|
|
||||||
|
|
||||||
function initSystemKnex() {
|
|
||||||
return Knex({
|
|
||||||
client: config.system.db_client,
|
|
||||||
connection: {
|
|
||||||
host: config.system.db_host,
|
|
||||||
user: config.system.db_user,
|
|
||||||
password: config.system.db_password,
|
|
||||||
database: config.system.db_name,
|
|
||||||
charset: 'utf8',
|
|
||||||
},
|
|
||||||
migrations: {
|
|
||||||
directory: config.system.migrations_dir,
|
|
||||||
},
|
|
||||||
seeds: {
|
|
||||||
directory: config.system.seeds_dir,
|
|
||||||
},
|
|
||||||
pool: { min: 0, max: 7 },
|
|
||||||
...knexSnakeCaseMappers({ upperCase: true }),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function exit(text) {
|
|
||||||
if (text instanceof Error) {
|
|
||||||
console.error(
|
|
||||||
color.red(`${text.detail ? `${text.detail}\n` : ''}${text.stack}`)
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
console.error(color.red(text));
|
|
||||||
}
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
function success(text) {
|
|
||||||
console.log(text);
|
|
||||||
process.exit(0);
|
|
||||||
}
|
|
||||||
function log(text) {
|
|
||||||
console.log(text);
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
log,
|
|
||||||
success,
|
|
||||||
exit,
|
|
||||||
initSystemKnex,
|
|
||||||
};
|
|
||||||
@@ -8,7 +8,9 @@
|
|||||||
"clear": "rimraf build",
|
"clear": "rimraf build",
|
||||||
"dev": "cross-env NODE_ENV=development webpack --config scripts/webpack.config.js",
|
"dev": "cross-env NODE_ENV=development webpack --config scripts/webpack.config.js",
|
||||||
"build:resources": "gulp --gulpfile=scripts/gulpfile.js styles styles-rtl",
|
"build:resources": "gulp --gulpfile=scripts/gulpfile.js styles styles-rtl",
|
||||||
"build": "cross-env NODE_ENV=production webpack --config scripts/webpack.config.js",
|
"build:app": "cross-env NODE_ENV=production webpack --config scripts/webpack.config.js",
|
||||||
|
"build:commands": "cross-env NODE_ENV=production webpack --config scripts/webpack.cli.js",
|
||||||
|
"build": "npm-run-all build:*",
|
||||||
"lint:fix": "eslint --fix ./**/*.ts"
|
"lint:fix": "eslint --fix ./**/*.ts"
|
||||||
},
|
},
|
||||||
"author": "Ahmed Bouhuolia, <a.bouhuolia@gmail.com>",
|
"author": "Ahmed Bouhuolia, <a.bouhuolia@gmail.com>",
|
||||||
|
|||||||
11
packages/server/scripts/webpack.cli.js
Normal file
11
packages/server/scripts/webpack.cli.js
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
const { getCommonWebpackOptions } = require('./webpack.common');
|
||||||
|
|
||||||
|
const inputEntry = './src/commands/index.ts';
|
||||||
|
const outputDir = '../build';
|
||||||
|
const outputFilename = 'commands.js';
|
||||||
|
|
||||||
|
module.exports = getCommonWebpackOptions({
|
||||||
|
inputEntry,
|
||||||
|
outputDir,
|
||||||
|
outputFilename,
|
||||||
|
});
|
||||||
76
packages/server/scripts/webpack.common.js
Normal file
76
packages/server/scripts/webpack.common.js
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
const path = require('path');
|
||||||
|
const { NormalModuleReplacementPlugin } = require('webpack');
|
||||||
|
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
|
||||||
|
const { RunScriptWebpackPlugin } = require('run-script-webpack-plugin');
|
||||||
|
const nodeExternals = require('webpack-node-externals');
|
||||||
|
const ProgressBarPlugin = require('progress-bar-webpack-plugin');
|
||||||
|
|
||||||
|
const isDev = process.env.NODE_ENV === 'development';
|
||||||
|
|
||||||
|
exports.getCommonWebpackOptions = ({
|
||||||
|
inputEntry,
|
||||||
|
outputDir,
|
||||||
|
outputFilename,
|
||||||
|
}) => {
|
||||||
|
const webpackOptions = {
|
||||||
|
entry: ['regenerator-runtime/runtime', inputEntry],
|
||||||
|
target: 'node',
|
||||||
|
mode: isDev ? 'development' : 'production',
|
||||||
|
watch: isDev,
|
||||||
|
watchOptions: {
|
||||||
|
aggregateTimeout: 200,
|
||||||
|
poll: 1000,
|
||||||
|
},
|
||||||
|
output: {
|
||||||
|
path: path.resolve(__dirname, outputDir),
|
||||||
|
filename: outputFilename,
|
||||||
|
},
|
||||||
|
resolve: {
|
||||||
|
extensions: ['.ts', '.tsx', '.js'],
|
||||||
|
extensionAlias: {
|
||||||
|
'.ts': ['.js', '.ts'],
|
||||||
|
'.cts': ['.cjs', '.cts'],
|
||||||
|
'.mts': ['.mjs', '.mts'],
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
new TsconfigPathsPlugin({
|
||||||
|
configFile: './tsconfig.json',
|
||||||
|
extensions: ['.ts', '.tsx', '.js'],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
// Ignore knex dynamic required dialects that we don't use
|
||||||
|
new NormalModuleReplacementPlugin(
|
||||||
|
/m[sy]sql2?|oracle(db)?|sqlite3|pg-(native|query)/,
|
||||||
|
'noop2'
|
||||||
|
),
|
||||||
|
new ProgressBarPlugin(),
|
||||||
|
],
|
||||||
|
externals: [nodeExternals(), 'aws-sdk', 'prettier'],
|
||||||
|
module: {
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
test: /\.([cm]?ts|tsx|js)$/,
|
||||||
|
use: [
|
||||||
|
{
|
||||||
|
loader: 'ts-loader',
|
||||||
|
options: {
|
||||||
|
transpileOnly: true,
|
||||||
|
configFile: 'tsconfig.json',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
exclude: /(node_modules)/,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
if (isDev) {
|
||||||
|
webpackOptions.plugins.push(
|
||||||
|
new RunScriptWebpackPlugin({ name: outputFilename })
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return webpackOptions;
|
||||||
|
};
|
||||||
@@ -1,74 +1,11 @@
|
|||||||
const path = require('path');
|
const { getCommonWebpackOptions } = require('./webpack.common');
|
||||||
const { NormalModuleReplacementPlugin } = require('webpack');
|
|
||||||
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
|
|
||||||
const { RunScriptWebpackPlugin } = require('run-script-webpack-plugin');
|
|
||||||
const nodeExternals = require('webpack-node-externals');
|
|
||||||
const ProgressBarPlugin = require('progress-bar-webpack-plugin');
|
|
||||||
|
|
||||||
const isDev = process.env.NODE_ENV === 'development';
|
const inputEntry = './src/server.ts';
|
||||||
const outputDir = '../build';
|
const outputDir = '../build';
|
||||||
const outputFilename = 'index.js';
|
const outputFilename = 'index.js';
|
||||||
const inputEntry = './src/server.ts';
|
|
||||||
|
|
||||||
const webpackOptions = {
|
module.exports = getCommonWebpackOptions({
|
||||||
entry: ['regenerator-runtime/runtime', inputEntry],
|
inputEntry,
|
||||||
target: 'node',
|
outputDir,
|
||||||
mode: isDev ? 'development' : 'production',
|
outputFilename,
|
||||||
watch: isDev,
|
});
|
||||||
watchOptions: {
|
|
||||||
aggregateTimeout: 200,
|
|
||||||
poll: 1000,
|
|
||||||
},
|
|
||||||
output: {
|
|
||||||
path: path.resolve(__dirname, outputDir),
|
|
||||||
filename: outputFilename,
|
|
||||||
},
|
|
||||||
resolve: {
|
|
||||||
extensions: ['.ts', '.tsx', '.js'],
|
|
||||||
extensionAlias: {
|
|
||||||
'.ts': ['.js', '.ts'],
|
|
||||||
'.cts': ['.cjs', '.cts'],
|
|
||||||
'.mts': ['.mjs', '.mts'],
|
|
||||||
},
|
|
||||||
plugins: [
|
|
||||||
new TsconfigPathsPlugin({
|
|
||||||
configFile: './tsconfig.json',
|
|
||||||
extensions: ['.ts', '.tsx', '.js'],
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
},
|
|
||||||
plugins: [
|
|
||||||
// Ignore knex dynamic required dialects that we don't use
|
|
||||||
new NormalModuleReplacementPlugin(
|
|
||||||
/m[sy]sql2?|oracle(db)?|sqlite3|pg-(native|query)/,
|
|
||||||
'noop2'
|
|
||||||
),
|
|
||||||
new ProgressBarPlugin(),
|
|
||||||
],
|
|
||||||
externals: [nodeExternals(), 'aws-sdk', 'prettier'],
|
|
||||||
module: {
|
|
||||||
rules: [
|
|
||||||
{
|
|
||||||
test: /\.([cm]?ts|tsx|js)$/,
|
|
||||||
use: [
|
|
||||||
{
|
|
||||||
loader: 'ts-loader',
|
|
||||||
options: {
|
|
||||||
transpileOnly: true,
|
|
||||||
configFile: 'tsconfig.json',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
exclude: /(node_modules)/,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
if (isDev) {
|
|
||||||
webpackOptions.plugins.push(
|
|
||||||
new RunScriptWebpackPlugin({ name: outputFilename })
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = webpackOptions;
|
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
const commander = require('commander');
|
import commander from 'commander';
|
||||||
const color = require('colorette');
|
import color from 'colorette';
|
||||||
const argv = require('getopts');
|
import argv from 'getopts';
|
||||||
const Knex = require('knex');
|
import Knex from 'knex';
|
||||||
const { knexSnakeCaseMappers } = require('objection');
|
import { knexSnakeCaseMappers } from 'objection';
|
||||||
const config = require('../src/config');
|
import config from '../config';
|
||||||
|
|
||||||
function initSystemKnex() {
|
function initSystemKnex() {
|
||||||
return Knex({
|
return Knex({
|
||||||
@@ -279,4 +279,4 @@ commander
|
|||||||
exit(error);
|
exit(error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
commander.parse();
|
|
||||||
4
packages/server/src/commands/index.ts
Normal file
4
packages/server/src/commands/index.ts
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
import commander from 'commander';
|
||||||
|
import './bigcapital';
|
||||||
|
|
||||||
|
commander.parse();
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
const dotenv = require('dotenv');
|
import dotenv from 'dotenv';
|
||||||
|
|
||||||
// Set the NODE_ENV to 'development' by default
|
// Set the NODE_ENV to 'development' by default
|
||||||
// process.env.NODE_ENV = process.env.NODE_ENV || 'development';
|
// process.env.NODE_ENV = process.env.NODE_ENV || 'development';
|
||||||
Reference in New Issue
Block a user