Skip to content

Commit

Permalink
feat: init project gcp cloud storage
Browse files Browse the repository at this point in the history
  • Loading branch information
pornchaitippawan committed Nov 2, 2023
1 parent 2980cd0 commit e47f3ba
Show file tree
Hide file tree
Showing 14 changed files with 10,358 additions and 0 deletions.
70 changes: 70 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---
name: Release

on:
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x]

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'
- name: Install dependencies
run: yarn
- run: yarn build

release:
name: Semantic Release
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
persist-credentials: false
- name: Install dependencies for release
uses: actions/setup-node@v3
with:
node-version: 14
cache: 'yarn'
- name: Install dependencies
run: yarn
- name: Semantic Release
uses: cycjimmy/semantic-release-action@v3
with:
semantic_version: 19
branches: |
[
'+([0-9])?(.{+([0-9]),x}).x',
'main',
'next',
'next-major',
{
name: 'beta',
prerelease: true
},
{
name: 'alpha',
prerelease: true
}
]
extra_plugins: |
@semantic-release/changelog
@semantic-release/git
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish package to NPM 📦
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
32 changes: 32 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
name: Test

on:
pull_request:
branches:
- main

jobs:
test:
strategy:
matrix:
node-version: [12.x,14.x]
name: Node
runs-on: ubuntu-latest
steps:
- name: Checkout ${{ matrix.node-version }}
uses: actions/checkout@v3

- name: Setup and Test ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'

- name: Install node modules
shell: bash
run: yarn

- name: Testing
shell: bash
run: yarn test
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx --no-install commitlint --edit "$1"
7 changes: 7 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

# Enable linting when ready to refactor code
yarn build
# yarn lint
yarn test:unit
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
18.17
18 changes: 18 additions & 0 deletions .releaserc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"dryRun": false,
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/changelog",
["@semantic-release/npm", { "npmPublish": true }],
[
"@semantic-release/git",
{
"assets": ["CHANGELOG.md", "package.json"],
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
}
],
"@semantic-release/github"
],
"branches": ["main"]
}
70 changes: 70 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<p align="center">
<a href="https://www.medusajs.com">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://user-images.githubusercontent.com/59018053/229103275-b5e482bb-4601-46e6-8142-244f531cebdb.svg">
<source media="(prefers-color-scheme: light)" srcset="https://user-images.githubusercontent.com/59018053/229103726-e5b529a3-9b3f-4970-8a1f-c6af37f087bf.svg">
<img alt="Medusa logo" src="https://user-images.githubusercontent.com/59018053/229103726-e5b529a3-9b3f-4970-8a1f-c6af37f087bf.svg">
</picture>
</a>
</p>
<h1 align="center">
Medusa
</h1>

<h4 align="center">
<a href="https://docs.medusajs.com">Documentation</a> |
<a href="https://www.medusajs.com">Website</a>
</h4>

<p align="center">
Building blocks for digital commerce
</p>
<p align="center">
<a href="https://github.com/medusajs/medusa/blob/master/CONTRIBUTING.md">
<img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat" alt="PRs welcome!" />
</a>
<a href="https://www.producthunt.com/posts/medusa"><img src="https://img.shields.io/badge/Product%20Hunt-%231%20Product%20of%20the%20Day-%23DA552E" alt="Product Hunt"></a>
<a href="https://discord.gg/xpCwq3Kfn8">
<img src="https://img.shields.io/badge/chat-on%20discord-7289DA.svg" alt="Discord Chat" />
</a>
<a href="https://twitter.com/intent/follow?screen_name=medusajs">
<img src="https://img.shields.io/twitter/follow/medusajs.svg?label=Follow%20@medusajs" alt="Follow @medusajs" />
</a>
</p>

## Compatibility

This starter is compatible with versions >= 1.8.0 of `@medusajs/medusa`.

## Getting Started

