Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@tobiastengler/create-relay-app

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tobiastengler/create-relay-app - npm Package Compare versions

Comparing version 2.0.0 to 2.1.0

dist/tasks/AddRelayCompilerScriptsTask.js

34

dist/bin.js

@@ -7,3 +7,3 @@ #!/usr/bin/env node

import { ArgumentHandler, ArtifactDirectoryArgument, PackageManagerArgument, SchemaFileArgument, SrcArgument, ToolchainArgument, TypeScriptArgument, SubscriptionsArgument, } from "./arguments/index.js";
import { BABEL_RELAY_MACRO, PACKAGE_FILE } from "./consts.js";
import { BABEL_RELAY_MACRO, GITHUB_CODE_URL, PACKAGE_FILE } from "./consts.js";
import { Filesystem } from "./misc/Filesystem.js";

@@ -17,2 +17,3 @@ import { getPackageManger, getExecutingPackageManager } from "./misc/packageManagers/index.js";

import { CommandRunner } from "./misc/CommandRunner.js";
import { AddRelayCompilerScriptsTask } from "./tasks/AddRelayCompilerScriptsTask.js";
const fs = new Filesystem();

@@ -65,4 +66,3 @@ const cmdRunner = new CommandRunner();

]);
const git = new Git();
const isGitRepo = await git.isGitRepository(env.cwd);
let isGitRepo = false;
let userArgs;

