Skip to content

Commit 1c47ab1

Browse files
committed
feat: extra command 'license-setup'
1 parent 821ae6c commit 1c47ab1

File tree

6 files changed

+169
-138
lines changed

6 files changed

+169
-138
lines changed
Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import chalk from 'chalk';
2-
import { checkbox } from '@inquirer/prompts';
32
import { checkStrapiProject } from '../utils/strapi';
4-
import { getContentTypes, enableWebtoolsForContentType } from '../utils/content-types';
3+
import { getContentTypes } from '../utils/content-types';
4+
import { enableContentTypes } from './subcommands/enable-content-types';
55

66
export async function enable() {
77
// Check if we're in a Strapi project
@@ -14,37 +14,8 @@ export async function enable() {
1414
// Get available content types
1515
const contentTypes = getContentTypes();
1616

17-
if (contentTypes.length === 0) {
18-
console.log(chalk.yellow('No content types found in your Strapi project.'));
19-
return;
20-
}
21-
22-
// Let user select content types
23-
const selectedContentTypes = await checkbox({
24-
message: 'Select content types to enable Webtools for:',
25-
choices: contentTypes.map((type) => ({
26-
name: type,
27-
value: type,
28-
})),
29-
});
30-
31-
// Enable Webtools for selected content types
32-
if (selectedContentTypes.length > 0) {
33-
console.log(`\n${chalk.cyan('●')} Enabling Webtools for selected content types...`);
34-
35-
selectedContentTypes.map((contentType) => {
36-
const success = enableWebtoolsForContentType(contentType);
37-
if (success) {
38-
console.log(chalk.green(`✓ Enabled Webtools for ${contentType}`));
39-
return true;
40-
}
41-
42-
console.log(chalk.red(`✗ Failed to enable Webtools for ${contentType}`));
43-
return false;
44-
});
45-
} else {
46-
console.log(chalk.yellow('No content types selected. Nothing to do.'));
47-
}
17+
// Enable Webtools for content types
18+
await enableContentTypes(contentTypes);
4819

4920
console.log(chalk.yellow('\nYou may need to restart your Strapi server for changes to take effect.'));
5021
}

packages/cli/src/commands/install.ts

Lines changed: 7 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import chalk from 'chalk';
2-
import { checkbox, input, select } from '@inquirer/prompts';
2+
import { checkbox } from '@inquirer/prompts';
33
import { checkStrapiProject } from '../utils/strapi';
4-
import { getContentTypes, enableWebtoolsForContentType } from '../utils/content-types';
4+
import { getContentTypes } from '../utils/content-types';
55
import { getAvailableAddons, getPremiumAddons } from '../utils/addons';
66
import { installPackage } from '../utils/package-manager';
7-
import { createLicenseFiles } from '../utils/license';
87
import { logger } from '../utils/logger';
8+
import { licenseSetup } from './subcommands/license-setup';
9+
import { enableContentTypes } from './subcommands/enable-content-types';
910

1011
export async function install() {
1112
// Check if we're in a Strapi project
@@ -22,112 +23,13 @@ export async function install() {
2223

2324
console.log('🚀 Get more out of Webtools with premium add-ons!\n');
2425

25-
console.log('Start your free trial and get:');
26-
console.log('✨ 30 days of access to the Essential plan, which includes:');
27-
console.log('✅ Automated Redirects');
28-
console.log('✅ Internal Links\n');
29-
30-
const selectedPlan = await select({
31-
message: 'Do you have a license?',
32-
choices: [
33-
{ name: 'Yes, use my license', value: 'license' },
34-
{ name: 'Get me a trial', value: 'trial' },
35-
{ name: 'Skip', value: 'skip' },
36-
],
37-
});
38-
39-
let licenseKey: string | null = null;
40-
41-
if (selectedPlan === 'license') {
42-
licenseKey = await input({
43-
message: 'Please enter your license key:',
44-
validate: (value) => {
45-
if (!value || value.trim().length === 0) {
46-
return 'License key cannot be empty';
47-
}
48-
return true;
49-
},
50-
});
51-
52-
// Create license files
53-
console.log(`\n${chalk.cyan('●')} Setting up license configuration...`);
54-
const success = await createLicenseFiles(licenseKey);
55-
if (!success) {
56-
console.log(chalk.red('\nFailed to setup license configuration. Continuing without a license.'));
57-
licenseKey = null;
58-
}
59-
}
60-
61-
if (selectedPlan === 'trial') {
62-
logger.title(
63-
'Trial',
64-
`${chalk.bold('🚀 Get your free trial license!')}\n`,
65-
);
66-
console.log('You can start your free trial by visiting the following link:');
67-
console.log(chalk.underline('https://polar.sh/checkout/polar_c_4NUnsZ24PTLPhbSux9STPqeLL7ptZlcz003Yy15MArc'));
68-
console.log('\n✨ Enjoy 30 days of access to the Essential plan completely free!');
69-
console.log('💡 Remember: You can cancel within the 30 days to ensure your trial remains free.\n');
70-
71-
const trialPlan = await select({
72-
message: 'Got your license key?',
73-
choices: [
74-
{ name: 'Yes', value: 'yes' },
75-
{ name: 'Skip', value: 'skip' },
76-
],
77-
});
78-
79-
if (trialPlan === 'yes') {
80-
licenseKey = await input({
81-
message: 'Please enter your license key:',
82-
validate: (value) => {
83-
if (!value || value.trim().length === 0) {
84-
return 'License key cannot be empty';
85-
}
86-
return true;
87-
},
88-
});
89-
90-
// Create license files
91-
console.log(`\n${chalk.cyan('●')} Setting up license configuration...`);
92-
const success = await createLicenseFiles(licenseKey);
93-
if (!success) {
94-
console.log(chalk.red('\nFailed to setup license configuration. Continuing without a license.'));
95-
licenseKey = null;
96-
}
97-
}
98-
}
26+
const { licenseKey } = await licenseSetup();
9927

10028
// Get available content types
10129
const contentTypes = getContentTypes();
10230

103-
if (contentTypes.length === 0) {
104-
console.log(chalk.yellow('No content types found in your Strapi project, skipping Webtools setup step. You can enable Webtools later using the "enable" command.'));
105-
} else {
106-
// Let user select content types
107-
const selectedContentTypes = await checkbox({
108-
message: 'Select content types to enable Webtools for:',
109-
choices: contentTypes.map((type) => ({
110-
name: type,
111-
value: type,
112-
})),
113-
});
114-
115-
// Enable Webtools for selected content types
116-
if (selectedContentTypes.length > 0) {
117-
console.log(`\n${chalk.cyan('●')} Enabling Webtools for selected content types...`);
118-
119-
selectedContentTypes.map((contentType) => {
120-
const success = enableWebtoolsForContentType(contentType);
121-
if (success) {
122-
console.log(chalk.green(`✓ Enabled Webtools for ${contentType}`));
123-
return true;
124-
}
125-
126-
console.log(chalk.red(`✗ Failed to enable Webtools for ${contentType}`));
127-
return false;
128-
});
129-
}
130-
}
31+
// Enable Webtools for content types
32+
await enableContentTypes(contentTypes);
13133

13234
// Get available addons
13335
const availableAddons = getAvailableAddons();
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import chalk from 'chalk';
2+
import { checkStrapiProject } from '../utils/strapi';
3+
import { logger } from '../utils/logger';
4+
import { licenseSetup } from './subcommands/license-setup';
5+
6+
export async function setupLicense() {
7+
// Check if we're in a Strapi project
8+
const isStrapiProject = await checkStrapiProject();
9+
if (!isStrapiProject) {
10+
console.log(chalk.red('Error: This command must be run in a Strapi project directory.'));
11+
return;
12+
}
13+
14+
logger.title(
15+
'Webtools',
16+
`${chalk.bold('🚀 Let\'s build your new website with Strapi')}\n`,
17+
);
18+
19+
await licenseSetup();
20+
21+
console.log(chalk.green('\nLicense setup complete!'));
22+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { checkbox } from '@inquirer/prompts';
2+
import chalk from 'chalk';
3+
import { enableWebtoolsForContentType } from '../../utils/content-types';
4+
5+
export const enableContentTypes = async (contentTypes: string[]) => {
6+
if (contentTypes.length === 0) {
7+
console.log(chalk.yellow('No content types found in your Strapi project.'));
8+
return;
9+
}
10+
11+
// Let user select content types
12+
const selectedContentTypes = await checkbox({
13+
message: 'Select content types to enable Webtools for:',
14+
choices: contentTypes.map((type) => ({
15+
name: type,
16+
value: type,
17+
})),
18+
});
19+
20+
// Enable Webtools for selected content types
21+
if (selectedContentTypes.length > 0) {
22+
console.log(`\n${chalk.cyan('●')} Enabling Webtools for selected content types...`);
23+
24+
selectedContentTypes.map((contentType) => {
25+
const success = enableWebtoolsForContentType(contentType);
26+
if (success) {
27+
console.log(chalk.green(`✓ Enabled Webtools for ${contentType}`));
28+
return true;
29+
}
30+
31+
console.log(chalk.red(`✗ Failed to enable Webtools for ${contentType}`));
32+
return false;
33+
});
34+
} else {
35+
console.log(chalk.yellow('No content types selected. Nothing to do.'));
36+
}
37+
};
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import chalk from 'chalk';
2+
import { input, select } from '@inquirer/prompts';
3+
import { createLicenseFiles } from '../../utils/license';
4+
import { logger } from '../../utils/logger';
5+
6+
export async function licenseSetup() {
7+
console.log('Start your free trial and get:');
8+
console.log('✨ 30 days of access to the Essential plan, which includes:');
9+
console.log('✅ Automated Redirects');
10+
console.log('✅ Internal Links\n');
11+
12+
const selectedPlan = await select({
13+
message: 'Do you have a license?',
14+
choices: [
15+
{ name: 'Yes, use my license', value: 'license' },
16+
{ name: 'Get me a trial', value: 'trial' },
17+
{ name: 'Skip', value: 'skip' },
18+
],
19+
});
20+
21+
let licenseKey: string | null = null;
22+
23+
if (selectedPlan === 'license') {
24+
licenseKey = await input({
25+
message: 'Please enter your license key:',
26+
validate: (value) => {
27+
if (!value || value.trim().length === 0) {
28+
return 'License key cannot be empty';
29+
}
30+
return true;
31+
},
32+
});
33+
34+
// Create license files
35+
console.log(`\n${chalk.cyan('●')} Setting up license configuration...`);
36+
const success = await createLicenseFiles(licenseKey);
37+
if (!success) {
38+
console.log(chalk.red('\nFailed to setup license configuration. Continuing without a license.'));
39+
licenseKey = null;
40+
}
41+
}
42+
43+
if (selectedPlan === 'trial') {
44+
logger.title(
45+
'Trial',
46+
`${chalk.bold('🚀 Get your free trial license!')}\n`,
47+
);
48+
console.log('You can start your free trial by visiting the following link:');
49+
console.log(chalk.underline('https://polar.sh/checkout/polar_c_4NUnsZ24PTLPhbSux9STPqeLL7ptZlcz003Yy15MArc'));
50+
console.log('\n✨ Enjoy 30 days of access to the Essential plan completely free!');
51+
console.log('💡 Remember: You can cancel within the 30 days to ensure your trial remains free.\n');
52+
53+
const trialPlan = await select({
54+
message: 'Got your license key?',
55+
choices: [
56+
{ name: 'Yes', value: 'yes' },
57+
{ name: 'Skip', value: 'skip' },
58+
],
59+
});
60+
61+
if (trialPlan === 'yes') {
62+
licenseKey = await input({
63+
message: 'Please enter your license key:',
64+
validate: (value) => {
65+
if (!value || value.trim().length === 0) {
66+
return 'License key cannot be empty';
67+
}
68+
return true;
69+
},
70+
});
71+
72+
// Create license files
73+
console.log(`\n${chalk.cyan('●')} Setting up license configuration...`);
74+
const success = await createLicenseFiles(licenseKey);
75+
if (!success) {
76+
console.log(chalk.red('\nFailed to setup license configuration. Continuing without a license.'));
77+
licenseKey = null;
78+
}
79+
}
80+
}
81+
82+
return {
83+
selectedPlan,
84+
licenseKey,
85+
};
86+
}

packages/cli/src/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Command } from 'commander';
44
import chalk from 'chalk';
55
import { install } from './commands/install';
66
import { enable } from './commands/enable';
7+
import { setupLicense } from './commands/license-setup';
78

89
const program = new Command();
910

@@ -36,4 +37,16 @@ program
3637
}
3738
});
3839

40+
program
41+
.command('setup-license')
42+
.description('Set up your Webtools license in your Strapi project')
43+
.action(async () => {
44+
try {
45+
await setupLicense();
46+
} catch (error) {
47+
console.error(chalk.red('Error:'), error instanceof Error ? error.message : 'An unknown error occurred');
48+
process.exit(1);
49+
}
50+
});
51+
3952
program.parse();

0 commit comments

Comments
 (0)