Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
TimurRin committed Nov 19, 2024
0 parents commit 12cb521
Show file tree
Hide file tree
Showing 40 changed files with 5,875 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM docker.io/node:22.11.0

USER node
16 changes: 16 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"build": {
"context": ".",
"dockerfile": "./Dockerfile"
},
"customizations": {
"vscode": {
"extensions": [
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"streetsidesoftware.code-spell-checker"
]
}
},
"name": "Node.js 22"
}
35 changes: 35 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Release

on:
release:
types: [created]

jobs:
build-bundle:
permissions: write-all
runs-on: ubuntu-latest
env:
ANCA_CI: true
name: Build bundle
steps:
- uses: actions/checkout@v4
name: Checkout repo
- uses: actions/setup-node@v4
with:
node-version: 22.11.0
name: Install Node.js
- run: npm ci
name: Install dependencies
- run: npm run build:bundle
name: Build bundle
- run: |
mv build/bundle/index.js build/bundle/${{ github.event.repository.name }}-${{ github.ref_name }}.js
shell: bash
name: Rename bundle
- uses: softprops/action-gh-release@v1
with:
files: |
build/bundle/${{ github.event.repository.name }}-${{ github.ref_name }}.js
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
name: Attach bundle to release
25 changes: 25 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Test

on:
push:
branches: ["**"]

jobs:
test-commit:
runs-on: ubuntu-latest
strategy:
matrix:
node: [18.20.4, 20.18.0, 22.11.0, 23.2.0]
name: Test repo on Node.js ${{ matrix.node }}
steps:
- uses: actions/checkout@v4
name: "Checkout repo"
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
registry-url: https://registry.npmjs.org/
name: "Install Node.js"
- run: npm ci
name: "Install dependencies"
- run: npm test
name: "Run tests"
56 changes: 56 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Editor directories and files
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
.vscode

# Logs
logs
*.log

# Runtime data
pids
*.pid
*.seed
*.pid.lock
*.lock

# Temp folder
tmp

# Built sources
dist
build
*.spec

# Dependency directories
node_modules/
jspm_packages/
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
.yarn-integrity

# Local settings
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# Node.js logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Output of 'npm pack'
*.tgz
30 changes: 30 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# General
**/.git
**/.svn
**/.hg

# Binaries
/bin

# Devcontainer
.devcontainer

# Node.js
**/node_modules
package-lock.json

# Distributions
/build
/dist

# Cinnabar Meta
**/cinnabar.js
**/cinnabar.ts
cinnabar.json
CHANGELOG.md

# Anca
anca.json
esbuild.js
eslint.config.js
openapi.json
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
16 changes: 16 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Contributing

Contributions are welcome! If you find any issues or have suggestions for improvements, feel free to open an issue or create a pull request.

## Installation

