Skip to content

Chore/add kickstarts to bootstrap #1980

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .talismanrc
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
fileignoreconfig:
- filename: pnpm-lock.yaml
checksum: f207dfb0198bc78f647a0a9456142fba670d49dc1b456bcf73de5e79ca0ec5d5
checksum: 13a0830f8404a11cf8262369e97abb463714f257dec39625c50f49f0d673a7e9
- filename: packages/contentstack-import/test/integration/auth-token-modules/environments.test.js
checksum: bc6f06b75d082aaf99e2f2f4b932b143765e2f14086967fb8973fe1b2ca6c03e
- filename: packages/contentstack-import/test/integration/environments.test.js
checksum: e71f033dad8944ffeafdf22d0514bda1d20c43e8fea0d62c96e774f3414beb31
- filename: package-lock.json
checksum: 48aade36a6bb3150851296921f0fc425cc92952d6651528d27576eb24bff422f
checksum: b2fdab6282215032685b967468034898d591a140c33aeec3b48a7a7c6a1218c3
- filename: packages/contentstack-auth/test/unit/tokens-validation.test.ts
checksum: 676052e30d31a771ce68302d89b050d176bbef50f3abc7e9cdd4384f0e274e10
- filename: packages/contentstack-import/test/integration/auth-token.test.js
Expand Down Expand Up @@ -52,7 +52,7 @@ fileignoreconfig:
- filename: packages/contentstack-import/test/integration/auth-token-modules/global-fields.test.js
checksum: db5b7aedcd89d783760eb988a2369243c34edc9c12e93a41b2b08fb0da02afdc
- filename: packages/contentstack-export/src/export/modules/assets.ts
checksum: c7f19e6c4a212329d981cebce9a9a8393923dd7c85feb762ddcdca678f7a9349
checksum: a30e3f66bed994f4e04b79bcaf1014d2814db3c7b00b886b86c7ee9d8213de63
- filename: packages/contentstack/README.md
checksum: d6da4ce77d52464737a4f22034f62fb93e47ec9200f8f788f06dbcedaae123b3
version: ''
628 changes: 314 additions & 314 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@
"license": "MIT",
"workspaces": [
"packages/*"
]
],
"packageManager": "pnpm@9.12.3+sha512.cce0f9de9c5a7c95bef944169cc5dfe8741abfb145078c0d508b868056848a87c81e626246cb60967cbd7fd29a6c062ef73ff840d96b3c86c40ac92cf4a813ee"
}
17 changes: 10 additions & 7 deletions packages/contentstack-bootstrap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ $ npm install -g @contentstack/cli-cm-bootstrap
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-cm-bootstrap/1.14.1 darwin-arm64 node-v22.13.1
@contentstack/cli-cm-bootstrap/1.15.0 darwin-arm64 node-v22.13.1
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down Expand Up @@ -45,18 +45,19 @@ Bootstrap contentstack apps
```
USAGE
$ csdx cm:bootstrap [--app-name <value>] [--project-dir <value>] [-k <value> | --org <value> | -n <value>] [-y
<value>] [-a <value>]
<value>] [--run-dev-server] [-a <value>]

FLAGS
-a, --alias=<value> Alias of the management token
-k, --stack-api-key=<value> Provide stack API key to seed content
-n, --stack-name=<value> Name of the new stack that will be created.
-y, --yes=<value> [Optional] Skip stack confirmation
--app-name=<value> App name, reactjs-starter, nextjs-starter, gatsby-starter, angular-starter, nuxt-starter,
vue-starter, stencil-starter
--app-name=<value> App name, kickstart-next, kickstart-next-ssr, kickstart-next-ssg, kickstart-next-graphql,
kickstart-next-middleware, kickstart-nuxt, kickstart-nuxt-ssr
--org=<value> Provide organization UID to create a new stack
--project-dir=<value> Directory to setup the project. If directory name has a space then provide the path as a
string or escap the space using back slash eg: "../../test space" or ../../test\ space
--run-dev-server Automatically start the development server after setup

DESCRIPTION
Bootstrap contentstack apps
Expand All @@ -66,11 +67,13 @@ EXAMPLES

$ csdx cm:bootstrap --project-dir <path/to/setup/the/app>

$ csdx cm:bootstrap --app-name "reactjs-starter" --project-dir <path/to/setup/the/app>
$ csdx cm:bootstrap --app-name "kickstart-next" --project-dir <path/to/setup/the/app>

$ csdx cm:bootstrap --app-name "reactjs-starter" --project-dir <path/to/setup/the/app> --stack-api-key "stack-api-key"
$ csdx cm:bootstrap --app-name "kickstart-next" --project-dir <path/to/setup/the/app> --stack-api-key "stack-api-key"

$ csdx cm:bootstrap --app-name "reactjs-starter" --project-dir <path/to/setup/the/app> --org "your-org-uid" --stack-name "stack-name"
$ csdx cm:bootstrap --app-name "kickstart-next" --project-dir <path/to/setup/the/app> --org "your-org-uid" --stack-name "stack-name"

$ csdx cm:bootstrap --app-name "kickstart-next" --project-dir <path/to/setup/the/app> --run-dev-server
```

