Skip to content
This repository has been archived by the owner on Mar 10, 2023. It is now read-only.

Commit

Permalink
feat: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
phuctm97 committed Jun 12, 2022
0 parents commit 48827b6
Show file tree
Hide file tree
Showing 27 changed files with 6,164 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
@@ -0,0 +1,3 @@
node_modules
out
.DS_Store
4 changes: 4 additions & 0 deletions .husky/commit-msg
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn commitlint --edit $1
5 changes: 5 additions & 0 deletions .husky/pre-commit
@@ -0,0 +1,5 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn tsc --noEmit
yarn lint-staged
1 change: 1 addition & 0 deletions .prettierignore
@@ -0,0 +1 @@
out
7 changes: 7 additions & 0 deletions .vscode/extensions.json
@@ -0,0 +1,7 @@
{
"recommendations": [
"esbenp.prettier-vscode",
"streetsidesoftware.code-spell-checker",
"vivaxy.vscode-conventional-commits"
]
}
16 changes: 16 additions & 0 deletions .vscode/settings.json
@@ -0,0 +1,16 @@
{
"typescript.tsdk": "node_modules/typescript/lib",
"javascript.suggestionActions.enabled": false,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"files.trimTrailingWhitespace": true,
"files.trimFinalNewlines": true,
"files.insertFinalNewline": true,
"files.exclude": {
"**/node_modules": true,
"**/.webpack": true,
"yarn.lock": true,
".husky": true
},
"conventionalCommits.gitmoji": false
}
17 changes: 17 additions & 0 deletions .vscode/tasks.json
@@ -0,0 +1,17 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "start",
"problemMatcher": "$ts-webpack-watch",
"label": "npm: start",
"detail": "Start building & watching in development mode",
"isBackground": true,
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
98 changes: 98 additions & 0 deletions README.md
@@ -0,0 +1,98 @@
# Create Notion App · [![CI](https://github.com/nbundle/create-notion-app/actions/workflows/ci.yml/badge.svg)](https://github.com/nbundle/create-notion-app/actions/workflows/ci.yml)

Create [nbundle]-powered [Notion] apps with one command:

<details>
<summary>npm</summary>

```shell
npx create-notion-app
```

</details>

<details>
<summary>yarn</summary>

```shell
yarn create notion-app
```

</details>

<details>
<summary>pnpm</summary>

```shell
pnpm create notion-app
```

</details>

Or for a TypeScript project:

<details>
<summary>npm</summary>

```shell
npx create-notion-app --ts
```

</details>

<details>
<summary>yarn</summary>

```shell
yarn create notion-app --ts
```

</details>

<details>
<summary>pnpm</summary>

```shell
pnpm create notion-app --ts
```

</details>

## Options

`create-notion-app` comes with the following options:

| Option | Description |
| -------------------------- | ---------------------------------- |
| **-t, --ts, --typescript** | Initialize as a TypeScript project |

## Contributing

### Requirements

- Node 14+

- Yarn 1.22+

### Setup

1. Install requirements

2. Clone the repository

3. Run `yarn` to install dependencies

### Develop

- Run `yarn start` to start building & watching in development mode

