@project-ajax/create 0.0.0 → 0.0.1

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.mjs ADDED
@@ -0,0 +1,141 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/index.ts
4
+ import fs from "fs";
5
+ import os from "os";
6
+ import path from "path";
7
+ import chalk from "chalk";
8
+ import { execa } from "execa";
9
+ import ora from "ora";
10
+ import prompts from "prompts";
11
+ run();
12
+ async function run() {
13
+ console.log(chalk.bold.cyan("\n\u{1F680} Create a new Project Ajax worker\n"));
14
+ const { directoryName, projectName } = await prompts([
15
+ {
16
+ type: "text",
17
+ name: "directoryName",
18
+ message: "Path to the new worker project:",
19
+ initial: "."
20
+ },
21
+ {
22
+ type: "text",
23
+ name: "projectName",
24
+ message: "Project name:",
25
+ initial: "my-worker"
26
+ }
27
+ ]);
28
+ if (!directoryName || !projectName) {
29
+ console.log(chalk.red("Cancelled."));
30
+ process.exit(1);
31
+ }
32
+ const spinner = ora("Setting up template...").start();
33
+ let tempDir = null;
34
+ try {
35
+ tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "project-ajax-"));
36
+ spinner.text = "Fetching template from repository...";
37
+ await pullCode(tempDir);
38
+ spinner.text = "Preparing destination...";
39
+ const destPath = prepareDestination(directoryName);
40
+ spinner.text = "Copying template files...";
41
+ copyTemplate(tempDir, destPath);
42
+ spinner.text = "Customizing package.json...";
43
+ customizePackageJson(destPath, projectName);
44
+ spinner.succeed(chalk.green("Worker project created successfully!"));
45
+ printNextSteps(directoryName);
46
+ } catch (err) {
47
+ spinner.fail("Failed to create project.");
48
+ console.error(chalk.red(`
49
+ ${err.message}`));
50
+ if (err.message.includes("Permission denied") || err.message.includes("publickey")) {
51
+ console.log(
52
+ chalk.yellow("\n\u26A0\uFE0F SSH authentication failed. Make sure you have:")
53
+ );
54
+ console.log(" 1. SSH keys set up with GitHub");
55
+ console.log(" 2. Added your SSH key to your GitHub account");
56
+ console.log(
57
+ " 3. See: https://docs.github.com/en/authentication/connecting-to-github-with-ssh"
58
+ );
59
+ }
60
+ process.exit(1);
61
+ } finally {
62
+ if (tempDir) {
63
+ try {
64
+ fs.rmSync(tempDir, { recursive: true, force: true });
65
+ } catch {
66
+ }
67
+ }
68
+ }
69
+ }
70
+ async function pullCode(tempDir) {
71
+ await execa("git", ["init"], { cwd: tempDir });
72
+ await execa(
73
+ "git",
74
+ ["remote", "add", "origin", "git@github.com:makenotion/project-ajax.git"],
75
+ { cwd: tempDir }
76
+ );
77
+ await execa("git", ["config", "core.sparseCheckout", "true"], {
78
+ cwd: tempDir
79
+ });
80
+ const sparseCheckoutPath = path.join(
81
+ tempDir,
82
+ ".git",
83
+ "info",
84
+ "sparse-checkout"
85
+ );
86
+ fs.writeFileSync(sparseCheckoutPath, "packages/template/*\n");
87
+ await execa("git", ["pull", "--depth=1", "origin", "main"], {
88
+ cwd: tempDir
89
+ });
90
+ }
91
+ function prepareDestination(repoName) {
92
+ const destPath = repoName === "." ? process.cwd() : path.resolve(process.cwd(), repoName);
93
+ if (fs.existsSync(destPath)) {
94
+ const files = fs.readdirSync(destPath);
95
+ if (files.length > 0) {
96
+ throw new Error(
97
+ `Destination directory "${repoName}" is not empty. Please use an empty directory.`
98
+ );
99
+ }
100
+ } else if (repoName !== ".") {
101
+ fs.mkdirSync(destPath, { recursive: true });
102
+ }
103
+ return destPath;
104
+ }
105
+ function copyTemplate(tempDir, destPath) {
106
+ const templatePath = path.join(tempDir, "packages", "template");
107
+ const templateFiles = fs.readdirSync(templatePath);
108
+ for (const file of templateFiles) {
109
+ const srcPath = path.join(templatePath, file);
110
+ const destFilePath = path.join(destPath, file);
111
+ fs.cpSync(srcPath, destFilePath, { recursive: true });
112
+ }
113
+ }
114
+ function customizePackageJson(destPath, projectName) {
115
+ const packageJsonPath = path.join(destPath, "package.json");
116
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
117
+ packageJson.name = projectName;
118
+ fs.writeFileSync(
119
+ packageJsonPath,
120
+ `${JSON.stringify(packageJson, null, 2)}
121
+ `
122
+ );
123
+ }
124
+ function printNextSteps(directoryName) {
125
+ console.log(chalk.cyan(`
126
+ \u2728 Next steps:`));
127
+ if (directoryName === ".") {
128
+ console.log(`
129
+ ${chalk.bold("npm install")}
130
+ ${chalk.bold("npx workers auth login")}
131
+ ${chalk.bold("npx workers deploy")}
132
+ `);
133
+ } else {
134
+ console.log(`
135
+ ${chalk.bold(`cd ${directoryName}`)}
136
+ ${chalk.bold("npm install")}
137
+ ${chalk.bold("npx workers auth login")}
138
+ ${chalk.bold("npx workers deploy")}
139
+ `);
140
+ }
141
+ }
package/package.json CHANGED
@@ -1,17 +1,36 @@
1
1
  {
2
2
  "name": "@project-ajax/create",
3
- "version": "0.0.0",
3
+ "version": "0.0.1",
4
4
  "description": "Initialize a new Notion Project Ajax extensions repo.",
5
5
  "bin": {
6
- "create-ajax": "src/index.js"
6
+ "create-ajax": "dist/index.mjs"
7
+ },
8
+ "scripts": {
9
+ "build": "tsup"
10
+ },
11
+ "tsup": {
12
+ "entry": [
13
+ "src/index.ts"
14
+ ],
15
+ "splitting": false,
16
+ "sourcemap": false,
17
+ "clean": true,
18
+ "format": "esm"
7
19
  },
8
20
  "publishConfig": {
9
21
  "access": "public"
10
22
  },
23
+ "files": [
24
+ "dist/"
25
+ ],
11
26
  "dependencies": {
12
27
  "chalk": "^5.3.0",
13
28
  "execa": "^8.0.0",
14
29
  "ora": "^8.0.1",
15
30
  "prompts": "^2.4.2"
31
+ },
32
+ "devDependencies": {
33
+ "tsup": "^8.5.0",
34
+ "typescript": "^5.9.3"
16
35
  }
17
36
  }
