Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adding rename-packages script #67

Merged
merged 26 commits into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
49e517e
feat: adding rename-packages script
imCorfitz May 28, 2024
da5e0c3
fix: removing unnecessary double hyphens
imCorfitz May 28, 2024
43a74a3
feat: create dedicated script utils
imCorfitz May 28, 2024
26a3db7
refactor: improved organisation and reuseability of scripts
imCorfitz May 28, 2024
4e58502
fix: fixing comments in scripts
imCorfitz May 28, 2024
309881c
feat: adding exclude option
imCorfitz May 29, 2024
4b4b885
feat: adding includeroot option to scripts
imCorfitz May 29, 2024
3c6182e
refactor: changing include-root flag
imCorfitz May 29, 2024
f7dfc9a
feat: adding set:license script
imCorfitz May 29, 2024
78c2c29
docs(docs): updating documentation for set scripts
imCorfitz May 29, 2024
ecfd711
docs(docs): updating documentation for set scripts
imCorfitz May 29, 2024
0f51ad8
refactor: updating scripts after linting
imCorfitz May 29, 2024
68aa44b
chore: merging main to feat/rename-script
imCorfitz May 29, 2024
e347433
chore: updating versions and added changesets
imCorfitz May 29, 2024
9480b40
Update set-author.ts
imCorfitz May 29, 2024
394baea
docs: adding jsdoc comments to custom scripts
imCorfitz May 30, 2024
d43412a
chore: updating comment
imCorfitz May 30, 2024
a054a9d
feat: adding callback script and dependency updates in set:namespace
imCorfitz May 30, 2024
f589d54
feat: adding rename functionality
imCorfitz May 30, 2024
23cea1b
feat: updating to promises
imCorfitz May 31, 2024
86eadd6
Merge branch 'main' into feat/rename-script
imCorfitz Jun 7, 2024
f09e432
feat: adding bun types
imCorfitz Jun 8, 2024
9a5631d
refactor: removing type-fest in favour of pkg-types
imCorfitz Jun 8, 2024
adabebb
feat: running bun scripts after namespace update
imCorfitz Jun 8, 2024
56ba059
feat: merging scripts to one
imCorfitz Jun 8, 2024
f8f93ec
chore: update docs & activate ci pipeline from me
ixahmedxi Jun 8, 2024
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
7 changes: 7 additions & 0 deletions .changeset/fuzzy-crabs-hear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@orbitkit/docs': patch
---

docs: updated installation documentation

- introduced new commands setting project metadata
19 changes: 19 additions & 0 deletions .changeset/rotten-comics-decide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
'@orbitkit/marketing': patch
'@orbitkit/web': patch
'@orbitkit/api': patch
'@orbitkit/assets': patch
'@orbitkit/auth': patch
'@orbitkit/eslint': patch
'@orbitkit/storybook': patch
'@orbitkit/tailwind': patch
'@orbitkit/tsconfig': patch
'@orbitkit/vite': patch
'@orbitkit/core': patch
'@orbitkit/db': patch
'@orbitkit/env': patch
'@orbitkit/ui': patch
'@orbitkit/utils': patch
---

feat: added new scripts for setting project metadata
87 changes: 3 additions & 84 deletions .commitlintrc.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/* eslint-disable security/detect-non-literal-fs-filename */
import * as fs from 'fs';
import * as path from 'path';
import { getWorkspacePackageNames } from './scripts/utils';

// ------------------------------------------------------------------

Expand All @@ -13,97 +11,19 @@ import * as path from 'path';
//
// This was previously achieved using @commitlint/config-pnpm-scopes
// which provides a custom commitlint configuration.
//
// As Orbitkit has moved away from pnpm workspaces, we need to
// implement a custom commitlint configuration to achieve the same.

// ------------------------------------------------------------------

interface PackageJson {
name: string;
workspaces?: string[];
}

interface Context {
cwd?: string;
}

// ------------------------------------------------------------------

/**
* Function to read and parse the root package.json
* @param cwd the current working directory
* @returns the root package.json in the workspace.
*/
function getRootPackageJson(cwd: string): PackageJson {
const rootPackageJsonPath = path.resolve(cwd, 'package.json');
const rootPackageJson = JSON.parse(
fs.readFileSync(rootPackageJsonPath, 'utf-8'),
) as PackageJson;
return rootPackageJson;
}

/**
* Function to get all workspace package paths.
* @param workspaces the workspaces defined in the root package.json.
* @returns an array of all workspace package paths.
*/
function getWorkspacePackagePaths(workspaces: string[]): string[] {
const workspacePackagePaths: string[] = [];

workspaces.forEach((workspacePattern) => {
const workspaceDirs = workspacePattern.replace(/\/\*$/, '');
const absolutePath = path.resolve(process.cwd(), workspaceDirs);
const packages = fs
.readdirSync(absolutePath)
.map((pkgDir) => path.join(workspaceDirs, pkgDir))
.filter((pkgPath) => fs.existsSync(path.join(pkgPath, 'package.json'))); // Filter only directories with package.json
workspacePackagePaths.push(...packages);
});

return workspacePackagePaths;
}

