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
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

strategy:
matrix:
node-version: [16.x, 18.x]
node-version: [20.x, 22.x]

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion bin/eckode.mjs
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/usr/bin/env node
import '../src/index.mjs'
import '../src/index.mjs';
50 changes: 24 additions & 26 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eckode/cli",
"version": "0.0.4",
"version": "0.0.8",
"description": "CLI tool, written in TypeScript, for running @eckode scoped packages.",
"keywords": [
"eckode",
Expand All @@ -20,16 +20,16 @@
},
"homepage": "https://github.com/eckode/cli",
"scripts": {
"build": "yarn clean && tsc",
"clean": "ts-node-esm ./src/clean.mts",
"pkg": "tsc && ts-node-esm ./src/package.mts"
"build": "tsc",
"clean": "ts-node-esm ./src/clean.mjs",
"pkg": "tsc && ts-node-esm ./src/package.mjs"
},
"bin": {
"eckode": "./bin/eckode.mjs"
},
"engines": {
"node": ">=16",
"npm": ">=8"
"node": ">=20.0.0",
"npm": ">=9"
},
"files": [
"bin",
Expand All @@ -43,25 +43,23 @@
"access": "public"
},
"devDependencies": {
"@types/express": "^4.17.14",
"@types/node": "^18.11.9",
"@types/resolve-bin": "^0.4.1",
"@types/rimraf": "^3.0.2",
"@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/parser": "^5.43.0",
"chalk": "^5.1.2",
"eslint": "^8.0.1",
"eslint-config-standard-with-typescript": "^23.0.0",
"eslint-plugin-import": "^2.25.2",
"eslint-plugin-n": "^15.0.0",
"eslint-plugin-promise": "^6.0.0",
"jest": "^29.3.1",
"prettier": "^2.7.1",
"resolve-bin": "^1.0.1",
"rimraf": "^3.0.2",
"ts-node": "^10.9.1",
"typescript": "~4.9.0"
"@types/express": "^5.0.0",
"@types/node": "^22.10.1",
"@types/resolve-bin": "^0.4.3",
"@typescript-eslint/eslint-plugin": "^8.18.0",
"@typescript-eslint/parser": "^8.18.0",
"chalk": "^5.3.0",
"eslint": "^9.16.0",
"eslint-config-love": "^110.0.0",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-n": "^17.15.0",
"eslint-plugin-promise": "^7.2.1",
"jest": "^29.7.0",
"prettier": "^3.4.2",
"rimraf": "^6.0.1",
"ts-node": "^10.9.2",
"typescript": "~5.7.2"
},
"main": "./src/index.ts",
"main": "./src/index.mjs",
"dependencies": {}
}
}
3 changes: 1 addition & 2 deletions src/clean.mts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { logger, rmRf } from './utils.mjs';