- Commit adhering to [Angular commit convention](https://github.com/angular/angular/blob/master/CONTRIBUTING.md#commit) (use `yarn commit` or [Conventional Commits in Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=vivaxy.vscode-conventional-commits) to commit interactively)

- Submit a PR and make sure required status checks pass

- When a PR is merged or code is pushed to `main`, Github automatically builds & publishes a new release if there are relevant changes

<!-- Links -->

[nbundle]: https://www.nbundle.com
[notion]: https://www.notion.so
2 changes: 2 additions & 0 deletions bin/create-notion-app.js
@@ -0,0 +1,2 @@
#!/usr/bin/env node
require("../out/main.js");
4 changes: 4 additions & 0 deletions commitlint.config.js
@@ -0,0 +1,4 @@
module.exports = {
extends: ["@commitlint/config-angular"],
ignores: [(commit) => /^build\((deps|deps-dev)\): bump/.test(commit)],
};
13 changes: 13 additions & 0 deletions cspell.json
@@ -0,0 +1,13 @@
{
"ignorePaths": ["package.json", "cspell.json", ".vscode", "out"],
"words": [
"commitlint",
"hgcheck",
"hgignore",
"intellij",
"mkdocs",
"nbundle",
"npmignore",
"pnpm"
]
}
3 changes: 3 additions & 0 deletions lint-staged.config.js
@@ -0,0 +1,3 @@
module.exports = {
"*": ["prettier --write --ignore-unknown", "cspell --no-must-find-files"],
};
66 changes: 66 additions & 0 deletions package.json
@@ -0,0 +1,66 @@
{
"name": "create-notion-app",
"version": "0.0.0-SNAPSHOT",
"description": "Create nbundle-powered Notion apps with one command",
"keywords": [
"notion",
"notion-api",
"notion-client",
"notion-app",
"notion-integration",
"notion-extension",
"notion-plugin",
"notion-addon",
"notion-automation",
"nbundle",
"nbundle-app",
"nbundle-integration",
"nbundle-extension",
"nbundle-plugin",
"nbundle-addon"
],
"license": "AGPL-3.0",
"repository": "https://github.com/nbundle/create-notion-app",
"publishConfig": {
"access": "public"
},
"files": [
"out",
"bin"
],
"main": "out/main.js",
"bin": {
"create-notion-app": "bin/create-notion-app.js"
},
"engines": {
"node": ">=14.0.0",
"yarn": "^1.22.0"
},
"scripts": {
"prepare": "husky install",
"start": "webpack --mode development --watch --color",
"build": "webpack --mode production --color"
},
"devDependencies": {
"@commitlint/cli": "^17.0.2",
"@commitlint/config-angular": "^17.0.0",
"@commitlint/prompt-cli": "^17.0.0",
"@tsconfig/node14": "^1.0.1",
"@types/async-retry": "^1.4.4",
"@types/got": "^9.6.12",
"@types/node": "^14.18.12",
"@types/tar": "^6.1.1",
"async-retry": "^1.3.3",
"cspell": "^6.1.2",
"got": "^12.1.0",
"husky": "^8.0.1",
"lint-staged": "^13.0.1",
"prettier": "^2.6.2",
"semantic-release": "^19.0.3",
"tar": "^6.1.11",
"ts-loader": "^9.3.0",
"tsconfig-paths-webpack-plugin": "^3.5.2",
"webpack": "^5.73.0",
"webpack-cli": "^4.9.2"
}
}
74 changes: 74 additions & 0 deletions src/create.ts
@@ -0,0 +1,74 @@
import fs from "fs/promises";
import chalk from "chalk";

import {
mustBeEmpty,
downloadAndExtractRepo,
formatProject,
installDependencies,
tryGitInit,
} from "./utils";
import path from "path";

export interface CreateOptions {
typescript?: boolean;
}

export default async function create(
projectDirectory: string,
options: CreateOptions
): Promise<void> {
await fs.mkdir(projectDirectory, { recursive: true });

await mustBeEmpty(projectDirectory);

const example = `example${options.typescript ? "-ts" : ""}`;

console.log(
`Downloading template ${chalk.cyan(example)}. This might take a moment.\n`
);

await downloadAndExtractRepo(projectDirectory, {
username: "nbundle",
name: example,
branch: "main",
});

await formatProject(projectDirectory);

console.log("Installing packages. This might take a couple of minutes.\n");

await installDependencies(projectDirectory);

if (await tryGitInit(projectDirectory)) {
console.log("Initialized a git repository.\n");
}

const packageManager = "yarn";
const useYarn = packageManager === "yarn";

const name = path.basename(projectDirectory);
let cdPath: string;
if (path.join(process.cwd(), name) === projectDirectory) {
cdPath = name;
} else {
cdPath = projectDirectory;
}
console.log(
`${chalk.green("Success!")} Created ${chalk.blue(projectDirectory)}\n`
);
console.log("Inside that directory, you can run several commands:\n");
console.log(
chalk.cyan(` ${packageManager} ${useYarn ? "" : "run "}develop`)
);
console.log(" Starts the development server.\n");
console.log(chalk.cyan(` ${packageManager} ${useYarn ? "" : "run "}build`));
console.log(" Builds the app for production.\n");
console.log(chalk.cyan(` ${packageManager} preview`));
console.log(" Runs the built app in production mode.\n");
console.log("We suggest that you begin by typing:\n");
console.log(chalk.cyan(" cd"), cdPath);
console.log(
` ${chalk.cyan(`${packageManager} ${useYarn ? "" : "run "}dev`)}\n`
);
}
41 changes: 41 additions & 0 deletions src/index.ts
@@ -0,0 +1,41 @@
import path from "path";
import fs from "fs/promises";
import { Command, Option } from "commander";

import create from "./create";

async function index() {
const program = new Command();

const pkgJson = await fs.readFile(
path.resolve(__dirname, "..", "package.json"),
"utf8"
);
const pkg = JSON.parse(pkgJson);

program
.name(pkg.name)
.description(pkg.description)
.version(pkg.version, "-v, -V, --version")
.arguments("<project-directory>")
.usage(`<project-directory> [options]`)
.option("-t, --ts, --typescript", "initialize as a TypeScript project")
.addOption(
new Option(
"-t, --typescript",
"initialize as a TypeScript project"
).hideHelp()
)
.action((projectDirectory, opts) =>
create(path.resolve(projectDirectory), {
typescript: opts.ts || opts.typescript,
})
);

await program.parseAsync();
}

index().catch((err) => {
console.error(err);
process.exit(1);
});
4 changes: 4 additions & 0 deletions src/utils/async-exec.ts
@@ -0,0 +1,4 @@
import child_process from "child_process";
import { promisify } from "util";

export const exec = promisify(child_process.exec);
4 changes: 4 additions & 0 deletions src/utils/async-pipeline.ts
@@ -0,0 +1,4 @@
import stream from "stream";
import { promisify } from "util";

export const pipeline = promisify(stream.pipeline);

0 comments on commit 48827b6

Please sign in to comment.