/**
* Function to get package names from package.json files
* @param packagePaths an array of package paths
* @returns an array of package names
*/
function getPackageNamesFromPaths(packagePaths: string[]): string[] {
const packageNames = packagePaths.map((pkgPath) => {
const packageJsonPath = path.join(pkgPath, 'package.json');
const packageJson = JSON.parse(
fs.readFileSync(packageJsonPath, 'utf-8'),
) as PackageJson;
return packageJson.name;
});

return packageNames;
}

/**
* Function to get all workspace package names
* @param cwd the current working directory
* @returns an array of all workspace package names
*/
function getWorkspacePackageNames(cwd: string): string[] {
const rootPackageJson = getRootPackageJson(cwd);
if (!rootPackageJson.workspaces) {
throw new Error('No workspaces defined in the root package.json');
}

const workspacePackagePaths = getWorkspacePackagePaths(
rootPackageJson.workspaces,
);
const packageNames = getPackageNamesFromPaths(workspacePackagePaths);

return [...packageNames, rootPackageJson.name];
}

/**
* Function to get all projects in the workspace
* @param context the context object
* @returns an array of all projects in the workspace
* @param context The context object
* @returns An array of all projects in the workspace
*/
function getProjects(context?: Context): string[] {
const ctx = context ?? {};
Expand All @@ -129,4 +49,3 @@ export default {
'scope-enum': (ctx: Context) => [2, 'always', getProjects(ctx)],
},
};
/* eslint-enable security/detect-non-literal-fs-filename */
19 changes: 16 additions & 3 deletions apps/docs/installation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -171,16 +171,29 @@ OrbitKit currently ships with two authentication providers, Google and Github. Y

### Reset changelog and versions

When you first clone the repository, you should reset the changelog and versions to start fresh. You can do so by running the following commands:
When you first clone the repository, you should reset the changelog and project metadata to start fresh. You can do so by running the following commands:

```bash
# Reset changelog - this will remove all the changelog.md files in the packages
bun reset:changelog

# Reset package versions - this will reset the versions of all the packages to 0.1.0
bun reset:versions
# Update workspace - this will update the workspace with the new metadata
bun update:workspace --namespace "@myapp" --ir
```

The `update:workspace` command has the following options:

```bash
-n, --namespace # The namespace of the project (e.g. -n "@myapp")
-v, --ver # The version of the project (e.g. -v 1.0.0)
-a, --author # The author of the project (e.g. -a "Ahmed OrbitKit")
-l, --license # The license of the project (e.g. -l "MIT")
--ir, --include-root # Include the root package (e.g. --ir) - boolean flag - no value needs to be passed
-e, --exclude # Exclude packages (e.g. -e @myapp/core @myapp/db)
```

> Note: If you want to pass special characters or spaces in the author flag, you should wrap the value in two sets of quotes `'""'` e.g. `'"Ahmed Elsakaan - https://orbitkit.dev"'`.

### Running the project

Now that you have set up the environment variables, you can run the project!
Expand Down
Binary file modified bun.lockb
Binary file not shown.
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "orbitkit",
"version": "0.2.1",
"version": "0.2.2",
"private": true,
"description": "A comprehensive, opinionated company monorepo boilerplate",
"license": "MIT",
Expand All @@ -23,8 +23,8 @@
"prepare": "husky",
"release": "turbo run build lint typecheck && changeset version && changeset publish",
"reset:changelog": "rimraf --glob **/CHANGELOG.md",
"reset:versions": "bun run ./scripts/reset-versions",
"typecheck": "tsc"
"typecheck": "tsc",
"update:workspace": "bun run ./scripts/update-workspace"
},
"lint-staged": {
"*": [
Expand Down Expand Up @@ -52,7 +52,9 @@
"@orbitkit/eslint": "workspace:^",
"@orbitkit/tsconfig": "workspace:^",
"@playwright/test": "^1.44.1",
"@types/bun": "latest",
"@types/eslint": "^8.56.10",
"@types/yargs": "^17.0.32",
"commitizen": "^4.3.0",
"cspell": "^8.8.4",
"eslint": "^9.4.0",
Expand All @@ -66,6 +68,7 @@
"prettier-plugin-packagejson": "^2.5.0",
"rimraf": "^5.0.7",
"turbo": "^1.13.3",
"typescript": "^5.4.5"
"typescript": "^5.4.5",
"yargs": "^17.7.2"
}
}
37 changes: 0 additions & 37 deletions scripts/reset-versions.ts

This file was deleted.

Loading
Loading