create-tigris-app
Advanced tools
Comparing version 1.0.0-dev.5 to 1.0.1
@@ -16,9 +16,4 @@ "use strict"; | ||
const examples_1 = require("./examples"); | ||
async function createApp({ appPath, packageManager, example, clientId, clientSecret, environment, }) { | ||
const template = example ? example : "default"; | ||
const found = await (0, examples_1.existsInRepo)(template); | ||
if (!found) { | ||
console.error(`Could not locate a template named ${chalk_1.default.red(`"${template}"`)}. It could be due to the following:\n`, `1. Your spelling of template ${chalk_1.default.red(`"${template}"`)} might be incorrect.\n`, `2. You might not be connected to the internet or you are behind a proxy.`); | ||
process.exit(1); | ||
} | ||
const package_json_1 = require("./package-json"); | ||
async function createAppDir(appPath) { | ||
const root = path_1.default.resolve(appPath); | ||
@@ -35,8 +30,14 @@ if (!(await (0, is_writeable_1.isWriteable)(path_1.default.dirname(root)))) { | ||
} | ||
const useYarn = packageManager === "yarn"; | ||
const isOnline = !useYarn || (await (0, is_online_1.getOnline)()); | ||
const originalDirectory = process.cwd(); | ||
console.log(`Creating a new app in ${chalk_1.default.green(root)}.`); | ||
console.log(); | ||
process.chdir(root); | ||
return { root, appName }; | ||
} | ||
async function downloadExample({ originalDirectory, appPath, template, packageManager, isOnline, clientId, clientSecret, uri, databaseBranch, }) { | ||
const found = await (0, examples_1.existsInRepo)(template); | ||
if (!found) { | ||
console.error(`Could not locate a template named ${chalk_1.default.red(`"${template}"`)}. It could be due to the following:\n`, `1. Your spelling of template ${chalk_1.default.red(`"${template}"`)} might be incorrect.\n`, `2. You might not be connected to the internet or you are behind a proxy.`); | ||
process.exit(1); | ||
} | ||
const { appName, root } = await createAppDir(appPath); | ||
/** | ||
@@ -54,3 +55,4 @@ * If an example repository is not provided for cloning, proceed | ||
clientSecret, | ||
environment, | ||
uri, | ||
databaseBranch, | ||
}); | ||
@@ -69,8 +71,9 @@ if ((0, git_1.tryGitInit)(root)) { | ||
console.log(`\n${chalk_1.default.green("Success!")} Created ${appName} at ${appPath}\n`); | ||
const isYarn = packageManager === "yarn"; | ||
console.log("Inside that directory, you can run several commands:"); | ||
console.log(); | ||
console.log(chalk_1.default.cyan(` ${packageManager} ${useYarn ? "" : "run "}dev`)); | ||
console.log(chalk_1.default.cyan(` ${packageManager} ${isYarn ? "" : "run "}dev`)); | ||
console.log(" Starts the development server."); | ||
console.log(); | ||
console.log(chalk_1.default.cyan(` ${packageManager} ${useYarn ? "" : "run "}build`)); | ||
console.log(chalk_1.default.cyan(` ${packageManager} ${isYarn ? "" : "run "}build`)); | ||
console.log(" Builds the app for production."); | ||
@@ -84,5 +87,73 @@ console.log(); | ||
console.log(chalk_1.default.cyan(" cd"), cdpath); | ||
console.log(` ${chalk_1.default.cyan(`${packageManager} ${useYarn ? "" : "run "}dev`)}`); | ||
console.log(` ${chalk_1.default.cyan(`${packageManager} ${isYarn ? "" : "run "}dev`)}`); | ||
console.log(); | ||
} | ||
async function cloneRepo({ appPath, gitUrl, packageManager, isOnline, clientId, clientSecret, uri, databaseBranch, }) { | ||
if ((0, git_1.gitInstalled)() === false) { | ||
console.error("git must be installed in order to create an application from a template using a Git URL"); | ||
process.exit(1); | ||
} | ||
const { appName, root } = await createAppDir(appPath); | ||
console.log(`Downloading ${chalk_1.default.cyan(gitUrl)}. This might take a moment.`); | ||
console.log(); | ||
const cloneSuccess = (0, git_1.gitClone)(root, gitUrl); | ||
if (cloneSuccess === false) { | ||
console.error("A problem occurred cloning the Git repo"); | ||
process.exit(1); | ||
} | ||
await (0, package_json_1.setupDependencies)({ | ||
appName, | ||
root, | ||
packageManager, | ||
isOnline, | ||
}); | ||
(0, template_1.installEnv)({ | ||
root, | ||
uri: uri, | ||
project: appName, | ||
clientId: clientId, | ||
clientSecret: clientSecret, | ||
databaseBranch: databaseBranch, | ||
}); | ||
(0, git_1.tryRemoveGit)(root); | ||
if ((0, git_1.tryGitInit)(root)) { | ||
console.log("Initialized a git repository."); | ||
console.log(); | ||
} | ||
console.log(`\n${chalk_1.default.green("Success!")} Created ${appName} at ${appPath}\n`); | ||
} | ||
async function createApp({ appPath, packageManager, example, gitUrl, clientId, clientSecret, uri, databaseBranch, }) { | ||
if (gitUrl && example) { | ||
throw new Error(`A "gitUrl" and an "example" cannot both be set`); | ||
} | ||
const useYarn = packageManager === "yarn"; | ||
const isOnline = !useYarn || (await (0, is_online_1.getOnline)()); | ||
const originalDirectory = process.cwd(); | ||
if (gitUrl) { | ||
await cloneRepo({ | ||
appPath, | ||
clientId, | ||
clientSecret, | ||
uri, | ||
databaseBranch, | ||
isOnline, | ||
packageManager, | ||
gitUrl: gitUrl, | ||
}); | ||
} | ||
else { | ||
const template = example ? example : template_1.DEFAULT_TEMPLATE; | ||
await downloadExample({ | ||
originalDirectory, | ||
appPath, | ||
clientId, | ||
clientSecret, | ||
uri, | ||
databaseBranch, | ||
isOnline, | ||
packageManager, | ||
template, | ||
}); | ||
} | ||
} | ||
exports.createApp = createApp; |
@@ -26,3 +26,3 @@ "use strict"; | ||
catch { | ||
return isUrlOk(`https://api.github.com/repos/tigrisdata/create-tigris-app/contents/templates/${encodeURIComponent(nameOrUrl)}`); | ||
return isUrlOk(`https://api.github.com/repos/tigrisdata/tigris-examples-ts/contents/${encodeURIComponent(nameOrUrl)}`); | ||
} | ||
@@ -40,8 +40,8 @@ } | ||
} | ||
const tempFile = await downloadTar("https://codeload.github.com/tigrisdata/create-tigris-app/tar.gz/main"); | ||
const tempFile = await downloadTar("https://codeload.github.com/tigrisdata/tigris-examples-ts/tar.gz/main"); | ||
await tar_1.default.x({ | ||
file: tempFile, | ||
cwd: root, | ||
strip: 3, | ||
filter: (p) => p.includes(`create-tigris-app-main/templates/${name}/`), | ||
strip: 2, | ||
filter: (p) => p.includes(`tigris-examples-ts-main/${name}/`), | ||
}); | ||
@@ -48,0 +48,0 @@ await fs_1.promises.unlink(tempFile); |
@@ -6,3 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.tryGitInit = void 0; | ||
exports.gitClone = exports.tryRemoveGit = exports.tryGitInit = exports.gitInstalled = void 0; | ||
const child_process_1 = require("child_process"); | ||
@@ -27,2 +27,12 @@ const path_1 = __importDefault(require("path")); | ||
} | ||
function gitInstalled() { | ||
try { | ||
(0, child_process_1.execSync)("git --version", { stdio: "ignore" }); | ||
return true; | ||
} | ||
catch (_) { | ||
return false; | ||
} | ||
} | ||
exports.gitInstalled = gitInstalled; | ||
function tryGitInit(root) { | ||
@@ -46,6 +56,3 @@ let didInit = false; | ||
if (didInit) { | ||
try { | ||
rimraf_1.default.sync(path_1.default.join(root, ".git")); | ||
} | ||
catch (_) { } | ||
tryRemoveGit(root); | ||
} | ||
@@ -56,1 +63,21 @@ return false; | ||
exports.tryGitInit = tryGitInit; | ||
function tryRemoveGit(root) { | ||
try { | ||
rimraf_1.default.sync(path_1.default.join(root, ".git")); | ||
return true; | ||
} | ||
catch (_) { | ||
return false; | ||
} | ||
} | ||
exports.tryRemoveGit = tryRemoveGit; | ||
function gitClone(root, gitUrl) { | ||
try { | ||
(0, child_process_1.execSync)(`git clone --depth=1 ${gitUrl} ${root}`, { stdio: "ignore" }); | ||
return true; | ||
} | ||
catch (_) { | ||
return false; | ||
} | ||
} | ||
exports.gitClone = gitClone; |
@@ -17,3 +17,3 @@ "use strict"; | ||
const packageJson = JSON.parse(jsonString.toString()); | ||
packageJson["name"] = appName; | ||
packageJson["name"] = appName.toLowerCase(); | ||
/** | ||
@@ -20,0 +20,0 @@ * Write it to disk. |
@@ -6,3 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.installTemplate = exports.installEnv = exports.validTemplate = exports.TEMPLATES = exports.ENVIRONMENTS = void 0; | ||
exports.installTemplate = exports.installEnv = exports.validTemplate = exports.TEMPLATES = exports.DEFAULT_TEMPLATE = exports.TEMPLATE_FROM_GIT_URI = void 0; | ||
const package_json_1 = require("./package-json"); | ||
@@ -15,4 +15,12 @@ const examples_1 = require("./examples"); | ||
const path_1 = __importDefault(require("path")); | ||
exports.ENVIRONMENTS = ["dev", "preview"]; | ||
exports.TEMPLATES = ["default", "nextjs-api-routes", "rest-express"]; | ||
exports.TEMPLATE_FROM_GIT_URI = "Create an app from a Git repo"; | ||
exports.DEFAULT_TEMPLATE = "rest-express"; | ||
exports.TEMPLATES = [ | ||
"playground", | ||
"nextjs-api-routes", | ||
exports.DEFAULT_TEMPLATE, | ||
"rest-search-express", | ||
"vector-search-openai", | ||
exports.TEMPLATE_FROM_GIT_URI, | ||
]; | ||
/** | ||
@@ -28,19 +36,41 @@ * Validates that the template is one of the supported ones. | ||
*/ | ||
const installEnv = ({ root, project, clientId, clientSecret, environment, }) => { | ||
const parsedEnv = environment | ||
? exports.ENVIRONMENTS.includes(environment) | ||
? environment | ||
: "preview" | ||
: "preview"; | ||
const envContent = `TIGRIS_URI=api.${parsedEnv}.tigrisdata.cloud | ||
const installEnv = ({ root, project, clientId, clientSecret, uri, databaseBranch, }) => { | ||
const envExamplePath = path_1.default.join(root, ".env.example"); | ||
const envPath = path_1.default.join(root, ".env"); | ||
let envContent = ""; | ||
if (fs_1.default.existsSync(envExamplePath) === false) { | ||
// No example file to base the .env file from | ||
envContent = `TIGRIS_URI=${uri} | ||
TIGRIS_PROJECT=${project} | ||
TIGRIS_CLIENT_ID=${clientId} | ||
TIGRIS_CLIENT_SECRET=${clientSecret}`; | ||
fs_1.default.writeFileSync(path_1.default.join(root, ".env"), envContent + os_1.default.EOL); | ||
TIGRIS_CLIENT_SECRET=${clientSecret} | ||
TIGRIS_DB_BRANCH=${databaseBranch}${os_1.default.EOL}`; | ||
} | ||
else { | ||
// .env.example exists, so: | ||
// 1. replace any template variables in the form `{VARIABLE_NAME}` with value | ||
// 2. append an environment variable if a template variable does not exist | ||
envContent = fs_1.default.readFileSync(envExamplePath, "utf-8"); | ||
envContent = replaceOrAppend(envContent, "TIGRIS_URI", `${uri}`); | ||
envContent = replaceOrAppend(envContent, "TIGRIS_PROJECT", project); | ||
envContent = replaceOrAppend(envContent, "TIGRIS_CLIENT_ID", clientId); | ||
envContent = replaceOrAppend(envContent, "TIGRIS_CLIENT_SECRET", clientSecret); | ||
envContent = replaceOrAppend(envContent, "TIGRIS_DB_BRANCH", databaseBranch); | ||
} | ||
fs_1.default.writeFileSync(envPath, `${envContent}${os_1.default.EOL}`); | ||
}; | ||
exports.installEnv = installEnv; | ||
function replaceOrAppend(content, envVarName, envVarValue) { | ||
if (content.includes(`{${envVarName}}`)) { | ||
content = content.replace(`{${envVarName}}`, envVarValue); | ||
} | ||
else { | ||
content += `${os_1.default.EOL}${envVarName}=${envVarValue}`; | ||
} | ||
return content; | ||
} | ||
/** | ||
* Install a template to a given `root` directory. | ||
*/ | ||
const installTemplate = async ({ appName, root, packageManager, isOnline, template, clientId, clientSecret, environment, }) => { | ||
const installTemplate = async ({ appName, root, packageManager, isOnline, template, clientId, clientSecret, uri, databaseBranch, }) => { | ||
console.log(`Downloading files for example ${chalk_1.default.cyan(template)}. This might take a moment.`); | ||
@@ -79,8 +109,9 @@ console.log(); | ||
root, | ||
environment: environment, | ||
uri: uri, | ||
project: appName, | ||
clientId: clientId, | ||
clientSecret: clientSecret, | ||
databaseBranch: databaseBranch, | ||
}); | ||
}; | ||
exports.installTemplate = installTemplate; |
@@ -9,3 +9,3 @@ "use strict"; | ||
function validateNpmName(name) { | ||
const nameValidation = (0, validate_npm_package_name_1.default)(name); | ||
const nameValidation = (0, validate_npm_package_name_1.default)(name.toLowerCase()); | ||
if (nameValidation.validForNewPackages) { | ||
@@ -12,0 +12,0 @@ return { valid: true }; |
@@ -19,7 +19,7 @@ #!/usr/bin/env node | ||
let projectPath = ""; | ||
let templateName; | ||
let templateNameOrGitUrl; | ||
let clientId; | ||
let clientSecret; | ||
let uri; | ||
let packageManager; | ||
let environment; | ||
const program = new commander_1.default.Command(package_json_1.default.name) | ||
@@ -47,4 +47,4 @@ .version(package_json_1.default.version) | ||
`) | ||
.option(`-E, --env [${template_1.ENVIRONMENTS.join(", ")}]`, ` | ||
The environment where the project will be created | ||
.option("-u, --uri [uri]", ` | ||
The uri project will use to connect to Tigris | ||
`) | ||
@@ -54,6 +54,6 @@ .allowUnknownOption() | ||
projectPath = options.project; | ||
templateName = options.example; | ||
templateNameOrGitUrl = options.example; | ||
clientId = options.clientId; | ||
clientSecret = options.clientSecret; | ||
environment = options.env; | ||
uri = options.uri; | ||
packageManager = !!options.useNpm | ||
@@ -103,2 +103,19 @@ ? "npm" | ||
} | ||
// set up the uri | ||
if (!uri) { | ||
const res = await (0, prompts_1.default)({ | ||
type: "text", | ||
name: "uri", | ||
message: "What is the URI?", | ||
validate: (name) => { | ||
if (typeof name === "string" && name.trim().length > 0) { | ||
return true; | ||
} | ||
return "The uri cannot be empty"; | ||
}, | ||
}); | ||
if (typeof res.uri === "string") { | ||
uri = res.uri.trim(); | ||
} | ||
} | ||
// set up the clientId and clientSecret | ||
@@ -144,4 +161,7 @@ if (!clientId) { | ||
} | ||
// set up the template | ||
if (!templateName) { | ||
// set up the template or GitHub URL | ||
let gitUrl = isUrl(templateNameOrGitUrl) | ||
? templateNameOrGitUrl | ||
: undefined; | ||
if (!templateNameOrGitUrl) { | ||
const res = await (0, prompts_1.default)({ | ||
@@ -159,11 +179,23 @@ type: "autocomplete", | ||
if (typeof res.template === "string") { | ||
templateName = res.template.trim(); | ||
templateNameOrGitUrl = res.template.trim(); | ||
} | ||
} | ||
if (templateName) { | ||
templateName = templateName.trim(); | ||
if (!(0, template_1.validTemplate)(templateName)) { | ||
if (templateNameOrGitUrl === template_1.TEMPLATE_FROM_GIT_URI) { | ||
const res = (0, prompts_1.default)({ | ||
type: "text", | ||
name: "gitUrl", | ||
message: "Please enter a valid Git URL", | ||
validate: (value) => { | ||
return isUrl(value); | ||
}, | ||
}); | ||
gitUrl = (await res).gitUrl; | ||
} | ||
if (!gitUrl && templateNameOrGitUrl) { | ||
templateNameOrGitUrl = templateNameOrGitUrl.trim(); | ||
if (!(0, template_1.validTemplate)(templateNameOrGitUrl)) { | ||
console.error("\nPlease specify one of the supported templates\n" + | ||
"For example:\n" + | ||
` --example [${template_1.TEMPLATES.join(", ")}]\n\n` + | ||
"Examples:\n" + | ||
` --example [${template_1.TEMPLATES.filter((value) => value !== template_1.TEMPLATE_FROM_GIT_URI).join(", ")}]\n\n` + | ||
` --example https://github.com/tigrisdata-community/tigris-mongodb-typescript-example.git\n\n` + | ||
`Run ${chalk_1.default.cyan(`${program.name()} --help`)} to see all options.`); | ||
@@ -173,11 +205,20 @@ process.exit(1); | ||
} | ||
// for now we default the database branch to "main" | ||
const databaseBranch = "main"; | ||
await (0, create_app_1.createApp)({ | ||
appPath: resolvedProjectPath, | ||
packageManager, | ||
example: templateName && templateName !== "default" ? templateName : undefined, | ||
example: !gitUrl ? templateNameOrGitUrl : undefined, | ||
gitUrl: gitUrl, | ||
clientId, | ||
clientSecret, | ||
environment, | ||
uri, | ||
databaseBranch, | ||
}); | ||
} | ||
function isUrl(value) { | ||
if (!value) | ||
return false; | ||
return value.startsWith("https://") || value.startsWith("git@"); | ||
} | ||
const update = (0, update_check_1.default)(package_json_1.default).catch(() => null); | ||
@@ -184,0 +225,0 @@ async function notifyUpdate() { |
{ | ||
"name": "create-tigris-app", | ||
"version": "1.0.0-dev.5", | ||
"version": "1.0.1", | ||
"keywords": [ | ||
"database", | ||
"nosql", | ||
"tigris", | ||
"starter" | ||
"starter", | ||
"search", | ||
"vector search" | ||
], | ||
"description": "Utility to create typescript application to interact with Tigris database", | ||
"description": "Utility to create applications to interact with Tigris, the open source developer data platform MongoDB alternative", | ||
"repository": "github:tigrisdata/create-tigris-app", | ||
@@ -11,0 +14,0 @@ "author": "Tigris team <support@tigrisdata.com>", |
{ | ||
"name": "create-tigris-app", | ||
"version": "1.0.0-dev.5", | ||
"version": "1.0.1", | ||
"keywords": [ | ||
"database", | ||
"nosql", | ||
"tigris", | ||
"starter" | ||
"starter", | ||
"search", | ||
"vector search" | ||
], | ||
"description": "Utility to create typescript application to interact with Tigris database", | ||
"description": "Utility to create applications to interact with Tigris, the open source developer data platform MongoDB alternative", | ||
"repository": "github:tigrisdata/create-tigris-app", | ||
@@ -11,0 +14,0 @@ "author": "Tigris team <support@tigrisdata.com>", |
# Create Tigris App | ||
The easiest way to get started with Tigris is by using `create-tigris-app`. | ||
This CLI tool enables you to quickly start building a new application with | ||
The simplest way to get started with Tigris is by using `create-tigris-app`. | ||
This CLI tool lets you quickly start building a new application with | ||
Tigris as the backend. You can create a new app using one of the templates. | ||
@@ -27,2 +27,3 @@ | ||
Initializing project with template: nextjs-api-routes | ||
@@ -34,11 +35,12 @@ | ||
- @next/font: ^13.0.6 | ||
- @tigrisdata/core: 1.0.0-dev.1 | ||
- @tigrisdata/core: latest | ||
- next: ^13.0.6 | ||
- react: ^18.2.0 | ||
- react-dom: ^18.2.0 | ||
- reflect-metadata: ^0.1.13 | ||
added 302 packages, and audited 303 packages in 13s | ||
added 314 packages, and audited 315 packages in 6s | ||
88 packages are looking for funding | ||
91 packages are looking for funding | ||
run `npm fund` for details | ||
@@ -49,2 +51,3 @@ | ||
Success! Created myapp at /Users/ovaistariq/projects/myapp | ||
@@ -65,3 +68,3 @@ | ||
cd /Users/ovaistariq/projects/myapp | ||
cd myapp | ||
npm run dev | ||
@@ -104,3 +107,3 @@ ``` | ||
[](https://www.npmjs.com/package/create-tigris-app) | ||
[](https://tigrisdata.slack.com) | ||
[](https://www.tigrisdata.com/discord) | ||
[](https://github.com/tigrisdata/create-tigris-app/blob/main/LICENSE) |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
53800
993
1
105