(async () => {
try {
await rmRf('./src/**/*.mjs');
await rmRf('./src/**/*.js');
await rmRf(['./src/**/*.mjs', './src/**/*.js']);
} catch (err) {
// @TODO @type
logger(err as string, 'error');
Expand Down
6 changes: 6 additions & 0 deletions src/deps/index.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import * as rimrafPkg from 'rimraf';
export const { rimraf } = rimrafPkg;
export default rimrafPkg;

import { createRequire } from 'module';
export const require = createRequire(import.meta.url);
5 changes: 2 additions & 3 deletions src/index.mts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { exit } from 'process';

import { spawnNodeProcess, logger } from './utils.mjs';
import nodeLocalVars from './node-env-vars.mjs';
import { EckodeNpmScripts } from './types.js';
import { EckodeNpmScripts } from './types.mjs';

const eckodeNpmCommands: Array<EckodeNpmScripts> = ['build', 'dev'];

Expand All @@ -21,8 +21,7 @@ process.env.ECKO_PROJECT_PATH = process.cwd();
process.env.ECKO_COMMAND = lifecycleEvent as EckodeNpmScripts;

if (!eckodeNpmCommands.includes(process.env.ECKO_COMMAND)) {
logger(`command not found!`, 'error', process.env.ECKO_COMMAND),
exit(1);
logger(`command not found!`, 'error', process.env.ECKO_COMMAND), exit(1);
}

// Start er up!
Expand Down
24 changes: 9 additions & 15 deletions src/package.mts
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
// const copyFile = async (src, dest) => {
// await fs.promises.copyFile(src, dest);
// };
import fs from 'fs/promises';
import { resolve } from 'path';
import { logger } from './utils.mjs';
import packageJson from '../package.json' assert { type: 'json' };
import { logger, rmRf } from './utils.mjs';

const packageJsonPath = resolve('./', 'package.json');

(async () => {
logger('Package.json file copied');
logger('Making changes...');
const updatedJson = ({ devDependencies: dependencies, ...rest }: typeof packageJson) => ({
...rest,
dependencies,
});
await fs.writeFile('./package.json', JSON.stringify(updatedJson(packageJson)));
logger('Changes applied');
})();
logger('Making changes...');
const updatedJson = ({ devDependencies: dependencies, ...rest }: typeof packageJson) => ({
...rest,
dependencies,
});
await fs.writeFile('./package.json', JSON.stringify(updatedJson(packageJson)));
logger('Changes applied');
})();
4 changes: 2 additions & 2 deletions src/scripts/build.mts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
*/
import { platform } from 'os';
import { spawnSync } from 'child_process';
import { sync as resolveBin } from 'resolve-bin';
import { require } from '../deps/index.mjs';

const { ECKO_SCOPED_PATH } = process.env;

import { normalize } from 'path';

// @TODO Make args dynamic.
const { status } = spawnSync(
resolveBin('webpack'),
require.resolve('webpack/bin/webpack.js'),
['--config', normalize(`${ECKO_SCOPED_PATH}/webpack/webpack/webpack.prod.mjs`)],
{
stdio: 'inherit',
Expand Down
6 changes: 3 additions & 3 deletions src/scripts/dev.mts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
* External dependencies
*/
import { platform } from 'os';
import { spawnSync } from 'child_process';
import { sync as resolveBin } from 'resolve-bin';
import { normalize } from 'path';
import { spawnSync } from 'child_process';
import { require } from '../deps/index.mjs';

const { ECKO_SCOPED_PATH } = process.env;

// @TODO Make args dynamic.
const { status } = spawnSync(
resolveBin('webpack'),
require.resolve('webpack/bin/webpack.js'),
['serve', '--config', normalize(`${ECKO_SCOPED_PATH}/webpack/webpack/webpack.dev.mjs`)],
{
stdio: 'inherit',
Expand Down
File renamed without changes.
24 changes: 12 additions & 12 deletions src/utils.mts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import { exit } from 'process';
import { existsSync } from 'fs';
import { normalize } from 'path';
// Local
import { LoggerTypes, BgColors, Colors, SpawnNodeProcessArgs } from './types';
import { LoggerTypes, BgColors, Colors, SpawnNodeProcessArgs } from './types.mjs';
import { spawnSync } from 'child_process';
import rimraf from 'rimraf';
import { rimraf } from './deps/index.mjs';

/**
* Spawn Node Process to load one of the script commands.
Expand Down Expand Up @@ -156,13 +156,13 @@ export function logger(msg: string, type: keyof LoggerTypes = 'text', em: string
* @uses rimraf
* @since 0.0.1
*/
export const rmRf = (src: string) =>
new Promise<string>((resolve, reject) => {
rimraf(src, (err) => {
if (err === null) {
logger(`${src} successfully removed`, 'success');
return resolve('Success');
}
return reject(new Error(`Error invoking rimraf for ${src}`));
});
});
export const rmRf = async (src: string | string[]) => {
try {
await rimraf(src, { glob: true });
} catch (error) {
if (error instanceof Error) {
throw new Error(`Error invoking rimraf for ${src}, ${error.message}`);
}
throw new Error(`Error invoking rimraf for ${src}`);
}
};
Loading
Loading