@patternfly/patternfly-cli 1.0.2 ā 1.0.4
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/.github/workflows/build.yml +1 -1
- package/.github/workflows/lint.yml +1 -1
- package/.github/workflows/release.yml +1 -1
- package/.github/workflows/test.yml +1 -1
- package/LICENSE +1 -1
- package/dist/cli.js +34 -145
- package/dist/cli.js.map +1 -1
- package/dist/create.d.ts +10 -0
- package/dist/create.d.ts.map +1 -0
- package/dist/create.js +151 -0
- package/dist/create.js.map +1 -0
- package/dist/gh-pages.d.ts +14 -0
- package/dist/gh-pages.d.ts.map +1 -0
- package/dist/gh-pages.js +139 -0
- package/dist/gh-pages.js.map +1 -0
- package/package.json +2 -2
- package/src/__tests__/cli.test.ts +0 -23
- package/src/__tests__/create.test.ts +306 -0
- package/src/__tests__/gh-pages.test.ts +283 -0
- package/src/cli.ts +33 -176
- package/src/create.ts +187 -0
- package/src/gh-pages.ts +170 -0
package/LICENSE
CHANGED
package/dist/cli.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { program } from 'commander';
|
|
3
3
|
import { execa } from 'execa';
|
|
4
|
-
import inquirer from 'inquirer';
|
|
5
4
|
import fs from 'fs-extra';
|
|
6
5
|
import path from 'path';
|
|
7
6
|
import { defaultTemplates } from './templates.js';
|
|
8
7
|
import { mergeTemplates } from './template-loader.js';
|
|
9
8
|
import { offerAndCreateGitHubRepo } from './github.js';
|
|
9
|
+
import { runCreate } from './create.js';
|
|
10
10
|
import { runSave } from './save.js';
|
|
11
11
|
import { runLoad } from './load.js';
|
|
12
|
+
import { runDeployToGitHubPages } from './gh-pages.js';
|
|
12
13
|
/** Command to create a new project */
|
|
13
14
|
program
|
|
14
15
|
.version('1.0.0')
|
|
@@ -19,154 +20,15 @@ program
|
|
|
19
20
|
.option('-t, --template-file <path>', 'Path to a JSON file with custom templates (same format as built-in)')
|
|
20
21
|
.option('--ssh', 'Use SSH URL for cloning the template repository')
|
|
21
22
|
.action(async (projectDirectory, templateName, options) => {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
{
|
|
27
|
-
type: 'input',
|
|
28
|
-
name: 'projectDirectory',
|
|
29
|
-
message: 'Please provide the directory where you want to create the project?',
|
|
30
|
-
default: 'my-app',
|
|
31
|
-
},
|
|
32
|
-
]);
|
|
33
|
-
projectDirectory = projectDirAnswer.projectDirectory;
|
|
34
|
-
}
|
|
35
|
-
// If template name is not provided, show available templates and let user select
|
|
36
|
-
if (!templateName) {
|
|
37
|
-
console.log('\nš Available templates:\n');
|
|
38
|
-
templatesToUse.forEach(t => {
|
|
39
|
-
console.log(` ${t.name.padEnd(12)} - ${t.description}`);
|
|
23
|
+
try {
|
|
24
|
+
await runCreate(projectDirectory, templateName, {
|
|
25
|
+
templateFile: options?.templateFile,
|
|
26
|
+
ssh: options?.ssh,
|
|
40
27
|
});
|
|
41
|
-
console.log('');
|
|
42
|
-
const templateQuestion = [
|
|
43
|
-
{
|
|
44
|
-
type: 'list',
|
|
45
|
-
name: 'templateName',
|
|
46
|
-
message: 'Select a template:',
|
|
47
|
-
choices: templatesToUse.map(t => ({
|
|
48
|
-
name: `${t.name} - ${t.description}`,
|
|
49
|
-
value: t.name
|
|
50
|
-
}))
|
|
51
|
-
}
|
|
52
|
-
];
|
|
53
|
-
const templateAnswer = await inquirer.prompt(templateQuestion);
|
|
54
|
-
templateName = templateAnswer.templateName;
|
|
55
28
|
}
|
|
56
|
-
|
|
57
|
-
const template = templatesToUse.find(t => t.name === templateName);
|
|
58
|
-
if (!template) {
|
|
59
|
-
console.error(`ā Template "${templateName}" not found.\n`);
|
|
60
|
-
console.log('š Available templates:\n');
|
|
61
|
-
templatesToUse.forEach(t => {
|
|
62
|
-
console.log(` ${t.name.padEnd(12)} - ${t.description}`);
|
|
63
|
-
});
|
|
64
|
-
console.log('');
|
|
29
|
+
catch {
|
|
65
30
|
process.exit(1);
|
|
66
31
|
}
|
|
67
|
-
// If --ssh was not passed, prompt whether to use SSH
|
|
68
|
-
let useSSH = options?.ssh;
|
|
69
|
-
if (useSSH === undefined && template.repoSSH) {
|
|
70
|
-
const sshAnswer = await inquirer.prompt([
|
|
71
|
-
{
|
|
72
|
-
type: 'confirm',
|
|
73
|
-
name: 'useSSH',
|
|
74
|
-
message: 'Use SSH URL for cloning?',
|
|
75
|
-
default: false,
|
|
76
|
-
},
|
|
77
|
-
]);
|
|
78
|
-
useSSH = sshAnswer.useSSH;
|
|
79
|
-
}
|
|
80
|
-
const templateRepoUrl = useSSH && template.repoSSH ? template.repoSSH : template.repo;
|
|
81
|
-
// Define the full path for the new project
|
|
82
|
-
const projectPath = path.resolve(projectDirectory);
|
|
83
|
-
console.log(`Cloning template "${templateName}" from ${templateRepoUrl} into ${projectPath}...`);
|
|
84
|
-
try {
|
|
85
|
-
// Clone the repository
|
|
86
|
-
const cloneArgs = ['clone'];
|
|
87
|
-
if (template.options && Array.isArray(template.options)) {
|
|
88
|
-
cloneArgs.push(...template.options);
|
|
89
|
-
}
|
|
90
|
-
cloneArgs.push(templateRepoUrl, projectPath);
|
|
91
|
-
await execa('git', cloneArgs, { stdio: 'inherit' });
|
|
92
|
-
console.log('ā
Template cloned successfully.');
|
|
93
|
-
// Remove the .git folder from the *new* project
|
|
94
|
-
await fs.remove(path.join(projectPath, '.git'));
|
|
95
|
-
console.log('š§¹ Cleaned up template .git directory.');
|
|
96
|
-
// Ask user for customization details
|
|
97
|
-
const questions = [
|
|
98
|
-
{
|
|
99
|
-
type: 'input',
|
|
100
|
-
name: 'name',
|
|
101
|
-
message: 'What is the project name?',
|
|
102
|
-
default: path.basename(projectPath),
|
|
103
|
-
},
|
|
104
|
-
{
|
|
105
|
-
type: 'input',
|
|
106
|
-
name: 'version',
|
|
107
|
-
message: 'What version number would you like to use?',
|
|
108
|
-
default: '1.0.0',
|
|
109
|
-
},
|
|
110
|
-
{
|
|
111
|
-
type: 'input',
|
|
112
|
-
name: 'description',
|
|
113
|
-
message: 'What is the project description?',
|
|
114
|
-
default: '',
|
|
115
|
-
},
|
|
116
|
-
{
|
|
117
|
-
type: 'input',
|
|
118
|
-
name: 'author',
|
|
119
|
-
message: 'Who is the author of the project?',
|
|
120
|
-
default: '',
|
|
121
|
-
},
|
|
122
|
-
];
|
|
123
|
-
const answers = await inquirer.prompt(questions);
|
|
124
|
-
// Update the package.json in the new project
|
|
125
|
-
const pkgJsonPath = path.join(projectPath, 'package.json');
|
|
126
|
-
if (await fs.pathExists(pkgJsonPath)) {
|
|
127
|
-
const pkgJson = await fs.readJson(pkgJsonPath);
|
|
128
|
-
// Overwrite fields with user's answers
|
|
129
|
-
pkgJson.name = answers.name;
|
|
130
|
-
pkgJson.version = answers.version;
|
|
131
|
-
pkgJson.description = answers.description;
|
|
132
|
-
pkgJson.author = answers.author;
|
|
133
|
-
// Write the updated package.json back
|
|
134
|
-
await fs.writeJson(pkgJsonPath, pkgJson, { spaces: 2 });
|
|
135
|
-
console.log('š Customized package.json.');
|
|
136
|
-
}
|
|
137
|
-
else {
|
|
138
|
-
console.log('ā¹ļø No package.json found in template, skipping customization.');
|
|
139
|
-
}
|
|
140
|
-
const packageManager = template.packageManager || "npm";
|
|
141
|
-
// Install dependencies
|
|
142
|
-
console.log('š¦ Installing dependencies... (This may take a moment)');
|
|
143
|
-
await execa(packageManager, ['install'], { cwd: projectPath, stdio: 'inherit' });
|
|
144
|
-
console.log('ā
Dependencies installed.');
|
|
145
|
-
// Optional: Create GitHub repository
|
|
146
|
-
await offerAndCreateGitHubRepo(projectPath);
|
|
147
|
-
// Let the user know the project was created successfully
|
|
148
|
-
console.log('\n⨠Project created successfully! āØ\n');
|
|
149
|
-
console.log(`To get started:`);
|
|
150
|
-
console.log(` cd ${projectDirectory}`);
|
|
151
|
-
console.log(' Happy coding! š');
|
|
152
|
-
}
|
|
153
|
-
catch (error) {
|
|
154
|
-
console.error('ā An error occurred:');
|
|
155
|
-
if (error instanceof Error) {
|
|
156
|
-
console.error(error.message);
|
|
157
|
-
}
|
|
158
|
-
else if (error && typeof error === 'object' && 'stderr' in error) {
|
|
159
|
-
console.error(error.stderr || String(error));
|
|
160
|
-
}
|
|
161
|
-
else {
|
|
162
|
-
console.error(String(error));
|
|
163
|
-
}
|
|
164
|
-
// Clean up the created directory if an error occurred
|
|
165
|
-
if (await fs.pathExists(projectPath)) {
|
|
166
|
-
await fs.remove(projectPath);
|
|
167
|
-
console.log('š§¹ Cleaned up failed project directory.');
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
32
|
});
|
|
171
33
|
/** Command to initialize a project and optionally create a GitHub repository */
|
|
172
34
|
program
|
|
@@ -268,5 +130,32 @@ program
|
|
|
268
130
|
process.exit(1);
|
|
269
131
|
}
|
|
270
132
|
});
|
|
133
|
+
/** Command to deploy the React app to GitHub Pages */
|
|
134
|
+
program
|
|
135
|
+
.command('deploy')
|
|
136
|
+
.description('Build the app and deploy it to GitHub Pages (uses gh-pages branch)')
|
|
137
|
+
.argument('[path]', 'Path to the project (defaults to current directory)')
|
|
138
|
+
.option('-d, --dist-dir <dir>', 'Build output directory to deploy', 'dist')
|
|
139
|
+
.option('--no-build', 'Skip running the build step (deploy existing output only)')
|
|
140
|
+
.option('-b, --branch <branch>', 'Git branch to deploy to', 'gh-pages')
|
|
141
|
+
.action(async (projectPath, options) => {
|
|
142
|
+
const cwd = projectPath ? path.resolve(projectPath) : process.cwd();
|
|
143
|
+
try {
|
|
144
|
+
await runDeployToGitHubPages(cwd, {
|
|
145
|
+
distDir: options.distDir,
|
|
146
|
+
skipBuild: options.build === false,
|
|
147
|
+
branch: options.branch,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
if (error instanceof Error) {
|
|
152
|
+
console.error(`\nā ${error.message}\n`);
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
console.error(error);
|
|
156
|
+
}
|
|
157
|
+
process.exit(1);
|
|
158
|
+
}
|
|
159
|
+
});
|
|
271
160
|
program.parse(process.argv);
|
|
272
161
|
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAC9B,OAAO,
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAC9B,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAEvD,sCAAsC;AACtC,OAAO;KACJ,OAAO,CAAC,OAAO,CAAC;KAChB,OAAO,CAAC,QAAQ,CAAC;KACjB,WAAW,CAAC,0CAA0C,CAAC;KACvD,QAAQ,CAAC,qBAAqB,EAAE,wCAAwC,CAAC;KACzE,QAAQ,CAAC,iBAAiB,EAAE,iCAAiC,CAAC;KAC9D,MAAM,CAAC,4BAA4B,EAAE,qEAAqE,CAAC;KAC3G,MAAM,CAAC,OAAO,EAAE,iDAAiD,CAAC;KAClE,MAA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,EAAE,UAAU,CAAC;KACtE,MAAM,CAAC,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,EAAE;IACrC,MAAM,GAAG,GAAG,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC;IACpE,IAAI,CAAC;QACH,MAAM,sBAAsB,CAAC,GAAG,EAAE;YAChC,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,SAAS,EAAE,OAAO,CAAC,KAAK,KAAK,KAAK;YAClC,MAAM,EAAE,OAAO,CAAC,MAAM;SACvB,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;YAC3B,OAAO,CAAC,KAAK,CAAC,OAAO,KAAK,CAAC,OAAO,IAAI,CAAC,CAAC;QAC1C,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACvB,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC,CAAC,CAAC;AAEL,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC"}
|
package/dist/create.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type RunCreateOptions = {
|
|
2
|
+
templateFile?: string;
|
|
3
|
+
ssh?: boolean;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Runs the create flow: clone template, customize package.json, install deps, optionally create GitHub repo.
|
|
7
|
+
* Throws on fatal errors. Caller should catch and process.exit(1).
|
|
8
|
+
*/
|
|
9
|
+
export declare function runCreate(projectDirectory: string | undefined, templateName: string | undefined, options?: RunCreateOptions): Promise<void>;
|
|
10
|
+
//# sourceMappingURL=create.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AAoBA,MAAM,MAAM,gBAAgB,GAAG;IAC7B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,GAAG,CAAC,EAAE,OAAO,CAAC;CACf,CAAC;AAEF;;;GAGG;AACH,wBAAsB,SAAS,CAC7B,gBAAgB,EAAE,MAAM,GAAG,SAAS,EACpC,YAAY,EAAE,MAAM,GAAG,SAAS,EAChC,OAAO,CAAC,EAAE,gBAAgB,GACzB,OAAO,CAAC,IAAI,CAAC,CAyJf"}
|
package/dist/create.js
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
|
+
import { execa } from 'execa';
|
|
4
|
+
import inquirer from 'inquirer';
|
|
5
|
+
import { defaultTemplates } from './templates.js';
|
|
6
|
+
import { mergeTemplates } from './template-loader.js';
|
|
7
|
+
import { offerAndCreateGitHubRepo } from './github.js';
|
|
8
|
+
/**
|
|
9
|
+
* Runs the create flow: clone template, customize package.json, install deps, optionally create GitHub repo.
|
|
10
|
+
* Throws on fatal errors. Caller should catch and process.exit(1).
|
|
11
|
+
*/
|
|
12
|
+
export async function runCreate(projectDirectory, templateName, options) {
|
|
13
|
+
const templatesToUse = mergeTemplates(defaultTemplates, options?.templateFile);
|
|
14
|
+
// If project directory is not provided, prompt for it
|
|
15
|
+
if (!projectDirectory) {
|
|
16
|
+
const projectDirAnswer = await inquirer.prompt([
|
|
17
|
+
{
|
|
18
|
+
type: 'input',
|
|
19
|
+
name: 'projectDirectory',
|
|
20
|
+
message: 'Please provide the directory where you want to create the project?',
|
|
21
|
+
default: 'my-app',
|
|
22
|
+
},
|
|
23
|
+
]);
|
|
24
|
+
projectDirectory = projectDirAnswer.projectDirectory;
|
|
25
|
+
}
|
|
26
|
+
// If template name is not provided, show available templates and let user select
|
|
27
|
+
if (!templateName) {
|
|
28
|
+
console.log('\nš Available templates:\n');
|
|
29
|
+
templatesToUse.forEach(t => {
|
|
30
|
+
console.log(` ${t.name.padEnd(12)} - ${t.description}`);
|
|
31
|
+
});
|
|
32
|
+
console.log('');
|
|
33
|
+
const templateQuestion = [
|
|
34
|
+
{
|
|
35
|
+
type: 'list',
|
|
36
|
+
name: 'templateName',
|
|
37
|
+
message: 'Select a template:',
|
|
38
|
+
choices: templatesToUse.map(t => ({
|
|
39
|
+
name: `${t.name} - ${t.description}`,
|
|
40
|
+
value: t.name,
|
|
41
|
+
})),
|
|
42
|
+
},
|
|
43
|
+
];
|
|
44
|
+
const templateAnswer = await inquirer.prompt(templateQuestion);
|
|
45
|
+
templateName = templateAnswer.templateName;
|
|
46
|
+
}
|
|
47
|
+
// Look up the template by name
|
|
48
|
+
const template = templatesToUse.find(t => t.name === templateName);
|
|
49
|
+
if (!template) {
|
|
50
|
+
console.error(`ā Template "${templateName}" not found.\n`);
|
|
51
|
+
console.log('š Available templates:\n');
|
|
52
|
+
templatesToUse.forEach(t => {
|
|
53
|
+
console.log(` ${t.name.padEnd(12)} - ${t.description}`);
|
|
54
|
+
});
|
|
55
|
+
console.log('');
|
|
56
|
+
throw new Error(`Template "${templateName}" not found`);
|
|
57
|
+
}
|
|
58
|
+
const templateRepoUrl = options?.ssh && template.repoSSH ? template.repoSSH : template.repo;
|
|
59
|
+
// Define the full path for the new project (projectDirectory is set above via arg or prompt)
|
|
60
|
+
const dir = projectDirectory ?? 'my-app';
|
|
61
|
+
const projectPath = path.resolve(dir);
|
|
62
|
+
console.log(`Cloning template "${templateName}" from ${templateRepoUrl} into ${projectPath}...`);
|
|
63
|
+
try {
|
|
64
|
+
// Clone the repository
|
|
65
|
+
const cloneArgs = ['clone'];
|
|
66
|
+
if (template.options && Array.isArray(template.options)) {
|
|
67
|
+
cloneArgs.push(...template.options);
|
|
68
|
+
}
|
|
69
|
+
cloneArgs.push(templateRepoUrl, projectPath);
|
|
70
|
+
await execa('git', cloneArgs, { stdio: 'inherit' });
|
|
71
|
+
console.log('ā
Template cloned successfully.');
|
|
72
|
+
// Remove the .git folder from the *new* project
|
|
73
|
+
await fs.remove(path.join(projectPath, '.git'));
|
|
74
|
+
console.log('š§¹ Cleaned up template .git directory.');
|
|
75
|
+
// Ask user for customization details
|
|
76
|
+
const questions = [
|
|
77
|
+
{
|
|
78
|
+
type: 'input',
|
|
79
|
+
name: 'name',
|
|
80
|
+
message: 'What is the project name?',
|
|
81
|
+
default: path.basename(projectPath),
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
type: 'input',
|
|
85
|
+
name: 'version',
|
|
86
|
+
message: 'What version number would you like to use?',
|
|
87
|
+
default: '1.0.0',
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
type: 'input',
|
|
91
|
+
name: 'description',
|
|
92
|
+
message: 'What is the project description?',
|
|
93
|
+
default: '',
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
type: 'input',
|
|
97
|
+
name: 'author',
|
|
98
|
+
message: 'Who is the author of the project?',
|
|
99
|
+
default: '',
|
|
100
|
+
},
|
|
101
|
+
];
|
|
102
|
+
const answers = await inquirer.prompt(questions);
|
|
103
|
+
// Update the package.json in the new project
|
|
104
|
+
const pkgJsonPath = path.join(projectPath, 'package.json');
|
|
105
|
+
if (await fs.pathExists(pkgJsonPath)) {
|
|
106
|
+
const pkgJson = await fs.readJson(pkgJsonPath);
|
|
107
|
+
// Overwrite fields with user's answers
|
|
108
|
+
pkgJson.name = answers.name;
|
|
109
|
+
pkgJson.version = answers.version;
|
|
110
|
+
pkgJson.description = answers.description;
|
|
111
|
+
pkgJson.author = answers.author;
|
|
112
|
+
// Write the updated package.json back
|
|
113
|
+
await fs.writeJson(pkgJsonPath, pkgJson, { spaces: 2 });
|
|
114
|
+
console.log('š Customized package.json.');
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
console.log('ā¹ļø No package.json found in template, skipping customization.');
|
|
118
|
+
}
|
|
119
|
+
const packageManager = template.packageManager || 'npm';
|
|
120
|
+
// Install dependencies
|
|
121
|
+
console.log('š¦ Installing dependencies... (This may take a moment)');
|
|
122
|
+
await execa(packageManager, ['install'], { cwd: projectPath, stdio: 'inherit' });
|
|
123
|
+
console.log('ā
Dependencies installed.');
|
|
124
|
+
// Optional: Create GitHub repository
|
|
125
|
+
await offerAndCreateGitHubRepo(projectPath);
|
|
126
|
+
// Let the user know the project was created successfully
|
|
127
|
+
console.log('\n⨠Project created successfully! āØ\n');
|
|
128
|
+
console.log(`To get started:`);
|
|
129
|
+
console.log(` cd ${dir}`);
|
|
130
|
+
console.log(' Happy coding! š');
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
console.error('ā An error occurred:');
|
|
134
|
+
if (error instanceof Error) {
|
|
135
|
+
console.error(error.message);
|
|
136
|
+
}
|
|
137
|
+
else if (error && typeof error === 'object' && 'stderr' in error) {
|
|
138
|
+
console.error(error.stderr || String(error));
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
console.error(String(error));
|
|
142
|
+
}
|
|
143
|
+
// Clean up the created directory if an error occurred
|
|
144
|
+
if (await fs.pathExists(projectPath)) {
|
|
145
|
+
await fs.remove(projectPath);
|
|
146
|
+
console.log('š§¹ Cleaned up failed project directory.');
|
|
147
|
+
}
|
|
148
|
+
throw error;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=create.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1B,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAC9B,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAA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K,YAAY,KAAK,EAAE,CAAC;YAC3B,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAC/B,CAAC;aAAM,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,QAAQ,IAAI,KAAK,EAAE,CAAC;YACnE,OAAO,CAAC,KAAK,CAAE,KAA6B,CAAC,MAAM,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QACxE,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QAC/B,CAAC;QAED,sDAAsD;QACtD,IAAI,MAAM,EAAE,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC;YACrC,MAAM,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;YAC7B,OAAO,CAAC,GAAG,CAAC,yCAAyC,CAAC,CAAC;QACzD,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type DeployOptions = {
|
|
2
|
+
/** Build output directory to deploy (e.g. dist, build) */
|
|
3
|
+
distDir: string;
|
|
4
|
+
/** Skip running the build step */
|
|
5
|
+
skipBuild: boolean;
|
|
6
|
+
/** Branch to push to (default gh-pages) */
|
|
7
|
+
branch: string;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Deploy the built app to GitHub Pages using the gh-pages package.
|
|
11
|
+
* Builds the project first unless skipBuild is true, then publishes distDir to the gh-pages branch.
|
|
12
|
+
*/
|
|
13
|
+
export declare function runDeployToGitHubPages(projectPath: string, options?: Partial<DeployOptions>): Promise<void>;
|
|
14
|
+
//# sourceMappingURL=gh-pages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gh-pages.d.ts","sourceRoot":"","sources":["../src/gh-pages.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,aAAa,GAAG;IAC1B,0DAA0D;IAC1D,OAAO,EAAE,MAAM,CAAC;IAChB,kCAAkC;IAClC,SAAS,EAAE,OAAO,CAAC;IACnB,2CAA2C;IAC3C,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AA+FF;;;GAGG;AACH,wBAAsB,sBAAsB,CAC1C,WAAW,EAAE,MAAM,EACnB,OAAO,GAAE,OAAO,CAAC,aAAa,CAAM,GACnC,OAAO,CAAC,IAAI,CAAC,CAsDf"}
|
package/dist/gh-pages.js
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
|
+
import { execa } from 'execa';
|
|
4
|
+
import ghPages from 'gh-pages';
|
|
5
|
+
import { checkGhAuth } from './github.js';
|
|
6
|
+
const DEFAULT_DIST_DIR = 'dist';
|
|
7
|
+
const DEFAULT_BRANCH = 'gh-pages';
|
|
8
|
+
/**
|
|
9
|
+
* Parse owner and repo name from a Git remote URL.
|
|
10
|
+
* Supports https://github.com/owner/repo, https://github.com/owner/repo.git, git@github.com:owner/repo.git
|
|
11
|
+
*/
|
|
12
|
+
function parseRepoFromUrl(repoUrl) {
|
|
13
|
+
const trimmed = repoUrl.trim().replace(/\.git$/, '');
|
|
14
|
+
// git@github.com:owner/repo or https://github.com/owner/repo
|
|
15
|
+
const sshMatch = trimmed.match(/git@github\.com:([^/]+)\/([^/]+)/);
|
|
16
|
+
if (sshMatch?.[1] && sshMatch[2]) {
|
|
17
|
+
return { owner: sshMatch[1], repo: sshMatch[2] };
|
|
18
|
+
}
|
|
19
|
+
const httpsMatch = trimmed.match(/github\.com[/:]([^/]+)\/([^/#?]+)/);
|
|
20
|
+
if (httpsMatch?.[1] && httpsMatch[2]) {
|
|
21
|
+
return { owner: httpsMatch[1], repo: httpsMatch[2] };
|
|
22
|
+
}
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Ensure GitHub Pages is enabled for the repository, configured to use the given branch.
|
|
27
|
+
* Uses the GitHub API via `gh` CLI. No-op if gh is not authenticated or on failure.
|
|
28
|
+
*/
|
|
29
|
+
async function ensurePagesEnabled(owner, repo, branch) {
|
|
30
|
+
const auth = await checkGhAuth();
|
|
31
|
+
if (!auth.ok)
|
|
32
|
+
return;
|
|
33
|
+
const body = JSON.stringify({ source: { branch, path: '/' } });
|
|
34
|
+
try {
|
|
35
|
+
const getResult = await execa('gh', ['api', `repos/${owner}/${repo}/pages`, '--jq', '.source.branch'], {
|
|
36
|
+
reject: false,
|
|
37
|
+
encoding: 'utf8',
|
|
38
|
+
});
|
|
39
|
+
if (getResult.exitCode === 0) {
|
|
40
|
+
const currentBranch = getResult.stdout?.trim();
|
|
41
|
+
if (currentBranch === branch)
|
|
42
|
+
return;
|
|
43
|
+
await execa('gh', [
|
|
44
|
+
'api',
|
|
45
|
+
'-X',
|
|
46
|
+
'PUT',
|
|
47
|
+
`repos/${owner}/${repo}/pages`,
|
|
48
|
+
'--input',
|
|
49
|
+
'-',
|
|
50
|
+
], { input: body });
|
|
51
|
+
console.log(` GitHub Pages source updated to branch "${branch}".`);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
await execa('gh', [
|
|
55
|
+
'api',
|
|
56
|
+
'-X',
|
|
57
|
+
'POST',
|
|
58
|
+
`repos/${owner}/${repo}/pages`,
|
|
59
|
+
'--input',
|
|
60
|
+
'-',
|
|
61
|
+
], { input: body });
|
|
62
|
+
console.log(` GitHub Pages enabled (source: branch "${branch}").`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
// Best-effort: continue without enabling; user can enable manually
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Detect package manager from lock files.
|
|
71
|
+
*/
|
|
72
|
+
async function getPackageManager(cwd) {
|
|
73
|
+
if (await fs.pathExists(path.join(cwd, 'yarn.lock')))
|
|
74
|
+
return 'yarn';
|
|
75
|
+
if (await fs.pathExists(path.join(cwd, 'pnpm-lock.yaml')))
|
|
76
|
+
return 'pnpm';
|
|
77
|
+
return 'npm';
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Run build script in the project (npm run build / yarn build / pnpm build).
|
|
81
|
+
*/
|
|
82
|
+
async function runBuild(cwd) {
|
|
83
|
+
const pkgPath = path.join(cwd, 'package.json');
|
|
84
|
+
const pkg = await fs.readJson(pkgPath);
|
|
85
|
+
const scripts = pkg.scripts || {};
|
|
86
|
+
if (!scripts['build']) {
|
|
87
|
+
throw new Error('No "build" script found in package.json. Add a build script or use --no-build and deploy an existing folder with -d/--dist-dir.');
|
|
88
|
+
}
|
|
89
|
+
const pm = await getPackageManager(cwd);
|
|
90
|
+
const runCmd = pm === 'npm' ? 'npm' : pm === 'yarn' ? 'yarn' : 'pnpm';
|
|
91
|
+
const args = pm === 'npm' ? ['run', 'build'] : ['build'];
|
|
92
|
+
console.log(`š¦ Running build (${runCmd} ${args.join(' ')})...`);
|
|
93
|
+
await execa(runCmd, args, { cwd, stdio: 'inherit' });
|
|
94
|
+
console.log('ā
Build completed.\n');
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Deploy the built app to GitHub Pages using the gh-pages package.
|
|
98
|
+
* Builds the project first unless skipBuild is true, then publishes distDir to the gh-pages branch.
|
|
99
|
+
*/
|
|
100
|
+
export async function runDeployToGitHubPages(projectPath, options = {}) {
|
|
101
|
+
const distDir = options.distDir ?? DEFAULT_DIST_DIR;
|
|
102
|
+
const skipBuild = options.skipBuild ?? false;
|
|
103
|
+
const branch = options.branch ?? DEFAULT_BRANCH;
|
|
104
|
+
const cwd = path.resolve(projectPath);
|
|
105
|
+
const pkgPath = path.join(cwd, 'package.json');
|
|
106
|
+
if (!(await fs.pathExists(pkgPath))) {
|
|
107
|
+
throw new Error('No package.json found in this directory. Run this command from your project root (or pass the project path).');
|
|
108
|
+
}
|
|
109
|
+
let repoUrl;
|
|
110
|
+
try {
|
|
111
|
+
const { stdout } = await execa('git', ['remote', 'get-url', 'origin'], {
|
|
112
|
+
cwd,
|
|
113
|
+
reject: true,
|
|
114
|
+
});
|
|
115
|
+
repoUrl = stdout.trim();
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
throw new Error('Please save your changes first, before deploying to GitHub Pages.');
|
|
119
|
+
}
|
|
120
|
+
if (!skipBuild) {
|
|
121
|
+
await runBuild(cwd);
|
|
122
|
+
}
|
|
123
|
+
const absoluteDist = path.join(cwd, distDir);
|
|
124
|
+
if (!(await fs.pathExists(absoluteDist))) {
|
|
125
|
+
throw new Error(`Build output directory "${distDir}" does not exist. Run a build first or specify the correct directory with -d/--dist-dir.`);
|
|
126
|
+
}
|
|
127
|
+
const parsed = parseRepoFromUrl(repoUrl);
|
|
128
|
+
if (parsed) {
|
|
129
|
+
await ensurePagesEnabled(parsed.owner, parsed.repo, branch);
|
|
130
|
+
}
|
|
131
|
+
console.log(`š Deploying "${distDir}" to GitHub Pages (branch: ${branch})...`);
|
|
132
|
+
await new Promise((resolve, reject) => {
|
|
133
|
+
ghPages.publish(absoluteDist, { branch, repo: repoUrl }, (err) => (err ? reject(err) : resolve()));
|
|
134
|
+
});
|
|
135
|
+
console.log('\nā
Deployed to GitHub Pages.');
|
|
136
|
+
console.log(' Enable GitHub Pages in your repo: Settings ā Pages ā Source: branch "' + branch + '".');
|
|
137
|
+
console.log(' If the site is at username.github.io/<repo-name>, set your app\'s base path (e.g. base: \'/<repo-name>/\' in Vite).\n');
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=gh-pages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gh-pages.js","sourceRoot":"","sources":["../src/gh-pages.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1B,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAC9B,OAAO,OAAO,MAAM,UAAU,CAAC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