_See code: [src/commands/cm/bootstrap.ts](https://github.com/contentstack/cli/blob/main/packages/contentstack-bootstrap/src/commands/cm/bootstrap.ts)_
Expand Down
42 changes: 25 additions & 17 deletions packages/contentstack-bootstrap/messages/index.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
{
"CLI_BOOTSTRAP_INVALID_APP_NAME": "Invalid app name received, use cm:bootstrap see the list of apps supported",
"CLI_BOOTSTRAP_LOGIN_FAILED": "You need to login, first. See: auth:login --help",
"CLI_BOOTSTRAP_GITHUB_ACCESS_NOT_FOUND": "No Github access token found",
"CLI_BOOTSTRAP_START_CLONE_APP": "Cloning the selected app",
"CLI_BOOTSTRAP_REPO_NOT_FOUND": "Unable to find a repo for \"%s\"",
"CLI_BOOTSTRAP_NO_API_KEY_FOUND": "No API key generated for the stack",
"CLI_BOOTSTRAP_STACK_CREATION_FAILED": "Unable to create stack for content \"%s\"",
"CLI_BOOTSTRAP_APP_SELECTION_ENQUIRY": "Select an App",
"CLI_BOOTSTRAP_APP_COPY_SOURCE_CODE_DESTINATION_TYPE_ENQUIRY": "Choose the location where you want to copy the source code",
"CLI_BOOTSTRAP_APP_COPY_SOURCE_CODE_DESTINATION_ENQUIRY": "Enter destination path",
"CLI_BOOTSTRAP_NO_ACCESS_TOKEN_CREATED": "Note: Access token not created already, check out this link https://github.com/settings/tokens \n Provide github access token",
"CLI_BOOTSTRAP_TYPE_OF_APP_ENQUIRY": "Choose the type of app you want to clone",
"CLI_BOOTSTRAP_APP_FAILED_TO_CREATE_TOKEN_FOR_ENV": "Failed to create delivery token for env \"%s\"",
"CLI_BOOTSTRAP_APP_FAILED_TO_CREATE_ENV_FILE_FOR_ENV": "Failed to setup env file for \"%s\"",
"CLI_BOOTSTRAP_APP_ENV_NOT_FOUND_FOR_THE_STACK": "No environments found for the stack",
"CLI_BOOTSTRAP_SUCCESS": "Project setup is successful!"
}
"CLI_BOOTSTRAP_INVALID_APP_NAME": "Invalid app name received, use cm:bootstrap see the list of apps supported",
"CLI_BOOTSTRAP_LOGIN_FAILED": "You need to login, first. See: auth:login --help",
"CLI_BOOTSTRAP_GITHUB_ACCESS_NOT_FOUND": "No Github access token found",
"CLI_BOOTSTRAP_START_CLONE_APP": "Cloning the selected app",
"CLI_BOOTSTRAP_REPO_NOT_FOUND": "Unable to find a repo for \"%s\"",
"CLI_BOOTSTRAP_NO_API_KEY_FOUND": "No API key generated for the stack",
"CLI_BOOTSTRAP_STACK_CREATION_FAILED": "Unable to create stack for content \"%s\"",
"CLI_BOOTSTRAP_APP_SELECTION_ENQUIRY": "Select an App",
"CLI_BOOTSTRAP_APP_COPY_SOURCE_CODE_DESTINATION_TYPE_ENQUIRY": "Choose the location where you want to copy the source code",
"CLI_BOOTSTRAP_APP_COPY_SOURCE_CODE_DESTINATION_ENQUIRY": "Enter destination path",
"CLI_BOOTSTRAP_NO_ACCESS_TOKEN_CREATED": "Note: Access token not created already, check out this link https://github.com/settings/tokens \n Provide github access token",
"CLI_BOOTSTRAP_TYPE_OF_APP_ENQUIRY": "Choose the type of app you want to clone",
"CLI_BOOTSTRAP_APP_FAILED_TO_CREATE_TOKEN_FOR_ENV": "Failed to create delivery token for env \"%s\"",
"CLI_BOOTSTRAP_APP_FAILED_TO_CREATE_ENV_FILE_FOR_ENV": "Failed to setup env file for \"%s\"",
"CLI_BOOTSTRAP_APP_ENV_NOT_FOUND_FOR_THE_STACK": "No environments found for the stack",
"CLI_BOOTSTRAP_SUCCESS": "Project setup is successful!",
"CLI_BOOTSTRAP_SUCCESS_LIVE_PREVIEW_NOTE": "Note: Before running the app, please turn on Live Preview in the CMS: Stack Settings > Live Preview > Enable Live Preview",
"CLI_BOOTSTRAP_INSTALLING_DEPENDENCIES": "Installing local dependencies with NPM",
"CLI_BOOTSTRAP_DEPENDENCIES_INSTALLED": "NPM dependencies installed successfully!",
"CLI_BOOTSTRAP_DEPENDENCIES_INSTALL_FAILED": "Failed to install NPM dependencies.",
"CLI_BOOTSTRAP_RUN_DEV_SERVER_ENQUIRY": "Do you want to install dependencies and run the app locally (npm install && npm run dev)?",
"CLI_BOOTSTRAP_STARTING_DEV_SERVER": "Starting development server...",
"CLI_BOOTSTRAP_DEV_SERVER_STARTED": "Development server started successfully! Check your terminal for more details.",
"CLI_BOOTSTRAP_DEV_SERVER_FAILED": "Failed to start development server. You can start it manually with 'npm run dev' in the project directory."
}
2 changes: 1 addition & 1 deletion packages/contentstack-bootstrap/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@contentstack/cli-cm-bootstrap",
"description": "Bootstrap contentstack apps",
"version": "1.14.1",
"version": "1.15.0",
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"scripts": {
Expand Down
52 changes: 51 additions & 1 deletion packages/contentstack-bootstrap/src/bootstrap/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as path from 'path';
import { execSync, spawn } from 'child_process';
import { cliux, sanitizePath } from '@contentstack/cli-utilities';
import { default as ContentStackSeed } from '@contentstack/cli-cm-seed/lib/commands/cm/stacks/seed';

Expand All @@ -19,6 +20,7 @@ export interface BootstrapOptions {
accessToken?: string;
appType: string;
livePreviewEnabled?: boolean;
runDevServer?: boolean;
master_locale: any;
}

Expand Down Expand Up @@ -113,20 +115,68 @@ export default class Bootstrap {
this.options.livePreviewEnabled as boolean,
this.options.seedParams.managementToken as string,
);

} else {
throw new Error(messageHandler.parse('CLI_BOOTSTRAP_NO_API_KEY_FOUND'));
}