We support [Devcontainers](https://containers.dev/). You can use the provided development container to work on this project. The development container includes all the necessary tools and dependencies to work on this project.

Otherwise, download, install and configure [Node.js](https://nodejs.org/en/download/).

Then, run the following commands to install the dependencies and run the tests:

```bash
npm ci
npm test
```
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
There is nothing we can do
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# SnapCRUD

> **DISCLAIMER**: This project is not production ready. All versions below 1.0.0 should be considered unstable
## Installation

## Contributing

Visit [`CONTRIBUTING.md`](CONTRIBUTING.md).

## License

Visit [`LICENSE`](LICENSE).

## Anca

This repository is a part of [Anca](https://github.com/cinnabar-forge/anca) standardization project. Parts of the files and code are generated by Anca.
16 changes: 16 additions & 0 deletions anca.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"development": {
"nodejsOpenapi": {
"modelsLocation": "./src/types/openapi.ts",
"modelsModule": "../types/openapi.js",
"modelsLocationType": "file"
},
"readme": {}
},
"namings": {
"text": "SnapCRUD",
"npmPackage": "snapcrud"
},
"type": "api",
"stack": "nodejs"
}
114 changes: 114 additions & 0 deletions esbuild.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import { build, context } from "esbuild";
import fs from "fs";
import path from "path";
import { spawn } from "child_process";

const getNodeModules = () => {
const nodeModulesPath = path.resolve(import.meta.dirname, "node_modules");
if (!fs.existsSync(nodeModulesPath)) {
return [];
}

return fs.readdirSync(nodeModulesPath).filter((module) => {
return !module.startsWith(".");
});
};

const markBuild = () => {
if (process.env.NODE_ENV === "production") {
return `""`;
}

const datetime = new Date(Date.now())
.toISOString()
.replaceAll("-", "")
.replaceAll(":", "")
.replace("T", ".")
.replace("Z", "")
.split(".");

const build = datetime[0] + "_" + datetime[1];

return `"+next.${build}"`;
}

const IS_WATCH_MODE = process.argv[2] === "watch";
const IS_NPM_BUNDLE = process.argv[2] !== "full";
const ARGUMENTS = process.argv[3] || "";

const ESBUILD_NAME = IS_NPM_BUNDLE ? "NPM Bundle" : "Full Bundle";
const OUT_FILE = IS_NPM_BUNDLE ? "dist/index.js" : "build/bundle/index.js";

const nodeModules = IS_NPM_BUNDLE ? getNodeModules() : [];

const myVars = {
'process.env.ANCA_BUILD_PREFIX': markBuild(),
}

const buildOptions = {
bundle: true,
define: myVars,
entryPoints: ["src/index.ts"],
external: nodeModules,
format: IS_NPM_BUNDLE ? "esm" : "cjs",
outfile: OUT_FILE,
platform: "node",
};

let childProcess = null;

const runOutputFile = () => {
if (childProcess) {
childProcess.kill();
}
childProcess = spawn("node", [OUT_FILE, ...ARGUMENTS.split(" ")], {
stdio: "inherit",
});
};

const cleanUp = () => {
if (childProcess) {
childProcess.kill();
}
process.exit();
};

const watchOutputFile = () => {
fs.watch(OUT_FILE, (eventType) => {
if (eventType === "change") {
runOutputFile();
}
});
};

process.on("exit", cleanUp);
process.on("SIGINT", cleanUp);
process.on("SIGTERM", cleanUp);
process.on("uncaughtException", cleanUp);

if (IS_WATCH_MODE) {
context(buildOptions)
.then(async (ctx) => {
await ctx.watch();
console.log(
`Watching ${buildOptions.entryPoints[0]}... (out: ${ESBUILD_NAME} '${OUT_FILE}')`,
);
runOutputFile();
watchOutputFile();
})
.catch((e) => {
console.error(
`Error setting up watch mode for ${ESBUILD_NAME}: ${e.message}`,
);
process.exit(1);
});
} else {
build(buildOptions)
.then(() => {
console.log(`${ESBUILD_NAME} has been built to ${OUT_FILE}`);
})
.catch((e) => {
console.error(`Error building ${ESBUILD_NAME}: ${e.message}`);
process.exit(1);
});
}
31 changes: 31 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import cinnabarPlugin from "@cinnabar-forge/eslint-plugin";

// [ANCA-ANCHOR-CUSTOM-CONTENT-START]

const files = ["src/**/*.ts"];
const ignores = ["bin/**/*", "build/**/*", "dist/**/*"];
const rules = {
"@typescript-eslint/no-explicit-any": "off",
"jsdoc/require-param-description": "off",
"jsdoc/require-param-type": "off",
"jsdoc/require-returns": "off",
"jsdoc/require-returns-type": "off",
"security/detect-non-literal-fs-filename": "off",
"security/detect-object-injection": "off",
};

// [ANCA-ANCHOR-CUSTOM-CONTENT-END]

export default [
...cinnabarPlugin.default.map((config) => ({
...config,
files,
})),
{
files,
rules,
},
{
ignores,
},
];
Loading

0 comments on commit 12cb521

Please sign in to comment.