@youcan/create-app 1.1.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 YouCan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/bin/exec.cmd ADDED
@@ -0,0 +1,3 @@
1
+ @echo off
2
+
3
+ node "%~dp0\exec.js" %*
package/bin/exec.js ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env node
2
+
3
+ process.removeAllListeners('warning');
4
+
5
+ // eslint-disable-next-line import/first
6
+ import execCreateAppCli from '../dist/index.js';
7
+
8
+ execCreateAppCli(false);
@@ -0,0 +1,11 @@
1
+ import { Cli } from '@youcan/cli-kit';
2
+ export default class Init extends Cli.Command {
3
+ static aliases: string[];
4
+ static description: string;
5
+ static flags: {
6
+ path: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
7
+ 'no-color': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
8
+ verbose: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
9
+ };
10
+ run(): Promise<void>;
11
+ }
@@ -0,0 +1,31 @@
1
+ import { cwd } from 'node:process';
2
+ import { Flags } from '@oclif/core';
3
+ import { Cli, Path } from '@youcan/cli-kit';
4
+ import initPrompt from '../prompts/init.js';
5
+ import initService from '../services/init.js';
6
+
7
+ class Init extends Cli.Command {
8
+ static aliases = ['create-app'];
9
+ static description = 'bootstaps a new youcan app';
10
+ static flags = {
11
+ ...Cli.commonFlags,
12
+ path: Flags.string({
13
+ char: 'p',
14
+ env: 'YC_FLAG_PATH',
15
+ parse: async (input) => Path.resolve(input),
16
+ default: async () => cwd(),
17
+ hidden: false,
18
+ }),
19
+ };
20
+ async run() {
21
+ const { flags } = await this.parse(Init);
22
+ const response = await initPrompt(this);
23
+ await initService(this, {
24
+ name: response.name,
25
+ directory: flags.path,
26
+ template: response.template,
27
+ });
28
+ }
29
+ }
30
+
31
+ export { Init as default };
@@ -0,0 +1,2 @@
1
+ declare function execCreateAppCli(development: boolean): Promise<void>;
2
+ export default execCreateAppCli;
package/dist/index.js ADDED
@@ -0,0 +1,10 @@
1
+ import { Cli } from '@youcan/cli-kit';
2
+
3
+ async function execCreateAppCli(development) {
4
+ await Cli.execCreate('app', {
5
+ moduleUrl: import.meta.url,
6
+ development,
7
+ });
8
+ }
9
+
10
+ export { execCreateAppCli as default };
@@ -0,0 +1,13 @@
1
+ import type { Cli } from '@youcan/cli-kit';
2
+ interface InitOutput {
3
+ name: string;
4
+ template: string;
5
+ }
6
+ export declare const TEMPLATES: {
7
+ nuxt: {
8
+ label: string;
9
+ url: string;
10
+ };
11
+ };
12
+ declare function initPrompt(command: Cli.Command): Promise<InitOutput>;
13
+ export default initPrompt;
@@ -0,0 +1,42 @@
1
+ const TEMPLATES = {
2
+ nuxt: {
3
+ label: 'Start with Nuxt (recommended)',
4
+ url: 'https:/github.com/youcan-shop/shop-app-template-nuxt',
5
+ },
6
+ };
7
+ async function initPrompt(command) {
8
+ const defaults = {
9
+ name: 'my-youcan-shop-app',
10
+ template: TEMPLATES.nuxt.url,
11
+ };
12
+ command.log('\nHello! Start by picking a name for your app.');
13
+ const response = await command.prompt([
14
+ {
15
+ name: 'name',
16
+ type: 'text',
17
+ initial: defaults.name,
18
+ message: 'Your app\'s name',
19
+ validate: (v) => {
20
+ if (!v.length) {
21
+ return 'App name cannot be empty';
22
+ }
23
+ if (v.length > 32) {
24
+ return 'App name cannot exceed 32 characters';
25
+ }
26
+ return true;
27
+ },
28
+ },
29
+ {
30
+ type: 'select',
31
+ name: 'template',
32
+ message: 'Your app\'s starting template',
33
+ format: v => TEMPLATES[v].url,
34
+ choices: Object
35
+ .entries(TEMPLATES)
36
+ .map(([k, v]) => ({ title: v.label, value: k })),
37
+ },
38
+ ]);
39
+ return response;
40
+ }
41
+
42
+ export { TEMPLATES, initPrompt as default };
@@ -0,0 +1,8 @@
1
+ import type { Cli } from '@youcan/cli-kit';
2
+ interface InitServiceOptions {
3
+ name: string;
4
+ directory: string;
5
+ template: string;
6
+ }
7
+ declare function initService(command: Cli.Command, options: InitServiceOptions): Promise<void>;
8
+ export default initService;
@@ -0,0 +1,42 @@
1
+ import { String, Path, Github, Filesystem, Tasks, Git } from '@youcan/cli-kit';
2
+
3
+ async function initService(command, options) {
4
+ const slug = String.hyphenate(options.name);
5
+ const outdir = Path.join(options.directory, slug);
6
+ await assertDirectoryAvailability(outdir, slug);
7
+ const repo = Github.parseRepositoryReference(options.template);
8
+ await Filesystem.tapIntoTmp(async (tmp) => {
9
+ const templateDownloadDirectory = Path.join(tmp, 'download');
10
+ const url = repo.branch ? `${repo.baseUrl}#${repo.branch}` : repo.baseUrl;
11
+ await Filesystem.mkdir(templateDownloadDirectory);
12
+ const tasks = [];
13
+ tasks.push({
14
+ title: `Downloading app template from ${url}..`,
15
+ task: async () => {
16
+ await Git.clone({
17
+ url,
18
+ shallow: true,
19
+ destination: templateDownloadDirectory,
20
+ });
21
+ },
22
+ }, {
23
+ title: `Copying files to ${outdir}`,
24
+ task: async () => {
25
+ await Filesystem.move(templateDownloadDirectory, outdir);
26
+ },
27
+ });
28
+ await Tasks.run(tasks);
29
+ });
30
+ command.output.info(`${slug} is ready for your to develop! Head to the docs for more information`);
31
+ command.output.info(' Developer Docs: https://developer.youcan.shop\n\n');
32
+ command.output.info(' To preview your app, run `pnpm dev`');
33
+ command.output.info(' For an overview of all the command, run `pnpm youcan app help`');
34
+ }
35
+ async function assertDirectoryAvailability(directory, name) {
36
+ const exists = await Filesystem.exists(directory);
37
+ if (exists) {
38
+ throw new Error(`\nThe directory \`${name}\` already exists, please choose a new name for your app`);
39
+ }
40
+ }
41
+
42
+ export { initService as default };
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@youcan/create-app",
3
+ "type": "module",
4
+ "version": "1.1.0-beta.0",
5
+ "description": "A CLI for creating YouCan Shop apps",
6
+ "author": "YouCan <contact@youcan.shop> (https://youcan.shop)",
7
+ "license": "MIT",
8
+ "keywords": [
9
+ "youcan",
10
+ "youcan-cli",
11
+ "youcan-app"
12
+ ],
13
+ "exports": {
14
+ ".": "./dist/index.js"
15
+ },
16
+ "main": "./dist/index.js",
17
+ "bin": {
18
+ "create-app": "./bin/exec.js"
19
+ },
20
+ "files": [
21
+ "bin",
22
+ "dist"
23
+ ],
24
+ "dependencies": {
25
+ "@oclif/core": "^2.15.0",
26
+ "@youcan/cli-kit": "1.1.0-beta.0"
27
+ },
28
+ "devDependencies": {
29
+ "@oclif/plugin-legacy": "^1.3.0",
30
+ "@types/node": "^18.18.0",
31
+ "shx": "^0.3.4"
32
+ },
33
+ "oclif": {
34
+ "bin": "create-app",
35
+ "dirname": "create-app",
36
+ "commands": "./dist/commands",
37
+ "plugins": [
38
+ "@oclif/plugin-help",
39
+ "@oclif/plugin-plugins",
40
+ "@oclif/plugin-commands",
41
+ "@oclif/plugin-autocomplete"
42
+ ],
43
+ "topicSeparator": " ",
44
+ "topics": {}
45
+ },
46
+ "scripts": {
47
+ "build": "shx rm -rf dist && tsc --noEmit && rollup --config rollup.config.js",
48
+ "dev": "rollup --config rollup.config.js --watch",
49
+ "release": "pnpm publish --access public",
50
+ "type-check": "tsc --noEmit",
51
+ "relink": "pnpm link --global"
52
+ }
53
+ }