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 all 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: 0 additions & 6 deletions .talismanrc
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
fileignoreconfig:
- filename: pnpm-lock.yaml
checksum: 6447e8e8342717ecec1500db29f16b7b1d64dfe2c5c788b405983b190f2b5c7e
- 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: 7260d9647ed789f09e454d63f9bdd0393e6dfd93f69d4dd2a1505c1c2a60b194
- 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 @@ -51,8 +47,6 @@ fileignoreconfig:
checksum: 9c79540ab8522736f17c3ae1c9bfea07784b6ed0aa41f5617c90ba6812b91e72
- 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
- filename: packages/contentstack-variants/src/import/variant-entries.ts
checksum: 01059fd6aa42deb6f070f57f4376c35a85684312fb7ca4757df5b53bfe0144d2
- filename: packages/contentstack/README.md
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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.15.0 darwin-arm64 node-v18.20.2
@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."
}
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