@embeddable.com/init 0.0.4 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +124 -1
- package/package.json +8 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,127 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/index.ts
|
|
4
|
-
|
|
4
|
+
import { execSync } from "child_process";
|
|
5
|
+
import fs from "fs";
|
|
6
|
+
import path from "path";
|
|
7
|
+
import chalk from "chalk";
|
|
8
|
+
import degit from "degit";
|
|
9
|
+
import prompts from "prompts";
|
|
10
|
+
var REPO_URL = "embeddable-hq/remarkable-pro-boilerplate";
|
|
11
|
+
var DEFAULT_FOLDER = "embeddable-repo";
|
|
12
|
+
var SIGNUP_URLS = {
|
|
13
|
+
US: "https://app.us.embeddable.com/auth/login?screen_hint=signup",
|
|
14
|
+
EU: "https://app.eu.embeddable.com/auth/login?screen_hint=signup"
|
|
15
|
+
};
|
|
16
|
+
function exit(message) {
|
|
17
|
+
if (message) console.log(message);
|
|
18
|
+
process.exit(0);
|
|
19
|
+
}
|
|
20
|
+
async function main() {
|
|
21
|
+
prompts.override({ onCancel: () => exit("\nSetup cancelled.\n") });
|
|
22
|
+
console.log(chalk.bold("\nWelcome to Embeddable!\n"));
|
|
23
|
+
const cwd = process.cwd();
|
|
24
|
+
const { confirmDir } = await prompts({
|
|
25
|
+
type: "confirm",
|
|
26
|
+
name: "confirmDir",
|
|
27
|
+
message: `Create a new project in ${chalk.cyan(cwd)}?`,
|
|
28
|
+
initial: true
|
|
29
|
+
});
|
|
30
|
+
if (confirmDir === void 0) {
|
|
31
|
+
exit("\nSetup cancelled.\n");
|
|
32
|
+
}
|
|
33
|
+
if (!confirmDir) {
|
|
34
|
+
exit("\nRun this command from the directory where you'd like to create your project.\n");
|
|
35
|
+
}
|
|
36
|
+
const { folderName } = await prompts({
|
|
37
|
+
type: "text",
|
|
38
|
+
name: "folderName",
|
|
39
|
+
message: "Project folder name:",
|
|
40
|
+
initial: DEFAULT_FOLDER,
|
|
41
|
+
validate: (value) => {
|
|
42
|
+
if (!value.trim()) return "Folder name is required";
|
|
43
|
+
if (fs.existsSync(path.join(cwd, value))) {
|
|
44
|
+
return `Folder "${value}" already exists`;
|
|
45
|
+
}
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
if (!folderName) {
|
|
50
|
+
exit("\nSetup cancelled.\n");
|
|
51
|
+
}
|
|
52
|
+
const projectPath = path.join(cwd, folderName);
|
|
53
|
+
console.log(chalk.dim("\nDownloading boilerplate..."));
|
|
54
|
+
try {
|
|
55
|
+
const emitter = degit(REPO_URL, { cache: false, force: true });
|
|
56
|
+
await emitter.clone(projectPath);
|
|
57
|
+
} catch (error) {
|
|
58
|
+
if (fs.existsSync(projectPath)) {
|
|
59
|
+
fs.rmSync(projectPath, { recursive: true });
|
|
60
|
+
}
|
|
61
|
+
const message = error instanceof Error ? error.message : "Unknown error";
|
|
62
|
+
console.error(chalk.red(`
|
|
63
|
+
Failed to download boilerplate: ${message}
|
|
64
|
+
`));
|
|
65
|
+
process.exit(1);
|
|
66
|
+
}
|
|
67
|
+
try {
|
|
68
|
+
execSync("git init", { cwd: projectPath, stdio: "ignore" });
|
|
69
|
+
} catch {
|
|
70
|
+
console.log(
|
|
71
|
+
chalk.yellow("\nWarning: Could not initialize git repository. Is git installed?")
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
const { region: selectedRegion } = await prompts({
|
|
75
|
+
type: "select",
|
|
76
|
+
name: "region",
|
|
77
|
+
message: "Select your region:",
|
|
78
|
+
choices: [
|
|
79
|
+
{ title: "US", value: "US" },
|
|
80
|
+
{ title: "EU", value: "EU" }
|
|
81
|
+
],
|
|
82
|
+
initial: 0
|
|
83
|
+
});
|
|
84
|
+
if (!selectedRegion) {
|
|
85
|
+
exit("\nSetup cancelled.\n");
|
|
86
|
+
}
|
|
87
|
+
const region = selectedRegion;
|
|
88
|
+
if (region === "EU") {
|
|
89
|
+
const configPath = path.join(projectPath, "embeddable.config.ts");
|
|
90
|
+
if (!fs.existsSync(configPath)) {
|
|
91
|
+
console.log(
|
|
92
|
+
chalk.yellow("\nWarning: Could not find embeddable.config.ts to set region.")
|
|
93
|
+
);
|
|
94
|
+
} else {
|
|
95
|
+
let configContent = fs.readFileSync(configPath, "utf-8");
|
|
96
|
+
const originalContent = configContent;
|
|
97
|
+
configContent = configContent.replace(
|
|
98
|
+
/^(\s*)region:\s*["']US["'],?/m,
|
|
99
|
+
"$1// region: 'US',"
|
|
100
|
+
);
|
|
101
|
+
configContent = configContent.replace(
|
|
102
|
+
/^(\s*)\/\/\s*region:\s*["']EU["'],?/m,
|
|
103
|
+
"$1region: 'EU',"
|
|
104
|
+
);
|
|
105
|
+
if (configContent === originalContent) {
|
|
106
|
+
console.log(
|
|
107
|
+
chalk.yellow("\nWarning: Could not update region in config file. Please set it manually.")
|
|
108
|
+
);
|
|
109
|
+
} else {
|
|
110
|
+
fs.writeFileSync(configPath, configContent);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
console.log(chalk.green(`
|
|
115
|
+
\u2713 Created ${chalk.bold(folderName)}!
|
|
116
|
+
`));
|
|
117
|
+
console.log("Next steps:\n");
|
|
118
|
+
console.log(chalk.cyan(` cd ${folderName}`));
|
|
119
|
+
console.log(chalk.cyan(" npm install"));
|
|
120
|
+
console.log(chalk.cyan(" npm run dev\n"));
|
|
121
|
+
console.log(`Sign up at: ${chalk.underline(SIGNUP_URLS[region])}
|
|
122
|
+
`);
|
|
123
|
+
}
|
|
124
|
+
main().catch((error) => {
|
|
125
|
+
console.error(chalk.red("An unexpected error occurred:"), error);
|
|
126
|
+
process.exit(1);
|
|
127
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@embeddable.com/init",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "CLI tool for Embeddable",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -22,7 +22,14 @@
|
|
|
22
22
|
"engines": {
|
|
23
23
|
"node": ">=20"
|
|
24
24
|
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"chalk": "^5.3.0",
|
|
27
|
+
"degit": "^2.8.4",
|
|
28
|
+
"prompts": "^2.4.2"
|
|
29
|
+
},
|
|
25
30
|
"devDependencies": {
|
|
31
|
+
"@types/degit": "^2.8.6",
|
|
32
|
+
"@types/prompts": "^2.4.9",
|
|
26
33
|
"tsup": "^8.0.0",
|
|
27
34
|
"typescript": "^5.0.0"
|
|
28
35
|
}
|