if (this.options.livePreviewEnabled) {
cliux.print(
'Note: Before running the app, please configure a preview token, preview host, and app host in the environment file',
messageHandler.parse('CLI_BOOTSTRAP_SUCCESS_LIVE_PREVIEW_NOTE'),
{
color: 'yellow',
},
);
}

cliux.print(messageHandler.parse('CLI_BOOTSTRAP_SUCCESS'));

// Install dependencies and start development server if requested (after all other operations)
if (this.options.runDevServer) {
// Install project dependencies
cliux.loader(messageHandler.parse('CLI_BOOTSTRAP_INSTALLING_DEPENDENCIES'));
try {
execSync('npm install', {
cwd: this.cloneDirectory,
stdio: 'inherit'
});
cliux.loader();
cliux.print(messageHandler.parse('CLI_BOOTSTRAP_DEPENDENCIES_INSTALLED'));

// Start development server
cliux.print(messageHandler.parse('CLI_BOOTSTRAP_STARTING_DEV_SERVER'));
cliux.print(messageHandler.parse('CLI_BOOTSTRAP_DEV_SERVER_STARTED'));
cliux.print('You can now access your application. Check the output above for the local URL.');

// Run npm run dev using spawn for long-running process
const devProcess = spawn('npm', ['run', 'dev'], {
cwd: this.cloneDirectory,
stdio: 'inherit',
shell: true
});

devProcess.on('error', (error) => {
cliux.print(messageHandler.parse('CLI_BOOTSTRAP_DEV_SERVER_FAILED'), {
color: 'yellow',
});
console.error('Failed to start dev server:', error);
});

// Handle process exit
devProcess.on('exit', (code) => {
if (code !== 0 && code !== null) {
cliux.print(messageHandler.parse('CLI_BOOTSTRAP_DEV_SERVER_FAILED'), {
color: 'yellow',
});
}
});
} catch (installError: any) {
cliux.loader();
cliux.print(messageHandler.parse('CLI_BOOTSTRAP_DEPENDENCIES_INSTALL_FAILED'), {
color: 'yellow',
});
}
}
} catch (error) {
cliux.error(messageHandler.parse('CLI_BOOTSTRAP_STACK_CREATION_FAILED', this.appConfig.stack));
}
Expand Down
10 changes: 10 additions & 0 deletions packages/contentstack-bootstrap/src/bootstrap/interactive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@ export async function inquireLivePreviewSupport() {
return livePreviewEnabled;
}

export async function inquireRunDevServer() {
const { runDevServer } = await inquirer.prompt({
type: 'confirm',
name: 'runDevServer',
message: messageHandler.parse('CLI_BOOTSTRAP_RUN_DEV_SERVER_ENQUIRY'),
default: true,
});
return runDevServer;
}

export async function continueBootstrapCommand() {
const { shouldContinue } = await inquirer.prompt({
type: 'list',
Expand Down
Loading
Loading