Skip to content

Commit 765ba7b

Browse files
authored
πŸ› FIX: @baseai/core build module paths (#70)
* πŸ› FIX: @baseai/core build path * πŸ“¦ NEW: snapshot release * πŸ‘Œ IMPROVE: TS config * πŸ‘Œ IMPROVE: Code * πŸ› FIX: Export paths * πŸ“¦ NEW: snapshot release * πŸ‘Œ IMPROVE: Code
1 parent d56323a commit 765ba7b

File tree

6 files changed

+111
-16
lines changed

6 files changed

+111
-16
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/**
2+
* This script creates a snapshot release by performing the following steps:
3+
* 1. Ensures the script is running from the project root directory.
4+
* 2. Defines a function to execute shell commands and log their output.
5+
* 3. Defines a function to update the version in a given package.json file.
6+
* - If the current version is already a snapshot, it increments the snapshot number.
7+
* - If the current version is not a snapshot, it increments the patch version and sets the snapshot number to 0.
8+
* 4. Retrieves the current commit short SHA.
9+
* 5. Bumps the version in the specified package.json files.
10+
* 6. Runs a series of commands to version, build, and publish the packages as a snapshot release.
11+
*
12+
* @requires child_process
13+
* @requires path
14+
* @requires fs
15+
*/
16+
const {execSync} = require('child_process');
17+
const path = require('path');
18+
const fs = require('fs');
19+
20+
// Ensure we're in the project root
21+
process.chdir(path.resolve(__dirname, '../..'));
22+
23+
// Function to execute commands and log output
24+
function run(command) {
25+
console.log(`Running: ${command}`);
26+
try {
27+
execSync(command, {stdio: 'inherit'});
28+
} catch (error) {
29+
console.error(`Error executing command: ${command}`);
30+
console.error(error);
31+
process.exit(1);
32+
}
33+
}
34+
35+
// Function to update version in package.json
36+
function bumpVersion(packagePath) {
37+
const pkg = JSON.parse(fs.readFileSync(packagePath, 'utf8'));
38+
const currentVersion = pkg.version;
39+
let [major, minor, patch, snapshot] = currentVersion
40+
.split(/[-.]/)
41+
.map(v => (isNaN(parseInt(v)) ? v : parseInt(v)));
42+
43+
if (snapshot === 'snapshot') {
44+
// If already a snapshot, increment the snapshot number
45+
snapshot = parseInt(pkg.version.split('-snapshot.')[1]) + 1;
46+
} else {
47+
// If not a snapshot, increment patch and set snapshot to 0
48+
patch += 1;
49+
snapshot = 0;
50+
}
51+
52+
pkg.version = `${major}.${minor}.${patch}-snapshot.${snapshot}`;
53+
fs.writeFileSync(packagePath, JSON.stringify(pkg, null, 2));
54+
console.log(`Updated ${packagePath} to version ${pkg.version}`);
55+
}
56+
57+
// Get the current commit short SHA
58+
const SHORT_SHA = execSync('git rev-parse --short HEAD').toString().trim();
59+
60+
console.log('Creating snapshot release...');
61+
62+
// Bump versions
63+
bumpVersion('./packages/baseai/package.json');
64+
bumpVersion('./packages/core/package.json');
65+
66+
// Version and tag the snapshot release
67+
run(`pnpm changeset version --snapshot ${SHORT_SHA}`);
68+
69+
// Build and publish the snapshot release
70+
run('pnpm build:pkgs');
71+
run('pnpm changeset publish --no-git-tag --tag snapshot');
72+
73+
// Reset Git changes
74+
console.log('Git commit and push changes...');
75+
run('git add . && git commit -m "πŸ“¦ NEW: snapshot release" && git push');
76+
77+
console.log('All changes have been reset. Snapshot release process complete!');

β€Žpackage.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"clean-examples": "node .github/scripts/cleanup-examples-changesets.mjs",
3030
"update-examples": "npx tsx .github/scripts/update-examples.ts",
3131
"ci:version": "changeset version && node .github/scripts/cleanup-examples-changesets.mjs && pnpm install --no-frozen-lockfile",
32-
"snapshot": "changeset --empty && changeset version --snapshot && changeset publish --no-git-tag --snapshot"
32+
"snapshot": "node .github/scripts/release-snapshot.js"
3333
},
3434
"devDependencies": {
3535
"@baseai/eslint-config": "workspace:*",

β€Žpackages/core/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ node_modules/
33
/playwright-report/
44
/blob-report/
55
/playwright/.cache/
6+
/react
7+
/helpers
8+
/pipes

β€Žpackages/core/package.json

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
"types": "./dist/index.d.ts",
1010
"files": [
1111
"dist/**",
12+
"pipes/dist/**",
13+
"helpers/dist/**",
14+
"react/dist/**",
1215
"CHANGELOG.md"
1316
],
1417
"scripts": {
@@ -63,19 +66,19 @@
6366
"import": "./dist/index.mjs"
6467
},
6568
"./react": {
66-
"types": "./dist/react/index.d.ts",
67-
"require": "./dist/react/index.js",
68-
"import": "./dist/react/index.mjs"
69+
"types": "./react/dist/index.d.ts",
70+
"require": "./react/dist/index.js",
71+
"import": "./react/dist/index.mjs"
6972
},
7073
"./pipes": {
71-
"types": "./dist/pipes/index.d.ts",
72-
"require": "./dist/pipes/index.js",
73-
"import": "./dist/pipes/index.mjs"
74+
"types": "./pipes/dist/index.d.ts",
75+
"require": "./pipes/dist/index.js",
76+
"import": "./pipes/dist/index.mjs"
7477
},
7578
"./helpers": {
76-
"types": "./dist/helpers/index.d.ts",
77-
"require": "./dist/helpers/index.js",
78-
"import": "./dist/helpers/index.mjs"
79+
"types": "./helpers/dist/index.d.ts",
80+
"require": "./helpers/dist/index.js",
81+
"import": "./helpers/dist/index.mjs"
7982
}
8083
},
8184
"engines": {

β€Žpackages/core/tsup.config.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,33 @@ export default defineConfig([
1313
},
1414
{
1515
entry: ['src/pipes/index.ts'],
16-
outDir: 'dist/pipes',
16+
outDir: 'pipes/dist',
1717
format: ['cjs', 'esm'],
1818
external: ['react', 'svelte', 'vue'],
1919
dts: true,
20-
clean: false,
20+
clean: true,
2121
sourcemap: true,
2222
},
2323
{
2424
entry: ['src/helpers/index.ts'],
25-
outDir: 'dist/helpers',
25+
outDir: 'helpers/dist',
2626
format: ['cjs', 'esm'],
2727
external: ['react', 'svelte', 'vue'],
2828
dts: true,
29-
clean: false,
29+
clean: true,
3030
sourcemap: true,
3131
},
3232
// React APIs
3333
{
3434
entry: ['src/react/index.ts'],
35-
outDir: 'dist/react',
35+
outDir: 'react/dist',
3636
banner: {
3737
js: "'use client'",
3838
},
3939
format: ['cjs', 'esm'],
4040
external: ['react', 'svelte', 'vue', 'solid-js'],
4141
dts: true,
42-
clean: false,
42+
clean: true,
4343
sourcemap: true,
4444
},
4545
]);

β€Žpackages/core/turbo.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"extends": [
3+
"//"
4+
],
5+
"tasks": {
6+
"build": {
7+
"outputs": [
8+
"**/dist/**"
9+
]
10+
}
11+
}
12+
}

0 commit comments

Comments
Β (0)