Skip to content

Commit

Permalink
feat: adding rename-packages script (#67)
Browse files Browse the repository at this point in the history
* feat: adding rename-packages script

* fix: removing unnecessary double hyphens

* feat: create dedicated script utils

* refactor: improved organisation and reuseability of scripts

* fix: fixing comments in scripts

* feat: adding exclude option

* feat: adding includeroot option to scripts

* refactor: changing include-root flag

* feat: adding set:license script

* docs(docs): updating documentation for set scripts

* docs(docs): updating documentation for set scripts

* refactor: updating scripts after linting

* chore: updating versions and added changesets

* Update set-author.ts

* docs: adding jsdoc comments to custom scripts

* chore: updating comment

* feat: adding callback script and dependency updates in set:namespace

* feat: adding rename functionality

* feat: updating to promises

* feat: adding bun types

* refactor: removing type-fest in favour of pkg-types

* feat: running bun scripts after namespace update

* feat: merging scripts to one

* chore: update docs & activate ci pipeline from me

---------

Co-authored-by: Ahmed Elsakaan <[email protected]>
  • Loading branch information
imCorfitz and ixahmedxi authored Jun 8, 2024
1 parent 49086f7 commit 5b69876
Show file tree
Hide file tree
Showing 9 changed files with 599 additions and 128 deletions.
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

0 comments on commit 5b69876

Please sign in to comment.