package/CODEOWNERS DELETED
@@ -1 +0,0 @@
1
- * @makenotion/ajax-reviewers
package/src/index.js DELETED
@@ -1,200 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import fs from "node:fs";
4
- import os from "node:os";
5
- import path from "node:path";
6
- import chalk from "chalk";
7
- import { execa } from "execa";
8
- import ora from "ora";
9
- import prompts from "prompts";
10
-
11
- run();
12
-
13
- async function run() {
14
- console.log(
15
- chalk.bold.cyan("\n🚀 Create a new Project Ajax worker\n"),
16
- );
17
-
18
- const { directoryName, projectName } = await prompts([
19
- {
20
- type: "text",
21
- name: "directoryName",
22
- message: "Path to the new worker project:",
23
- initial: ".",
24
- },
25
- {
26
- type: "text",
27
- name: "projectName",
28
- message: "Project name:",
29
- initial: "my-worker",
30
- },
31
- ]);
32
-
33
- if (!directoryName || !projectName) {
34
- console.log(chalk.red("Cancelled."));
35
- process.exit(1);
36
- }
37
-
38
- const spinner = ora("Setting up template...").start();
39
-
40
- let tempDir;
41
-
42
- try {
43
- // Create a temporary directory for sparse checkout
44
- tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "project-ajax-"));
45
-
46
- spinner.text = "Fetching template from repository...";
47
- await pullCode(tempDir);
48
-
49
- spinner.text = "Preparing destination...";
50
- const destPath = prepareDestination(directoryName);
51
-
52
- spinner.text = "Copying template files...";
53
- copyTemplate(tempDir, destPath);
54
-
55
- spinner.text = "Customizing package.json...";
56
- customizePackageJson(destPath, projectName);
57
-
58
- spinner.succeed(chalk.green("Worker project created successfully!"));
59
-
60
- printNextSteps(directoryName);
61
- } catch (err) {
62
- spinner.fail("Failed to create project.");
63
- console.error(chalk.red(`\n${err.message}`));
64
-
65
- if (
66
- err.message.includes("Permission denied") ||
67
- err.message.includes("publickey")
68
- ) {
69
- console.log(
70
- chalk.yellow("\n⚠️ SSH authentication failed. Make sure you have:"),
71
- );
72
- console.log(" 1. SSH keys set up with GitHub");
73
- console.log(" 2. Added your SSH key to your GitHub account");
74
- console.log(
75
- " 3. See: https://docs.github.com/en/authentication/connecting-to-github-with-ssh",
76
- );
77
- }
78
-
79
- process.exit(1);
80
- } finally {
81
- // Clean up the temporary directory.
82
- if (tempDir) {
83
- try {
84
- fs.rmSync(tempDir, { recursive: true, force: true });
85
- } catch {
86
- // Ignore cleanup errors.
87
- }
88
- }
89
- }
90
- };
91
-
92
-
93
- /**
94
- * Pulls the template code from the repository using sparse checkout
95
- * @param tempDir Temporary directory path
96
- */
97
- async function pullCode(tempDir) {
98
- // Initialize git repo with sparse checkout
99
- await execa("git", ["init"], { cwd: tempDir });
100
- await execa(
101
- "git",
102
- ["remote", "add", "origin", "git@github.com:makenotion/project-ajax.git"],
103
- { cwd: tempDir },
104
- );
105
- await execa("git", ["config", "core.sparseCheckout", "true"], {
106
- cwd: tempDir,
107
- });
108
-
109
- // Configure sparse checkout to only get packages/template
110
- const sparseCheckoutPath = path.join(
111
- tempDir,
112
- ".git",
113
- "info",
114
- "sparse-checkout",
115
- );
116
- fs.writeFileSync(sparseCheckoutPath, "packages/template/*\n");
117
-
118
- // Pull only the template directory
119
- await execa("git", ["pull", "--depth=1", "origin", "main"], {
120
- cwd: tempDir,
121
- });
122
- }
123
-
124
- /**
125
- * Prepares and validates the destination directory
126
- * @param repoName Project name or "." for current directory
127
- * @returns The resolved destination path
128
- */
129
- function prepareDestination(repoName) {
130
- const destPath =
131
- repoName === "." ? process.cwd() : path.resolve(process.cwd(), repoName);
132
-
133
- // Check if destination has any files
134
- if (fs.existsSync(destPath)) {
135
- const files = fs.readdirSync(destPath);
136
- if (files.length > 0) {
137
- throw new Error(
138
- `Destination directory "${repoName}" is not empty. Please use an empty directory.`,
139
- );
140
- }
141
- } else if (repoName !== ".") {
142
- // Create destination directory if it doesn't exist
143
- fs.mkdirSync(destPath, { recursive: true });
144
- }
145
-
146
- return destPath;
147
- }
148
-
149
- /**
150
- * Copies template files from temporary directory to destination
151
- * @param tempDir Temporary directory path
152
- * @param destPath Destination directory path
153
- */
154
- function copyTemplate(tempDir, destPath) {
155
- const templatePath = path.join(tempDir, "packages", "template");
156
- const templateFiles = fs.readdirSync(templatePath);
157
-
158
- for (const file of templateFiles) {
159
- const srcPath = path.join(templatePath, file);
160
- const destFilePath = path.join(destPath, file);
161
- fs.cpSync(srcPath, destFilePath, { recursive: true });
162
- }
163
- }
164
-
165
- /**
166
- * Updates package.json with the project name
167
- * @param destPath Destination directory path
168
- * @param projectName Name for the project
169
- */
170
- function customizePackageJson(destPath, projectName) {
171
- const packageJsonPath = path.join(destPath, "package.json");
172
- const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
173
- packageJson.name = projectName;
174
- fs.writeFileSync(
175
- packageJsonPath,
176
- `${JSON.stringify(packageJson, null, 2)}\n`,
177
- );
178
- }
179
-
180
- /**
181
- * Prints next steps instructions
182
- * @param directoryName Directory name or "." for current directory
183
- */
184
- function printNextSteps(directoryName) {
185
- console.log(chalk.cyan(`\n✨ Next steps:`));
186
- if (directoryName === ".") {
187
- console.log(`
188
- ${chalk.bold("npm install")}
189
- ${chalk.bold("npx workers auth login")}
190
- ${chalk.bold("npx workers deploy")}
191
- `);
192
- } else {
193
- console.log(`
194
- ${chalk.bold(`cd ${directoryName}`)}
195
- ${chalk.bold("npm install")}
196
- ${chalk.bold("npx workers auth login")}
197
- ${chalk.bold("npx workers deploy")}
198
- `);
199
- }
200
- }