Skip to content

Commit 8d53805

Browse files
authored
chore(demo): add node js and ts demos
2 parents dce8eb1 + 0a7eac3 commit 8d53805

File tree

10 files changed

+147
-10
lines changed

10 files changed

+147
-10
lines changed

.editorconfig

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,5 @@ charset = utf-8
88
trim_trailing_whitespace = true
99
insert_final_newline = true
1010

11-
[{package.json,*.yml}]
12-
indent_style = space
13-
indent_size = 2
14-
1511
[*.md]
1612
trim_trailing_whitespace = false

demo/demo-node-javascript/index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const { strapi } = require('@strapi/sdk-js');
2+
3+
async function main() {
4+
// Create the SDK instance
5+
const sdk = strapi({ baseURL: 'http://localhost:1337/api' });
6+
7+
// Create a collection type query manager for the categories
8+
const categories = sdk.collection('categories');
9+
10+
// Fetch the list of all categories
11+
const docs = await categories.find();
12+
13+
console.dir(docs, { depth: null });
14+
}
15+
16+
main().catch(console.error);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "demo-node-javascript",
3+
"version": "1.0.0",
4+
"description": "A Strapi SDK demo using a Node x JavaScript application",
5+
"main": "index.js",
6+
"scripts": {
7+
"start": "node index.js",
8+
"debug": "DEBUG=* node index.js"
9+
},
10+
"dependencies": {
11+
"@strapi/sdk-js": "link:../.."
12+
},
13+
"keywords": [],
14+
"author": {
15+
"name": "Strapi Solutions SAS",
16+
"email": "[email protected]",
17+
"url": "https://strapi.io"
18+
},
19+
"license": "ISC"
20+
}

demo/demo-node-javascript/pnpm-lock.yaml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "demo-node-typescript",
3+
"version": "1.0.0",
4+
"description": "A Strapi SDK demo using a Node x TypeScript application",
5+
"main": "dist/index.js",
6+
"private": true,
7+
"type": "module",
8+
"scripts": {
9+
"build": "tsc -p tsconfig.json",
10+
"watch": "tsc -p tsconfig.json -w",
11+
"start": "node dist/index.js",
12+
"debug": "DEBUG=* node dist/index.js"
13+
},
14+
"dependencies": {
15+
"@strapi/sdk-js": "link:../.."
16+
},
17+
"devDependencies": {
18+
"typescript": "5.7.3"
19+
},
20+
"keywords": [],
21+
"author": {
22+
"name": "Strapi Solutions SAS",
23+
"email": "[email protected]",
24+
"url": "https://strapi.io"
25+
},
26+
"license": "ISC"
27+
}

demo/demo-node-typescript/pnpm-lock.yaml

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { strapi } from '@strapi/sdk-js';
2+
3+
// Create the SDK instance
4+
const sdk = strapi({ baseURL: 'http://localhost:1337/api' });
5+
6+
// Create a collection type query manager for the categories
7+
const categories = sdk.collection('categories');
8+
9+
// Fetch the list of all categories
10+
const docs = await categories.find();
11+
12+
console.dir(docs, { depth: null });
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"compilerOptions": {
3+
/* Language and Environment */
4+
"allowSyntheticDefaultImports": true,
5+
6+
/* Modules */
7+
"esModuleInterop": true,
8+
"forceConsistentCasingInFileNames": true,
9+
"module": "NodeNext",
10+
11+
/* Emit */
12+
"moduleResolution": "NodeNext",
13+
14+
/* Interop Constraints */
15+
16+
"outDir": "./dist",
17+
"rootDir": "./src",
18+
"skipLibCheck": false,
19+
20+
/* Type Checking */
21+
"strict": true,
22+
23+
/* Completeness */
24+
"target": "ESNext"
25+
}
26+
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
"exports": {
2929
".": {
3030
"types": "./dist/index.d.ts",
31-
"require": "./dist/bundle.cjs.js",
32-
"import": "./dist/bundle.esm.js",
31+
"require": "./dist/bundle.cjs",
32+
"import": "./dist/bundle.mjs",
3333
"browser": {
3434
"import": "./dist/bundle.browser.min.js",
3535
"require": "./dist/bundle.browser.min.js"

rollup.config.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ const isProduction = process.env.NODE_ENV === 'production';
1313
* system, ensuring compatibility with a wide range of tools and runtimes.
1414
*
1515
* Outputs:
16-
* - CommonJS (dist/bundle.cjs.js): for environments using `require`.
16+
* - CommonJS (dist/bundle.cjs): for environments using `require`.
1717
* Compatible with older tools and Node.js versions.
1818
* Includes source maps for debugging.
1919
*
20-
* - ES Module (dist/bundle.esm.js): for modern import/export environments.
20+
* - ES Module (dist/bundle.esm): for modern import/export environments.
2121
* Supports tree-shaking for smaller builds and also includes source maps.
2222
*
2323
* Plugins Used:
@@ -35,14 +35,14 @@ const node_build = {
3535
output: [
3636
// CommonJS build
3737
{
38-
file: 'dist/bundle.cjs.js',
38+
file: 'dist/bundle.cjs',
3939
format: 'cjs',
4040
sourcemap: isProduction ? 'hidden' : true,
4141
exports: 'named',
4242
},
4343
// ESM build
4444
{
45-
file: 'dist/bundle.esm.js',
45+
file: 'dist/bundle.mjs',
4646
format: 'esm',
4747
sourcemap: isProduction ? 'hidden' : true,
4848
exports: 'named',

0 commit comments

Comments
 (0)