(effects: CreateEffects = defaultEffects)
| 37 | }; |
| 38 | |
| 39 | export async function create(effects: CreateEffects = defaultEffects): Promise<void> { |
| 40 | const {clack} = effects; |
| 41 | clack.intro(`${inverse(" observable create ")} ${faint(`v${process.env.npm_package_version}`)}`); |
| 42 | const defaultRootPath = `.${op.sep}hello-framework`; |
| 43 | const defaultRootPathError = validateRootPath(defaultRootPath); |
| 44 | clack.log.success( |
| 45 | wrapAnsi( |
| 46 | "Welcome to Observable Framework! 👋 This command will help you create a new app. When prompted, you can press Enter to accept the default value.", |
| 47 | Math.min(80, effects.outputColumns) |
| 48 | ) + `\n\nWant help? ${link("https://observablehq.com/framework/getting-started")}` |
| 49 | ); |
| 50 | await clack.group( |
| 51 | { |
| 52 | rootPath: () => |
| 53 | clack.text({ |
| 54 | message: "Where should we create your project?", |
| 55 | placeholder: defaultRootPath, |
| 56 | defaultValue: defaultRootPathError ? undefined : defaultRootPath, |
| 57 | validate: (input) => validateRootPath(input, defaultRootPathError) |
| 58 | }), |
| 59 | appTitle: ({results: {rootPath}}) => |
| 60 | clack.text({ |
| 61 | message: "What should we title your app?", |
| 62 | placeholder: inferTitle(rootPath), |
| 63 | defaultValue: inferTitle(rootPath) |
| 64 | }), |
| 65 | includeSampleFiles: () => |
| 66 | clack.select({ |
| 67 | message: "Include sample files to help you get started?", |
| 68 | options: [ |
| 69 | {value: true, label: "Yes, include sample files", hint: "recommended"}, |
| 70 | {value: false, label: "No, create an empty project"} |
| 71 | ], |
| 72 | initialValue: true |
| 73 | }), |
| 74 | packageManager: () => |
| 75 | clack.select({ |
| 76 | message: "Install dependencies?", |
| 77 | options: [ |
| 78 | {value: "npm", label: "Yes, via npm", hint: "recommended"}, |
| 79 | {value: "yarn", label: "Yes, via yarn", hint: "recommended"}, |
| 80 | {value: null, label: "No"} |
| 81 | ], |
| 82 | initialValue: inferPackageManager("npm") |
| 83 | }), |
| 84 | initializeGit: () => |
| 85 | clack.confirm({ |
| 86 | message: "Initialize git repository?" |
| 87 | }), |
| 88 | installing: async ({results: {rootPath, appTitle, includeSampleFiles, packageManager, initializeGit}}) => { |
| 89 | rootPath = untildify(rootPath!); |
| 90 | let spinning = true; |
| 91 | const s = clack.spinner(); |
| 92 | s.start("Copying template files"); |
| 93 | const template = includeSampleFiles ? "default" : "empty"; |
| 94 | const templateDir = op.resolve(fileURLToPath(import.meta.url), "..", "..", "templates", template); |
| 95 | const runCommand = packageManager === "yarn" ? "yarn" : `${packageManager ?? "npm"} run`; |
| 96 | const installCommand = `${packageManager ?? "npm"} install`; |
no test coverage detected