Visit the [Quickstart Guide](https://docs.medusajs.com/create-medusa-app) to set up a server.

Visit the [Docs](https://docs.medusajs.com/development/backend/prepare-environment) to learn more about our system requirements.

## What is Medusa

Medusa is a set of commerce modules and tools that allow you to build rich, reliable, and performant commerce applications without reinventing core commerce logic. The modules can be customized and used to build advanced ecommerce stores, marketplaces, or any product that needs foundational commerce primitives. All modules are open-source and freely available on npm.

Learn more about [Medusa’s architecture](https://docs.medusajs.com/development/fundamentals/architecture-overview) and [commerce modules](https://docs.medusajs.com/modules/overview) in the Docs.

## Roadmap, Upgrades & Plugins

You can view the planned, started and completed features in the [Roadmap discussion](https://github.com/medusajs/medusa/discussions/categories/roadmap).

Follow the [Upgrade Guides](https://docs.medusajs.com/upgrade-guides/) to keep your Medusa project up-to-date.

Check out all [available Medusa plugins](https://medusajs.com/plugins/).

## Community & Contributions

The community and core team are available in [GitHub Discussions](https://github.com/medusajs/medusa/discussions), where you can ask for support, discuss roadmap, and share ideas.

Join our [Discord server](https://discord.com/invite/medusajs) to meet other community members.

## Other channels

- [GitHub Issues](https://github.com/medusajs/medusa/issues)
- [Twitter](https://twitter.com/medusajs)
- [LinkedIn](https://www.linkedin.com/company/medusajs)
- [Medusa Blog](https://medusajs.com/blog/)
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// noop
48 changes: 48 additions & 0 deletions medusa-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const dotenv = require("dotenv");

let ENV_FILE_NAME = "";
switch (process.env.NODE_ENV) {
case "production":
ENV_FILE_NAME = ".env.production";
break;
case "staging":
ENV_FILE_NAME = ".env.staging";
break;
case "test":
ENV_FILE_NAME = ".env.test";
break;
case "development":
default:
ENV_FILE_NAME = ".env";
break;
}

try {
dotenv.config({ path: process.cwd() + "/" + ENV_FILE_NAME });
} catch (e) {}

// CORS when consuming Medusa from admin
const ADMIN_CORS =
process.env.ADMIN_CORS || "http://localhost:7000,http://localhost:7001";

// CORS to avoid issues when consuming Medusa from a client
const STORE_CORS = process.env.STORE_CORS || "http://localhost:8000";

const DATABASE_URL =
process.env.DATABASE_URL || "postgres://localhost/medusa-store";

const REDIS_URL = process.env.REDIS_URL || "redis://localhost:6379";

const plugins = [];

const modules = {};

/** @type {import('@medusajs/medusa').ConfigModule["projectConfig"]} */
const projectConfig = {};

/** @type {import('@medusajs/medusa').ConfigModule} */
module.exports = {
projectConfig,
plugins,
modules,
};
93 changes: 93 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
{
"name": "@xponential/medusa-plugin-file-cloud-storage",
"version": "0.0.1",
"description": "A Medusa plugin to store files in Google Cloud Storage",
"keywords": [
"medusa-plugin",
"cloud-storage",
"google-cloud",
"gcp",
"typescript",
"ecommerce",
"headless",
"medusa"
],
"files": [
"dist"
],
"repository": {
"type": "git",
"url": "https://github.com/xponential-asia/medusa-plugin-file-cloud-storage"
},
"scripts": {
"clean": "cross-env rimraf dist",
"build": "cross-env npm run clean && tsc -p tsconfig.json",
"watch": "cross-env tsc --watch",
"test": "cross-env jest"
},
"dependencies": {
"@medusajs/file-local": "^1.0.2",
"@medusajs/medusa": "^1.17.3",
"@medusajs/types": "^1.11.5",
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"dotenv": "16.0.3",
"medusa-interfaces": "^1.3.7",
"typeorm": "^0.3.16"
},
"devDependencies": {
"@babel/cli": "^7.14.3",
"@babel/core": "^7.14.3",
"@babel/preset-typescript": "^7.21.4",
"@commitlint/cli": "^18.2.0",
"@commitlint/config-conventional": "^18.1.0",
"@semantic-release/changelog": "^6.0.3",
"@semantic-release/git": "^10.0.1",
"@semantic-release/npm": "^11.0.0",
"@types/express": "^4.17.13",
"@types/jest": "^27.4.0",
"@types/multer": "^1.4.7",
"@types/node": "^17.0.8",
"babel-preset-medusa-package": "^1.1.13",
"cross-env": "^7.0.3",
"eslint": "^6.8.0",
"jest": "^27.3.1",
"rimraf": "^3.0.2",
"semantic-release": "^22.0.6",
"ts-jest": "^27.0.7",
"ts-loader": "^9.2.6",
"typescript": "^4.5.2"
},
"peerDependencies": {
"@medusajs/medusa": "^1.16.0"
},
"jest": {
"globals": {
"ts-jest": {
"tsconfig": "tsconfig.spec.json"
}
},
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"testPathIgnorePatterns": [
"/node_modules/",
"<rootDir>/node_modules/"
],
"rootDir": "src",
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|js)$",
"transform": {
".ts": "ts-jest"
},
"collectCoverageFrom": [
"**/*.(t|j)s"
],
"coverageDirectory": "./coverage",
"testEnvironment": "node"
},
"publishConfig": {
"registry": "https://npm.pkg.github.com"
}
}
41 changes: 41 additions & 0 deletions src/services/cloud-storage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { AbstractFileService, IFileService, Logger } from '@medusajs/medusa';
import {
FileServiceUploadResult,
DeleteFileType,
UploadStreamDescriptorType,
FileServiceGetUploadStreamResult,
GetUploadedFileType
} from '@medusajs/types';

class CloudStorageService extends AbstractFileService implements IFileService {
protected logger_: Logger

constructor({ logger }, options) {
super({}, options);

this.logger_ = logger;
}

upload(fileData: Express.Multer.File): Promise<FileServiceUploadResult> {
throw new Error('Method not implemented.');
}
uploadProtected(fileData: Express.Multer.File): Promise<FileServiceUploadResult> {
throw new Error('Method not implemented.');
}
delete(fileData: DeleteFileType): Promise<void> {
throw new Error('Method not implemented.');
}
getUploadStreamDescriptor(
fileData: UploadStreamDescriptorType
): Promise<FileServiceGetUploadStreamResult> {
throw new Error('Method not implemented.');
}
getDownloadStream(fileData: GetUploadedFileType): Promise<NodeJS.ReadableStream> {
throw new Error('Method not implemented.');
}
getPresignedDownloadUrl(fileData: GetUploadedFileType): Promise<string> {
throw new Error('Method not implemented.');
}
}

export default CloudStorageService;
Loading

0 comments on commit e47f3ba

Please sign in to comment.