Skip to content

Commit

Permalink
refactor/move-scripts-to-src (#985)
Browse files Browse the repository at this point in the history
* chore: move scripts to src directory

It moves the modules needed by the cli from  scripts to src.
It lets only scripts needed by ci and dev under scripts dir.

* refactor: move `bin/eventcatalog.ts`to `src/`

It moves the `bin` to `scr/` dir to centralize all source files.

* chore: update tsup config

* refactor: update paths and references for new structure

* chore: remove `copyCore` from preview cli command

The preview cli command needs the `dist/` dir from the build command,
so the `copyCore` is useless.

* Create neat-crabs-join.md

---------

Co-authored-by: David Boyne <boyneyy123@gmail.com>
  • Loading branch information
carlosallexandre and boyney123 authored Dec 3, 2024
1 parent c1026b1 commit 8e95677
Show file tree
Hide file tree
Showing 67 changed files with 32 additions and 34 deletions.
5 changes: 5 additions & 0 deletions .changeset/neat-crabs-join.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@eventcatalog/core": minor
---

chore(core): refactor to code base moving files to new src directory
2 changes: 2 additions & 0 deletions bin/eventcatalog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env node
import '../dist/eventcatalog.js';
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
"access": "public"
},
"bin": {
"eventcatalog": "bin/dist/eventcatalog.cjs"
"eventcatalog": "bin/eventcatalog.js"
},
"files": [
"eventcatalog/",
"!eventcatalog/**/__tests__/",
"bin/dist/",
"bin/",
"dist/",
"default-files-for-collections/"
],
"scripts": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
getEventCatalogConfigFile,
verifyRequiredFieldsAreInCatalogConfigFile,
writeEventCatalogConfigFile,
} from 'scripts/eventcatalog-config-file-utils';
} from '../eventcatalog-config-file-utils';
import { tmpdir } from 'os';

describe('catalog-to-astro-content-directory', () => {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,7 @@ import { verifyRequiredFieldsAreInCatalogConfigFile, addPropertyToFrontMatter }
import { mapCatalogToAstro } from './map-catalog-to-astro.js';

const __filename = fileURLToPath(import.meta.url);
const rootPkg = path.resolve(
path.dirname(__filename),
/**
* TODO: fix me =0
*
* The following is a workaround until organize the structure to have the correct path
* for any value of NODE_ENV
*
* @author carlosallexandre
*/
process.env.NODE_ENV === 'test' ? '../' : '../../'
);
const rootPkg = path.resolve(path.dirname(__filename), '../');

const copyFiles = async (source, target) => {
const files = await glob(path.join(source, '**'), {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
34 changes: 17 additions & 17 deletions bin/eventcatalog.ts → src/eventcatalog.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
#!/usr/bin/env node
import { Command } from 'commander';
import { exec, execSync } from 'node:child_process';
import { execSync } from 'node:child_process';
import { join } from 'node:path';
import fs from 'fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import concurrently from 'concurrently';
import { generate } from 'scripts/generate';
import logBuild from 'scripts/analytics/log-build';
import { VERSION } from 'scripts/constants';
import { watch } from 'scripts/watcher';
import { catalogToAstro } from 'scripts/catalog-to-astro-content-directory';
import { generate } from './generate';
import logBuild from './analytics/log-build';
import { VERSION } from './constants';
import { watch } from './watcher';
import { catalogToAstro } from './catalog-to-astro-content-directory';

const currentDir = path.dirname(fileURLToPath(import.meta.url));

Expand All @@ -23,16 +22,10 @@ const dir = path.resolve(process.env.PROJECT_DIR || process.cwd());
const core = path.resolve(process.env.CATALOG_DIR || join(dir, '.eventcatalog-core'));

// The project itself
const eventCatalogDir = path.resolve(join(currentDir, '../../eventcatalog/'));
const eventCatalogDir = path.resolve(join(currentDir, '../eventcatalog/'));

program.name('eventcatalog').description('Documentation tool for event-driven architectures');

const copyFolder = (from: string, to: string) => {
if (fs.existsSync(from)) {
fs.cpSync(from, to, { recursive: true });
}
};

const ensureDir = (dir: string) => {
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
Expand Down Expand Up @@ -130,8 +123,9 @@ program
});

const previewCatalog = () => {
copyCore();

/**
* TODO: get the port and outDir from the eventcatalog.config.js.
*/
execSync(`cross-env PROJECT_DIR='${dir}' CATALOG_DIR='${core}' npx astro preview --root ${dir} --port 3000`, {
cwd: core,
stdio: 'inherit',
Expand Down Expand Up @@ -161,4 +155,10 @@ program
await generate(dir);
});

program.parseAsync();
program
.parseAsync()
.then(() => process.exit(0))
.catch((err) => {
console.error(err);
process.exit(1);
});
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"compilerOptions": {
"strict": true,
"baseUrl": ".",
"outDir": "dist/",
"types": ["vitest/globals"]
}
}
4 changes: 2 additions & 2 deletions tsup.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { defineConfig } from 'tsup';

export default defineConfig({
entry: ['bin/eventcatalog.ts', 'bin/eventcatalog.config.ts'],
entry: ['src/**', '!src/**/__tests__/**'],
dts: true,
outDir: 'bin/dist',
outDir: 'dist/',
format: ['esm', 'cjs'],
shims: true,
clean: true,
Expand Down

0 comments on commit 8e95677

Please sign in to comment.