Skip to content

Commit

Permalink
chore: merges master
Browse files Browse the repository at this point in the history
  • Loading branch information
DBozhinovski committed Mar 22, 2024
2 parents 643f68c + a2f3cae commit dbb41e6
Show file tree
Hide file tree
Showing 21 changed files with 213 additions and 143 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Enforce Unix newlines
* text=auto eol=lf
7 changes: 7 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ If you are testing an example app you have created on your own branch, you can p
npx . --branch=your_branch
```
### Update package version if needed
You should update the package's version following [semantic versioning](https://semver.org/) rules. This needs to be done in these files:
- `package.json`
- `lib/ts/version.ts`
### Create a pull request
1. Reference the relevant issue or pull request and give a clear description of changes/features added when submitting a pull request
Expand Down
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ The tool creates a folder for the created application. You can follow the instru

When running the tool you can provide additional arguments.

| Option | About | Usage |
| ---------- | -------------------------------------------------------- | :----------------------: |
| `appname` | The folder name to be used when creating the application | `--appname=my-app` |
| `recipe` | The type of authentication you want to use | `--recipe=emailpassword` |
| `frontend` | The frontend stack to use for the application | `--frontend=react` |
| `backend` | The backend stack to use for the application | `--backend=node` |
| Option | About | Usage |
| ----------- | --------------------------------------------------------- | :----------------------: |
| `appname` | The folder name to be used when creating the application | `--appname=my-app` |
| `recipe` | The type of authentication you want to use | `--recipe=emailpassword` |
| `frontend` | The frontend stack to use for the application | `--frontend=react` |
| `backend` | The backend stack to use for the application | `--backend=node` |
| `manager` | Which package manager to use (npm, yarn, pnpm, bun) | `--manager=pnpm` |
| `autostart` | Whether the CLI should start the project after setting up | `--autostart=true` |

## Contributing

Expand Down
8 changes: 0 additions & 8 deletions boilerplate/fullstack/remix/app/routes/auth.$.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@ import { PreBuiltUIList } from "../../app/config/frontend";
import SuperTokens from "supertokens-auth-react/index.js";

export default function Auth() {
useEffect(() => {
if (canHandleRoute(PreBuiltUIList) === false) {
SuperTokens.redirectToAuth({
redirectBack: false,
});
}
}, []);

// If the user visits a page that is not handled by us (like /auth/random), then we redirect them back to the auth page.
const [loaded, setLoaded] = useState(false);
useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { json } from "@remix-run/node";
import { LoaderFunctionArgs } from "react-router-dom";
import { getSessionDetails } from "../lib/superTokensHelpers.js";

// Loader function for handling GET requests that also adds cache control headers
export async function loader({ request }: LoaderFunctionArgs) {
try {
const res = await getSessionDetails(request);
return {
session: res.session,
};
} catch (error) {
return json({ error: "Internal server error" }, { status: 500 });
}
}
61 changes: 29 additions & 32 deletions lib/build/config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getPackageManagerCommand, validateFolderName } from "./userArgumentUtils.js";
import { validateFolderName } from "./userArgumentUtils.js";
import {
getDjangoPythonRunScripts,
getPythonRunScripts,
Expand All @@ -14,8 +14,7 @@ function getCapacitorMessage() {
return `create-supertokens-app uses ${chalk.bold("nextjs-native-starter")} as a template app for Capacitor. ${chalk.bold("nextjs-native-starter")} is a starter project created by ${chalk.blue("https://github.com/RobSchilderr")}, if you face any problems please open an issue here: ${chalk.blue("https://github.com/RobSchilderr/nextjs-native-starter/issues")} or reach out to us on the SuperTokens Discord server: ${chalk.blue("https://supertokens.com/discord")}.\n\nTo get started refer to the README on Github ${chalk.blue("https://github.com/RobSchilderr/nextjs-native-starter")}`;
}
}
export async function getFrontendOptions(userArguments) {
const packagerCommand = await getPackageManagerCommand(userArguments);
export async function getFrontendOptions({ manager }) {
return [
{
value: "react",
Expand All @@ -25,8 +24,8 @@ export async function getFrontendOptions(userArguments) {
config: [{ finalConfig: "/src/config.tsx", configFiles: "/config" }],
},
script: {
setup: [`${packagerCommand} install`],
run: [`${packagerCommand} run start`],
setup: [`${manager} install`],
run: [`${manager} run start`],
},
},
{
Expand All @@ -37,8 +36,8 @@ export async function getFrontendOptions(userArguments) {
config: [{ finalConfig: "/src/config.tsx", configFiles: "/config" }],
},
script: {
setup: [`${packagerCommand} install`],
run: [`${packagerCommand} run start`],
setup: [`${manager} install`],
run: [`${manager} run start`],
},
shouldDisplay: false,
},
Expand All @@ -64,8 +63,8 @@ export async function getFrontendOptions(userArguments) {
},
},
script: {
run: [`${packagerCommand} run dev`],
setup: [`${packagerCommand} install`],
run: [`${manager} run dev`],
setup: [`${manager} install`],
},
},
{
Expand All @@ -91,8 +90,8 @@ export async function getFrontendOptions(userArguments) {
},
},
script: {
run: [`${packagerCommand} run dev`],
setup: [`${packagerCommand} install`],
run: [`${manager} run dev`],
setup: [`${manager} install`],
},
},
{
Expand All @@ -118,8 +117,8 @@ export async function getFrontendOptions(userArguments) {
},
},
script: {
run: [`${packagerCommand} run dev`],
setup: [`${packagerCommand} install`],
run: [`${manager} run dev`],
setup: [`${manager} install`],
},
},
{
Expand All @@ -144,8 +143,8 @@ export async function getFrontendOptions(userArguments) {
},
},
script: {
run: [`${packagerCommand} run dev`],
setup: [`${packagerCommand} install`],
run: [`${manager} run dev`],
setup: [`${manager} install`],
},
},
{
Expand All @@ -159,8 +158,8 @@ export async function getFrontendOptions(userArguments) {
],
},
script: {
setup: [`${packagerCommand} install`],
run: [`${packagerCommand} run dev`],
setup: [`${manager} install`],
run: [`${manager} run dev`],
},
},
{
Expand All @@ -174,8 +173,8 @@ export async function getFrontendOptions(userArguments) {
],
},
script: {
setup: [`${packagerCommand} install`],
run: [`${packagerCommand} run dev`],
setup: [`${manager} install`],
run: [`${manager} run dev`],
},
},
{
Expand Down Expand Up @@ -211,8 +210,7 @@ export async function getFrontendOptions(userArguments) {
},
];
}
export async function getNextJSOptions(userArguments) {
const packagerCommand = await getPackageManagerCommand(userArguments);
export async function getNextJSOptions({ manager }) {
return [
{
displayName: "Using the App directory",
Expand All @@ -234,8 +232,8 @@ export async function getNextJSOptions(userArguments) {
},
},
script: {
run: [`${packagerCommand} run dev`],
setup: [`${packagerCommand} install`],
run: [`${manager} run dev`],
setup: [`${manager} install`],
},
value: "next-app-directory",
isFullStack: true,
Expand All @@ -262,8 +260,8 @@ export async function getNextJSOptions(userArguments) {
},
},
script: {
run: [`${packagerCommand} run dev`],
setup: [`${packagerCommand} install`],
run: [`${manager} run dev`],
setup: [`${manager} install`],
},
},
];
Expand Down Expand Up @@ -311,8 +309,7 @@ const pythonOptions = [
},
},
];
export async function getBackendOptions(userArguments) {
const packagerCommand = await getPackageManagerCommand(userArguments);
export async function getBackendOptions({ manager }) {
return [
{
value: "node",
Expand All @@ -327,8 +324,8 @@ export async function getBackendOptions(userArguments) {
],
},
script: {
setup: [`${packagerCommand} install`],
run: [`${packagerCommand} run start`],
setup: [`${manager} install`],
run: [`${manager} run start`],
},
},
{
Expand All @@ -339,8 +336,8 @@ export async function getBackendOptions(userArguments) {
config: [{ finalConfig: "/src/config.ts", configFiles: "/config" }],
},
script: {
setup: [`${packagerCommand} install`],
run: [`${packagerCommand} run start`],
setup: [`${manager} install`],
run: [`${manager} run start`],
},
},
{
Expand Down Expand Up @@ -477,7 +474,7 @@ export async function getQuestions(flags) {
message: "What type of authentication do you want to use?",
choices: mapOptionsToChoices(recipeOptions),
when: (answers) => {
// For capactor we dont ask this question because it has its own way of swapping between recipes
// For capacitor we don't ask this question because it has its own way of swapping between recipes
if (answers.frontend === "capacitor") {
return false;
}
Expand Down
15 changes: 10 additions & 5 deletions lib/build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import AnalyticsManager from "./analytics.js";
import figlet from "figlet";
import { package_version } from "./version.js";
import { modifyAnswersBasedOnNextJsFramework, modifyAnswersForPythonFrameworks } from "./questionUtils.js";
import { inferredPackageManager } from "./packageManager.js";
async function printInformation() {
const font = "Doom";
console.log("\n");
Expand Down Expand Up @@ -76,7 +77,7 @@ async function run() {
For example: `npx create-supertokens-app --recipe=emailpassword` will result
in userArguments.recipe === "emailpassword"
Avalaible flags:
Available flags:
--appname: App name
--recipe: Auth mechanism
--branch: Which branch to use when downloading from github (defaults to master)
Expand All @@ -86,8 +87,12 @@ async function run() {
--manager: Which package manager to use
--autostart: Whether the CLI should start the project after setting up
*/
const userArguments = await yargs(hideBin(process.argv)).argv;
validateUserArguments(userArguments);
const userArgumentsRaw = await yargs(hideBin(process.argv)).argv;
validateUserArguments(userArgumentsRaw);
const userArguments = {
...userArgumentsRaw,
manager: userArgumentsRaw.manager ?? inferredPackageManager() ?? "npm",
};
AnalyticsManager.sendAnalyticsEvent({
eventName: "cli_started",
});
Expand Down Expand Up @@ -176,9 +181,9 @@ async function run() {
* otherwise the user would have to manually delete the folder before
* running the CLI again
*
* NOTE: We dont do this for runProject because if running fails, the user
* NOTE: We don't do this for runProject because if running fails, the user
* can fix the error (install missing library for example) and then run the
* app again themseves without having to run and wait for the CLI to finish
* app again themselves without having to run and wait for the CLI to finish
*/
fs.rmSync(`${answers.appname}/`, {
recursive: true,
Expand Down
22 changes: 22 additions & 0 deletions lib/build/packageManager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { isValidPackageManager } from "./types.js";
import whichPMRuns from "which-pm-runs";
export function inferredPackageManager() {
const packageManager = whichPMRuns();
const packageManagerName = packageManager?.name;
if (packageManagerName && isValidPackageManager(packageManagerName)) {
return packageManagerName;
}
return undefined;
}
export function addPackageCommand(packageManager) {
switch (packageManager) {
case "bun":
return "bun add";
case "yarn":
return "yarn add";
case "pnpm":
return "pnpm add";
case "npm":
return "npm i";
}
}
2 changes: 1 addition & 1 deletion lib/build/questionUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function getDjangoPythonRunScripts() {
"python manage.py runserver",
];
}
// Converts the options array we declare to a format iquirer can use
// Converts the options array we declare to a format inquirer can use
export function mapOptionsToChoices(options) {
return options
.filter((i) => i.shouldDisplay !== false)
Expand Down
2 changes: 1 addition & 1 deletion lib/build/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export function isValidBackend(backend) {
}
return false;
}
export const allPackageManagers = ["npm", "yarn", "bun"];
export const allPackageManagers = ["npm", "yarn", "pnpm", "bun"];
export function isValidPackageManager(manager) {
if (allPackageManagers.includes(manager)) {
return true;
Expand Down
12 changes: 0 additions & 12 deletions lib/build/userArgumentUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,6 @@ export function modifyAnswersBasedOnFlags(answers, userArguments) {
}
return _answers;
}
export async function getPackageManagerCommand(userArguments) {
if (userArguments.manager === "npm") {
return "npm";
}
if (userArguments.manager === "yarn") {
return "yarn";
}
if (userArguments.manager === "bun") {
return "bun";
}
return "npm";
}
export function getShouldAutoStartFromArgs(userArguments) {
if (
userArguments.autostart !== undefined &&
Expand Down
Loading

0 comments on commit dbb41e6

Please sign in to comment.