Skip to content
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

Feature: interactive meteor create command #12803

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
1aedbcf
feat added prompts when missing name or skeleton
mr-loop-1 Oct 3, 2023
8165af3
one based indexing in prompt
mr-loop-1 Oct 3, 2023
6443568
reset pretty print
mr-loop-1 Oct 3, 2023
8f852e8
refactored and consistent with existing code
mr-loop-1 Oct 7, 2023
787de7a
skeleton fix
mr-loop-1 Oct 7, 2023
14d92dd
removed unused fn call
mr-loop-1 Oct 7, 2023
c5d52c2
Merge branch 'devel' into feature/interactive-meteor-create-command
mr-loop-1 Oct 7, 2023
9c8b4ab
better prompt for skeleton
mr-loop-1 Oct 7, 2023
0011bcc
Merge branch 'devel' of https://github.com/mr-loop-1/meteor into feat…
mr-loop-1 Oct 7, 2023
8b1a081
Merge branch 'feature/interactive-meteor-create-command' of https://g…
mr-loop-1 Oct 7, 2023
0901b96
fix failed test and added info for skeletons
mr-loop-1 Oct 8, 2023
ae4c1fa
feat made create compatible with existing scripts
mr-loop-1 Oct 9, 2023
02e4fda
added space in skeleton info
mr-loop-1 Oct 9, 2023
cd23b75
Merge branch 'devel' into feature/interactive-meteor-create-command
Grubba27 Oct 11, 2023
8f66047
Merge branch 'devel' into feature/interactive-meteor-create-command
Grubba27 Oct 11, 2023
e3ac14b
Merge branch 'devel' into feature/interactive-meteor-create-command
StorytellerCZ Oct 16, 2023
143da6a
Merge branch 'devel' into feature/interactive-meteor-create-command
StorytellerCZ Oct 20, 2023
25066c6
Merge branch 'devel' into feature/interactive-meteor-create-command
mr-loop-1 Oct 21, 2023
09965d8
Merge branch 'devel' into feature/interactive-meteor-create-command
StorytellerCZ Oct 31, 2023
8b77b6a
Add inquirer.js to project
Grubba27 Oct 31, 2023
3d5b0da
Make cli more interactive
Grubba27 Oct 31, 2023
bedcde7
revert blaze submodules
Grubba27 Oct 31, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions scripts/dev-bundle-tool-package.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ var packageJson = {
"source-map": "0.7.3",
chalk: "4.1.1",
sqlite3: "5.0.2",
inquirer: "8.2.6",
"http-proxy": "1.18.1",
"is-reachable": "3.1.0",
"wordwrap": "1.0.0",
Expand Down
110 changes: 78 additions & 32 deletions tools/cli/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const {
red,
yellow
} = require('../console/console.js').colors;
const inquirer = require('inquirer');

var projectContextModule = require('../project-context.js');
var release = require('../packaging/release.js');

Expand Down Expand Up @@ -528,9 +530,26 @@ export const AVAILABLE_SKELETONS = [
"solid",
];

const SKELETON_INFO = {
"apollo": "To create a basic Apollo + React app",
"bare": "To create an empty app",
"blaze": "To create an app using Blaze",
"full": "To create a more complete scaffolded app",
"minimal": "To create an app with as few Meteor packages as possible",
"react": "To create a basic React-based app",
"typescript": "To create an app using TypeScript and React",
"vue": "To create a basic Vue3-based app",
"vue-2": "To create a basic Vue2-based app",
"svelte": "To create a basic Svelte app",
"tailwind": "To create an app using React and Tailwind",
"chakra-ui": "To create an app Chakra UI and React",
"solid": "To create a basic Solid app"
}

main.registerCommand({
name: 'create',
maxArgs: 1,
minArgs: 0,
options: {
list: { type: Boolean },
example: { type: String },
Expand All @@ -550,8 +569,9 @@ main.registerCommand({
solid: { type: Boolean },
prototype: { type: Boolean }
},
pretty: false,
catalogRefresh: new catalog.Refresh.Never()
}, function (options) {
}, async function (options) {
// Creating a package is much easier than creating an app, so if that's what
// we are doing, do that first. (For example, we don't springboard to the
// latest release to create a package if we are inside an app)
Expand Down Expand Up @@ -724,12 +744,64 @@ main.registerCommand({
return 0;
}

var appPathAsEntered;
if (options.args.length === 1) {
appPathAsEntered = options.args[0];
} else {
throw new main.ShowUsage;
/**
*
* @returns {{appPathAsEntered: string, skeleton: string }}
*/
const setup = async () => {
// meteor create app-name
if (options.args.length === 1) {
const appPathAsEntered = options.args[0];
const skeletonExplicitOption =
AVAILABLE_SKELETONS.find(skeleton => !!options[skeleton]);

const skeleton = skeletonExplicitOption || DEFAULT_SKELETON;

console.log(`Using ${green`${skeleton}`} skeleton`);
return {
appPathAsEntered,
skeleton
}
}
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
const prompt = inquirer.createPromptModule();
// meteor create
// need to ask app name and skeleton
const r = await prompt([
{
type: 'input',
name: 'appPathAsEntered',
message: `What is the name/path of your ${yellow`app`}? `,
default(){
return 'my-app';
}
},
{
type: 'list',
name: 'skeleton',
message: `Which ${yellow`skeleton`} do you want to use?`,
choices: AVAILABLE_SKELETONS.map(skeleton => {return `${capitalizeFirstLetter(skeleton)} # ${SKELETON_INFO[skeleton]}`}),
default(){
return `${capitalizeFirstLetter(DEFAULT_SKELETON)} # ${SKELETON_INFO[DEFAULT_SKELETON]}`;
},
filter(val) {
const skel = val.split(' ')[0];
console.log(`Using ${green`${skel}`} skeleton`);
return skel.toLowerCase();
}
}
])
Console.setPretty(true) // to not lose the console
return r;
}

var {
appPathAsEntered,
skeleton
} = await setup();

var appPath = files.pathResolve(appPathAsEntered);

if (files.findAppDir(appPath)) {
Expand Down Expand Up @@ -797,9 +869,6 @@ main.registerCommand({
toIgnore.push(/(\.html|\.js|\.css)/);
}

const skeletonExplicitOption = AVAILABLE_SKELETONS.find(skeleton =>
!!options[skeleton]);
const skeleton = skeletonExplicitOption || DEFAULT_SKELETON;
files.cp_r(files.pathJoin(__dirnameConverted, '..', 'static-assets',
`skel-${skeleton}`), appPath, {
transformFilename: function (f) {
Expand Down Expand Up @@ -925,29 +994,6 @@ main.registerCommand({
Console.url("https://www.meteor.com/cloud"),
Console.options({ indent: 2 }));

if (!!skeletonExplicitOption) {
// Notify people about the skeleton options
Console.info([
"",
"To start with a different app template, try one of the following:",
"",
].join("\n"));

cmd("meteor create --bare # to create an empty app");
cmd("meteor create --minimal # to create an app with as few Meteor packages as possible");
cmd("meteor create --full # to create a more complete scaffolded app");
cmd("meteor create --react # to create a basic React-based app");
cmd("meteor create --vue # to create a basic Vue3-based app");
cmd("meteor create --vue-2 # to create a basic Vue2-based app");
cmd("meteor create --apollo # to create a basic Apollo + React app");
cmd("meteor create --svelte # to create a basic Svelte app");
cmd("meteor create --typescript # to create an app using TypeScript and React");
cmd("meteor create --blaze # to create an app using Blaze");
cmd("meteor create --tailwind # to create an app using React and Tailwind");
cmd("meteor create --chakra-ui # to create an app Chakra UI and React");
cmd("meteor create --solid # to create a basic Solid app");
}

Console.info("");
});

Expand Down