Skip to content

Commit

Permalink
chore(demo): add node js and ts demos
Browse files Browse the repository at this point in the history
  • Loading branch information
Convly authored Jan 30, 2025
2 parents dce8eb1 + 0a7eac3 commit 8d53805
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 10 deletions.
4 changes: 0 additions & 4 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,5 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[{package.json,*.yml}]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false
16 changes: 16 additions & 0 deletions demo/demo-node-javascript/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const { strapi } = require('@strapi/sdk-js');

async function main() {
// Create the SDK instance
const sdk = strapi({ baseURL: 'http://localhost:1337/api' });

// Create a collection type query manager for the categories
const categories = sdk.collection('categories');

// Fetch the list of all categories
const docs = await categories.find();

console.dir(docs, { depth: null });
}

main().catch(console.error);
20 changes: 20 additions & 0 deletions demo/demo-node-javascript/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "demo-node-javascript",
"version": "1.0.0",
"description": "A Strapi SDK demo using a Node x JavaScript application",
"main": "index.js",
"scripts": {
"start": "node index.js",
"debug": "DEBUG=* node index.js"
},
"dependencies": {
"@strapi/sdk-js": "link:../.."
},
"keywords": [],
"author": {
"name": "Strapi Solutions SAS",
"email": "[email protected]",
"url": "https://strapi.io"
},
"license": "ISC"
}
12 changes: 12 additions & 0 deletions demo/demo-node-javascript/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions demo/demo-node-typescript/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "demo-node-typescript",
"version": "1.0.0",
"description": "A Strapi SDK demo using a Node x TypeScript application",
"main": "dist/index.js",
"private": true,
"type": "module",
"scripts": {
"build": "tsc -p tsconfig.json",
"watch": "tsc -p tsconfig.json -w",
"start": "node dist/index.js",
"debug": "DEBUG=* node dist/index.js"
},
"dependencies": {
"@strapi/sdk-js": "link:../.."
},
"devDependencies": {
"typescript": "5.7.3"
},
"keywords": [],
"author": {
"name": "Strapi Solutions SAS",
"email": "[email protected]",
"url": "https://strapi.io"
},
"license": "ISC"
}
28 changes: 28 additions & 0 deletions demo/demo-node-typescript/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions demo/demo-node-typescript/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { strapi } from '@strapi/sdk-js';

// Create the SDK instance
const sdk = strapi({ baseURL: 'http://localhost:1337/api' });

// Create a collection type query manager for the categories
const categories = sdk.collection('categories');

// Fetch the list of all categories
const docs = await categories.find();

console.dir(docs, { depth: null });
26 changes: 26 additions & 0 deletions demo/demo-node-typescript/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"compilerOptions": {
/* Language and Environment */
"allowSyntheticDefaultImports": true,

/* Modules */
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"module": "NodeNext",

/* Emit */
"moduleResolution": "NodeNext",

/* Interop Constraints */

"outDir": "./dist",
"rootDir": "./src",
"skipLibCheck": false,

/* Type Checking */
"strict": true,

/* Completeness */
"target": "ESNext"
}
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
"exports": {
".": {
"types": "./dist/index.d.ts",
"require": "./dist/bundle.cjs.js",
"import": "./dist/bundle.esm.js",
"require": "./dist/bundle.cjs",
"import": "./dist/bundle.mjs",
"browser": {
"import": "./dist/bundle.browser.min.js",
"require": "./dist/bundle.browser.min.js"
Expand Down
8 changes: 4 additions & 4 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ const isProduction = process.env.NODE_ENV === 'production';
* system, ensuring compatibility with a wide range of tools and runtimes.
*
* Outputs:
* - CommonJS (dist/bundle.cjs.js): for environments using `require`.
* - CommonJS (dist/bundle.cjs): for environments using `require`.
* Compatible with older tools and Node.js versions.
* Includes source maps for debugging.
*
* - ES Module (dist/bundle.esm.js): for modern import/export environments.
* - ES Module (dist/bundle.esm): for modern import/export environments.
* Supports tree-shaking for smaller builds and also includes source maps.
*
* Plugins Used:
Expand All @@ -35,14 +35,14 @@ const node_build = {
output: [
// CommonJS build
{
file: 'dist/bundle.cjs.js',
file: 'dist/bundle.cjs',
format: 'cjs',
sourcemap: isProduction ? 'hidden' : true,
exports: 'named',
},
// ESM build
{
file: 'dist/bundle.esm.js',
file: 'dist/bundle.mjs',
format: 'esm',
sourcemap: isProduction ? 'hidden' : true,
exports: 'named',
Expand Down

0 comments on commit 8d53805

Please sign in to comment.