@@ -72,9 +72,16 @@ try {

const cliArgs = await argumentHandler.parseArgs(env);
if (isGitRepo && !cliArgs.ignoreGitChanges) {
const hasUnsavedChanges = await git.hasUnsavedChanges(env.cwd);
if (hasUnsavedChanges) {
printError(`Please commit or discard all changes in the ${bold(env.cwd)} directory before continuing.`);
exit(1);
try {
const git = new Git();
isGitRepo = await git.isGitRepository(env.cwd);
if (isGitRepo && !cliArgs.ignoreGitChanges) {
const hasUnsavedChanges = await git.hasUnsavedChanges(env.cwd);
if (hasUnsavedChanges) {
printError(`Please commit or discard all changes in the ${bold(env.cwd)} directory before continuing.`);
exit(1);
}
}
}
catch (_a) {
// We just ignore it if something goes wrong in the git detection.
}
// Prompt for all of the missing arguments, required to execute the program.

@@ -105,6 +112,7 @@ userArgs = await argumentHandler.resolveMissingArgs(cliArgs);

new ConfigureRelayCompilerTask(context),
new AddRelayCompilerScriptsTask(context),
new GenerateRelayEnvironmentTask(context),
new GenerateGraphQlSchemaFileTask(context),
new GenerateArtifactDirectoryTask(context),
isGitRepo && new ConfigureEolOfArtifactsTask(context),
new ConfigureEolOfArtifactsTask(context, isGitRepo),
new Cra_AddBabelMacroTypeDefinitionsTask(context),

@@ -122,3 +130,3 @@ new Cra_AddRelayEnvironmentProvider(context),

}
catch (_a) {
catch (_b) {
// The error should've already been correctly handled by the runner,

@@ -151,3 +159,3 @@ // we just exit the program here.

console.log("If you do not want to use the macro, you can check out the following document for guidance:");
console.log("https://github.com/tobias-tengler/create-relay-app/blob/main/docs/cra-babel-setup.md");
console.log(GITHUB_CODE_URL + "/docs/cra-babel-setup.md");
}

@@ -158,5 +166,5 @@ if (context.is("next")) {

console.log();
console.log(`Follow this guide, if you want to fetch data on the server instead of the client:`);
console.log("https://github.com/tobias-tengler/create-relay-app/blob/main/docs/next-data-fetching.md");
console.log(`Follow this guide, if you want to fetch data on the server instead of on the client:`);
console.log(GITHUB_CODE_URL + "/docs/next-data-fetching.md");
}
console.log();

@@ -15,1 +15,2 @@ export const TS_CONFIG_FILE = "tsconfig.json";

export const RELAY_ENV = "RelayEnvironment";
export const GITHUB_CODE_URL = "https://github.com/tobias-tengler/create-relay-app/blob/main";
import path from "path";
import { NEXT_SRC_PATH, RELAY_ENV } from "../consts.js";
import { NEXT_SRC_PATH, PACKAGE_FILE, RELAY_ENV } from "../consts.js";
export class ProjectContext {

@@ -23,2 +23,8 @@ constructor(env, args, manager, fs) {

}
get relayConfigFile() {
return this.env.rel("relay.config.json");
}
get ownPackageJsonFile() {
return this.env.rel(PACKAGE_FILE);
}
get artifactExtension() {

@@ -25,0 +31,0 @@ if (this.args.typescript) {

@@ -5,9 +5,10 @@ import { EOL } from "os";

export class ConfigureEolOfArtifactsTask extends TaskBase {
constructor(context) {
constructor(context, isGitRepo) {
super();
this.context = context;
this.message = "Configure Relay artifact EOL";
this.isGitRepo = isGitRepo;
this.message = "Configure Relay artifact EOL in .gitattributes";
}
isEnabled() {
return true;
return this.isGitRepo;
}

@@ -14,0 +15,0 @@ async run() {

import { TaskBase } from "./TaskBase.js";
import { PACKAGE_FILE } from "../consts.js";
import { bold } from "../utils/cli.js";
const validateRelayArtifactsScript = "relay-compiler --validate";
export class ConfigureRelayCompilerTask extends TaskBase {

@@ -9,3 +7,3 @@ constructor(context) {

this.context = context;
this.message = `Configure ${bold("relay-compiler")} in ${bold(PACKAGE_FILE)}`;
this.message = `Configure ${bold("relay-compiler")}`;
}

@@ -16,19 +14,18 @@ isEnabled() {

async run() {
var _a, _b;
const packageJson = await this.context.env.packageJson.parse();
const scriptsSection = (_a = packageJson["scripts"]) !== null && _a !== void 0 ? _a : {};
if (!scriptsSection["relay"]) {
// Add "relay" script
scriptsSection["relay"] = "relay-compiler";
this.updateMessage(this.message + ` in ${bold(this.context.relayConfigFile.rel)}`);
let relayConfig;
try {
const relayConfigContent = await this.context.fs.readFromFile(this.context.relayConfigFile.abs);
relayConfig = JSON.parse(relayConfigContent) || {};
}
const buildScript = scriptsSection["build"];
if (buildScript && typeof buildScript === "string" && !buildScript.includes(validateRelayArtifactsScript)) {
// There is an existing build script.
scriptsSection["build"] = validateRelayArtifactsScript + " && " + buildScript;
catch (_a) {
relayConfig = {};
}
const relaySection = ((_b = packageJson["relay"]) !== null && _b !== void 0 ? _b : {});
relaySection["src"] = this.context.srcPath.rel;
relaySection["language"] = this.context.compilerLanguage;
relaySection["schema"] = this.context.schemaPath.rel;
relaySection["exclude"] = ["**/node_modules/**", "**/__mocks__/**", "**/__generated__/**"];
relayConfig["src"] = this.context.srcPath.rel;
relayConfig["language"] = this.context.compilerLanguage;
relayConfig["schema"] = this.context.schemaPath.rel;
if (!relayConfig["exclude"]) {
// We only want to add this, if the user hasn't already specified it.
relayConfig["exclude"] = ["**/node_modules/**", "**/__mocks__/**", "**/__generated__/**"];
}
if (this.context.is("vite")) {

@@ -38,10 +35,10 @@ // When generating without eagerEsModules artifacts contain

// eagerEsModules will output export default.
relaySection["eagerEsModules"] = true;
relayConfig["eagerEsModules"] = true;
}
if (this.context.artifactPath) {
relaySection["artifactDirectory"] = this.context.artifactPath.rel;
relayConfig["artifactDirectory"] = this.context.artifactPath.rel;
}
packageJson["relay"] = relaySection;
this.context.env.packageJson.persist(packageJson);
const relayConfigWriteContent = JSON.stringify(relayConfig, null, 2);
await this.context.fs.writeToFile(this.context.relayConfigFile.abs, relayConfigWriteContent);
}
}

@@ -55,3 +55,3 @@ import { TaskBase } from "./TaskBase.js";

headers: {
Accept: "application/json",
Accept: "application/graphql-response+json; charset=utf-8, application/json; charset=utf-8",
"Content-Type": "application/json",

@@ -86,3 +86,3 @@ // <-- Additional headers like 'Authorization' would go here

subscribeFn = (request, variables) => {
// To understand why we return Observable<any>,
// To understand why we return Observable.create<any>,
// please see: https://github.com/enisdenjo/graphql-ws/issues/316#issuecomment-1047605774

@@ -89,0 +89,0 @@ return Observable.create<any>((sink) => {

{
"name": "@tobiastengler/create-relay-app",
"version": "v2.0.0",
"version": "v2.1.0",
"description": "Easy configuration of Relay for existing projects",

@@ -39,2 +39,3 @@ "homepage": "https://github.com/tobias-tengler/create-relay-app#readme",

"start": "tsc --watch",
"test": "jest",
"format": "prettier --write ./src/**/*.ts"

@@ -49,5 +50,8 @@ },

"@types/inquirer": "^9.0.0",
"@types/jest": "^29.2.4",
"@types/node": "^18.6.5",
"@types/ora": "^3.2.0",
"@types/prettier": "^2.7.0",
"jest": "^29.3.1",
"ts-jest": "^29.0.3",
"typescript": "^4.7.4"

@@ -54,0 +58,0 @@ },

@@ -35,5 +35,5 @@ <h1 align="center" style="font-size: 30px;">create-relay-app</h1>

1. Scaffold a new project using the toolchain of your choice (as long as [it's supported](#supported-toolchains))
- Next.js: `npm/yarn/pnpm create next-app --typescript`
- Vite.js: `npm/yarn/pnpm create vite --template react-ts`
- Create React App: `npm/yarn/pnpm create react-app <project-name> --template typescript`
- [Next.js](https://nextjs.org/docs#automatic-setup)
- [Vite.js](https://vitejs.dev/guide/#scaffolding-your-first-vite-project)
- [Create React App](https://create-react-app.dev/docs/getting-started)
2. If you are inside a Git repository, ensure your working directory is clean, by commiting or discarding any changes.

@@ -43,3 +43,3 @@ 3. Run the script inside of the scaffolded directory:

```bash
npm/yarn/pnpm create @tobiastengler/relay-app@latest
npm/yarn/pnpm create @tobiastengler/relay-app
```

@@ -54,5 +54,11 @@

```bash
npm/yarn/pnpm create @tobiastengler/relay-app@latest [options]
npm/yarn/pnpm create @tobiastengler/relay-app [options]
```
> **Warning**
>
> npm requires you to pass `--` before any command to a starter kit, e.g.
>
> `npm create @tobiastengler/relay-app -- --interactive`.
### -h, --help

@@ -59,0 +65,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc