blok0 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/detectors.d.ts +1 -0
- package/dist/detectors.js +20 -0
- package/dist/handlers/generate.d.ts +1 -0
- package/dist/handlers/generate.js +63 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +45 -0
- package/package.json +25 -0
- package/src/detectors.ts +22 -0
- package/src/handlers/generate.ts +62 -0
- package/src/index.ts +51 -0
- package/tsconfig.json +16 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function checkEmptyDirectory(): boolean;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.checkEmptyDirectory = checkEmptyDirectory;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
function checkEmptyDirectory() {
|
|
7
|
+
const cwd = process.cwd();
|
|
8
|
+
const pkgPath = (0, path_1.join)(cwd, 'package.json');
|
|
9
|
+
const configJs = (0, path_1.join)(cwd, 'payload.config.js');
|
|
10
|
+
const configTs = (0, path_1.join)(cwd, 'payload.config.ts');
|
|
11
|
+
if ((0, fs_1.existsSync)(pkgPath)) {
|
|
12
|
+
console.error('Error: package.json already exists. Please run in an empty directory.');
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
if ((0, fs_1.existsSync)(configJs) || (0, fs_1.existsSync)(configTs)) {
|
|
16
|
+
console.error('Error: Payload config file already exists. Please run in an empty directory.');
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function generateStarter(): Promise<void>;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateStarter = generateStarter;
|
|
4
|
+
const readline_1 = require("readline");
|
|
5
|
+
const child_process_1 = require("child_process");
|
|
6
|
+
const util_1 = require("util");
|
|
7
|
+
const execAsync = (0, util_1.promisify)(child_process_1.exec);
|
|
8
|
+
const repoUrl = 'https://github.com/blok0-payload/starter.git';
|
|
9
|
+
function prompt(question) {
|
|
10
|
+
return new Promise((resolve) => {
|
|
11
|
+
const rl = (0, readline_1.createInterface)({
|
|
12
|
+
input: process.stdin,
|
|
13
|
+
output: process.stdout,
|
|
14
|
+
});
|
|
15
|
+
rl.question(question, (answer) => {
|
|
16
|
+
rl.close();
|
|
17
|
+
resolve(answer.toLowerCase().startsWith('y'));
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
async function generateStarter() {
|
|
22
|
+
console.log('Cloning starter repository...');
|
|
23
|
+
try {
|
|
24
|
+
await execAsync(`git clone --depth 1 ${repoUrl} .`);
|
|
25
|
+
console.log('Repository cloned successfully.');
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
throw new Error(`Failed to clone repository: ${error}`);
|
|
29
|
+
}
|
|
30
|
+
// Prompt for bun install
|
|
31
|
+
const installDeps = await prompt('Run \'bun install\' to install dependencies? (y/n): ');
|
|
32
|
+
if (installDeps) {
|
|
33
|
+
console.log('Installing dependencies...');
|
|
34
|
+
try {
|
|
35
|
+
await new Promise((resolve, reject) => {
|
|
36
|
+
const child = (0, child_process_1.spawn)('bun', ['install'], { stdio: 'inherit' });
|
|
37
|
+
child.on('close', (code) => {
|
|
38
|
+
if (code === 0)
|
|
39
|
+
resolve();
|
|
40
|
+
else
|
|
41
|
+
reject(new Error('Failed to install dependencies'));
|
|
42
|
+
});
|
|
43
|
+
child.on('error', reject);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
console.error('Failed to install dependencies:', error);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
// Prompt for git init
|
|
51
|
+
const initGit = await prompt('Initialize git repository? (y/n): ');
|
|
52
|
+
if (initGit) {
|
|
53
|
+
console.log('Initializing git repository...');
|
|
54
|
+
try {
|
|
55
|
+
await execAsync('git init');
|
|
56
|
+
console.log('Git repository initialized.');
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
console.error('Failed to initialize git:', error);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
console.log('Blok0 starter project created successfully!');
|
|
63
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const readline_1 = require("readline");
|
|
6
|
+
const detectors_1 = require("./detectors");
|
|
7
|
+
const generate_1 = require("./handlers/generate");
|
|
8
|
+
function prompt(question) {
|
|
9
|
+
return new Promise((resolve) => {
|
|
10
|
+
const rl = (0, readline_1.createInterface)({
|
|
11
|
+
input: process.stdin,
|
|
12
|
+
output: process.stdout,
|
|
13
|
+
});
|
|
14
|
+
rl.question(question, (answer) => {
|
|
15
|
+
rl.close();
|
|
16
|
+
resolve(answer.trim());
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
async function main() {
|
|
21
|
+
const args = process.argv.slice(2);
|
|
22
|
+
if (args.length < 2 || args[0] !== 'generate' || args[1] !== 'starter') {
|
|
23
|
+
console.error('Error: Invalid command. Supported: generate starter [folder]');
|
|
24
|
+
process.exit(1);
|
|
25
|
+
}
|
|
26
|
+
let targetFolder = args[2];
|
|
27
|
+
if (!targetFolder) {
|
|
28
|
+
targetFolder = await prompt('Enter project folder name: ');
|
|
29
|
+
}
|
|
30
|
+
if (targetFolder !== '.') {
|
|
31
|
+
(0, fs_1.mkdirSync)(targetFolder, { recursive: true });
|
|
32
|
+
process.chdir(targetFolder);
|
|
33
|
+
}
|
|
34
|
+
if (!(0, detectors_1.checkEmptyDirectory)()) {
|
|
35
|
+
process.exit(1);
|
|
36
|
+
}
|
|
37
|
+
try {
|
|
38
|
+
await (0, generate_1.generateStarter)();
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
console.error(`Error: ${error.message}`);
|
|
42
|
+
process.exit(1);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
main();
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "blok0",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "CLI tool for Payload CMS scaffolding",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"blok0": "./dist/index.js"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "bun run tsc",
|
|
11
|
+
"dev": "bun run tsx src/index.ts"
|
|
12
|
+
},
|
|
13
|
+
"keywords": ["cli", "payload", "cms"],
|
|
14
|
+
"author": "Your Name",
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"payload": "^2.0.0"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@types/node": "^20.0.0",
|
|
21
|
+
"bun-types": "^1.0.0",
|
|
22
|
+
"tsx": "^4.0.0",
|
|
23
|
+
"typescript": "^5.0.0"
|
|
24
|
+
}
|
|
25
|
+
}
|
package/src/detectors.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { existsSync } from 'fs';
|
|
2
|
+
import { join } from 'path';
|
|
3
|
+
|
|
4
|
+
export function checkEmptyDirectory(): boolean {
|
|
5
|
+
const cwd = process.cwd();
|
|
6
|
+
|
|
7
|
+
const pkgPath = join(cwd, 'package.json');
|
|
8
|
+
const configJs = join(cwd, 'payload.config.js');
|
|
9
|
+
const configTs = join(cwd, 'payload.config.ts');
|
|
10
|
+
|
|
11
|
+
if (existsSync(pkgPath)) {
|
|
12
|
+
console.error('Error: package.json already exists. Please run in an empty directory.');
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (existsSync(configJs) || existsSync(configTs)) {
|
|
17
|
+
console.error('Error: Payload config file already exists. Please run in an empty directory.');
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { createInterface } from 'readline';
|
|
2
|
+
import { exec, spawn } from 'child_process';
|
|
3
|
+
import { promisify } from 'util';
|
|
4
|
+
|
|
5
|
+
const execAsync = promisify(exec);
|
|
6
|
+
|
|
7
|
+
const repoUrl = 'https://github.com/blok0-payload/starter.git';
|
|
8
|
+
|
|
9
|
+
function prompt(question: string): Promise<boolean> {
|
|
10
|
+
return new Promise((resolve) => {
|
|
11
|
+
const rl = createInterface({
|
|
12
|
+
input: process.stdin,
|
|
13
|
+
output: process.stdout,
|
|
14
|
+
});
|
|
15
|
+
rl.question(question, (answer) => {
|
|
16
|
+
rl.close();
|
|
17
|
+
resolve(answer.toLowerCase().startsWith('y'));
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export async function generateStarter(): Promise<void> {
|
|
23
|
+
console.log('Cloning starter repository...');
|
|
24
|
+
try {
|
|
25
|
+
await execAsync(`git clone --depth 1 ${repoUrl} .`);
|
|
26
|
+
console.log('Repository cloned successfully.');
|
|
27
|
+
} catch (error) {
|
|
28
|
+
throw new Error(`Failed to clone repository: ${error}`);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Prompt for bun install
|
|
32
|
+
const installDeps = await prompt('Run \'bun install\' to install dependencies? (y/n): ');
|
|
33
|
+
if (installDeps) {
|
|
34
|
+
console.log('Installing dependencies...');
|
|
35
|
+
try {
|
|
36
|
+
await new Promise<void>((resolve, reject) => {
|
|
37
|
+
const child = spawn('bun', ['install'], { stdio: 'inherit' });
|
|
38
|
+
child.on('close', (code) => {
|
|
39
|
+
if (code === 0) resolve();
|
|
40
|
+
else reject(new Error('Failed to install dependencies'));
|
|
41
|
+
});
|
|
42
|
+
child.on('error', reject);
|
|
43
|
+
});
|
|
44
|
+
} catch (error) {
|
|
45
|
+
console.error('Failed to install dependencies:', error);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Prompt for git init
|
|
50
|
+
const initGit = await prompt('Initialize git repository? (y/n): ');
|
|
51
|
+
if (initGit) {
|
|
52
|
+
console.log('Initializing git repository...');
|
|
53
|
+
try {
|
|
54
|
+
await execAsync('git init');
|
|
55
|
+
console.log('Git repository initialized.');
|
|
56
|
+
} catch (error) {
|
|
57
|
+
console.error('Failed to initialize git:', error);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
console.log('Blok0 starter project created successfully!');
|
|
62
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
|
|
3
|
+
import { mkdirSync } from 'fs';
|
|
4
|
+
import { createInterface } from 'readline';
|
|
5
|
+
import { checkEmptyDirectory } from './detectors';
|
|
6
|
+
import { generateStarter } from './handlers/generate';
|
|
7
|
+
|
|
8
|
+
function prompt(question: string): Promise<string> {
|
|
9
|
+
return new Promise((resolve) => {
|
|
10
|
+
const rl = createInterface({
|
|
11
|
+
input: process.stdin,
|
|
12
|
+
output: process.stdout,
|
|
13
|
+
});
|
|
14
|
+
rl.question(question, (answer) => {
|
|
15
|
+
rl.close();
|
|
16
|
+
resolve(answer.trim());
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async function main() {
|
|
22
|
+
const args = process.argv.slice(2);
|
|
23
|
+
|
|
24
|
+
if (args.length < 2 || args[0] !== 'generate' || args[1] !== 'starter') {
|
|
25
|
+
console.error('Error: Invalid command. Supported: generate starter [folder]');
|
|
26
|
+
process.exit(1);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let targetFolder = args[2];
|
|
30
|
+
if (!targetFolder) {
|
|
31
|
+
targetFolder = await prompt('Enter project folder name: ');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (targetFolder !== '.') {
|
|
35
|
+
mkdirSync(targetFolder, { recursive: true });
|
|
36
|
+
process.chdir(targetFolder);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (!checkEmptyDirectory()) {
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
try {
|
|
44
|
+
await generateStarter();
|
|
45
|
+
} catch (error) {
|
|
46
|
+
console.error(`Error: ${(error as Error).message}`);
|
|
47
|
+
process.exit(1);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
main();
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"outDir": "./dist",
|
|
6
|
+
"rootDir": "./src",
|
|
7
|
+
"strict": true,
|
|
8
|
+
"esModuleInterop": true,
|
|
9
|
+
"skipLibCheck": true,
|
|
10
|
+
"forceConsistentCasingInFileNames": true,
|
|
11
|
+
"declaration": true,
|
|
12
|
+
"resolveJsonModule": true
|
|
13
|
+
},
|
|
14
|
+
"include": ["src/**/*.ts"],
|
|
15
|
+
"exclude": ["node_modules", "dist", "src/templates/**"]
|
|
16
|
+
}
|