@multiplatform.one/cli 1.0.27 → 1.0.30

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.
@@ -1,23 +1,80 @@
1
1
  // src/bin/multiplatformOne.ts
2
+ import fs from "fs/promises";
3
+ import inquirer from "inquirer";
4
+ import os from "os";
2
5
  import path from "path";
6
+ import pkg from "@multiplatform.one/cli/package.json";
3
7
  import { execa } from "execa";
4
8
  import { fileURLToPath } from "url";
5
9
  import { program } from "commander";
10
+ process.env.COOKIECUTTER = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../../scripts/cookiecutter.sh");
6
11
  program.name("multiplatform.one");
7
- program.command("init").argument("[remote]", "the remote to use", "https://gitlab.com/bitspur/multiplatform.one/cookiecutter").description("init multiplatform.one").action(async (remote) => {
12
+ program.version(pkg.version);
13
+ program.command("init").argument("[remote]", "the remote to use", "https://gitlab.com/bitspur/multiplatform.one/cookiecutter").option("--name <name>", "the name of the project").description("init multiplatform.one").action(async (remote) => {
14
+ if ((await execa("git", [
15
+ "rev-parse",
16
+ "--is-inside-work-tree"
17
+ ])).stdout.trim() === "true") {
18
+ throw new Error("multiplatform.one cannot be initialized inside a git repository");
19
+ }
20
+ const cookieCutterConfig = {
21
+ name: program.opts().name || (await inquirer.prompt([
22
+ {
23
+ message: "What is the project name?",
24
+ name: "name",
25
+ type: "input"
26
+ }
27
+ ]))?.name
28
+ };
29
+ const cookieCutterConfigFile = await fs.mkdtemp(path.join(os.tmpdir(), "multiplatform-"));
30
+ await fs.writeFile(cookieCutterConfigFile, JSON.stringify(cookieCutterConfig, null, 2));
8
31
  await execa("sh", [
9
32
  path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../../scripts/init.sh"),
33
+ "-f",
34
+ "--config-file",
35
+ cookieCutterConfigFile,
10
36
  remote
11
37
  ], {
12
38
  stdio: "inherit"
13
39
  });
14
40
  });
15
41
  program.command("update").argument("[remote]", "the remote to use", "https://gitlab.com/bitspur/multiplatform.one/cookiecutter").description("update multiplatform.one").action(async (remote) => {
42
+ if ((await execa("git", [
43
+ "rev-parse",
44
+ "--is-inside-work-tree"
45
+ ])).stdout.trim() !== "true") {
46
+ throw new Error("multiplatform.one cannot be updated outside of a git repository");
47
+ }
48
+ if ((await execa("git", [
49
+ "diff",
50
+ "--cached",
51
+ "--quiet"
52
+ ])).stdout.trim() !== "true") {
53
+ throw new Error("multiplatform.one cannot be updated with uncommitted changes");
54
+ }
55
+ const projectRoot = (await execa("git", [
56
+ "rev-parse",
57
+ "--show-toplevel"
58
+ ])).stdout.trim();
59
+ let cookieCutterConfig;
60
+ if ((await fs.stat(path.resolve(projectRoot, "package.json"))).isFile() && (await fs.stat(path.resolve(projectRoot, "app/package.json"))).isFile() && JSON.parse(await fs.readFile(path.resolve(projectRoot, "app/package.json"), "utf8"))?.dependencies?.["multiplatform.one"]?.length) {
61
+ const name = JSON.parse(await fs.readFile(path.resolve(projectRoot, "package.json"), "utf8"))?.name;
62
+ if (name) cookieCutterConfig = {
63
+ name
64
+ };
65
+ }
66
+ if (!cookieCutterConfig) throw new Error("not a multiplatform.one project");
67
+ const cookieCutterConfigFile = await fs.mkdtemp(path.join(os.tmpdir(), "multiplatform-"));
68
+ await fs.writeFile(cookieCutterConfigFile, JSON.stringify(cookieCutterConfig, null, 2));
16
69
  await execa("sh", [
17
70
  path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../../scripts/update.sh"),
71
+ "-f",
72
+ "--config-file",
73
+ cookieCutterConfigFile,
18
74
  remote
19
75
  ], {
20
- stdio: "inherit"
76
+ stdio: "inherit",
77
+ cwd: projectRoot
21
78
  });
22
79
  });
23
80
  program.parse(process.argv);
@@ -0,0 +1,5 @@
1
+ interface CookieCutterConfig {
2
+ name: string;
3
+ }
4
+
5
+ export type { CookieCutterConfig };
package/lib/types.mjs ADDED
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@multiplatform.one/cli",
3
- "version": "1.0.27",
3
+ "version": "1.0.30",
4
4
  "author": "BitSpur <support@bitspur.com> (https://bitspur.com)",
5
5
  "contributors": [
6
6
  {
@@ -48,14 +48,16 @@
48
48
  "node": ">= 16.0"
49
49
  },
50
50
  "devDependencies": {
51
+ "@types/inquirer": "^9.0.7",
51
52
  "@types/node": "~20.12.13",
52
53
  "tsup": "^8.1.0",
53
54
  "typescript": "~5.3.3",
54
- "@multiplatform.one/utils": "^0.0.12"
55
+ "@multiplatform.one/utils": "^0.0.15"
55
56
  },
56
57
  "dependencies": {
57
58
  "commander": "^9.5.0",
58
- "execa": "^9.2.0"
59
+ "execa": "^9.2.0",
60
+ "inquirer": "^9.2.23"
59
61
  },
60
62
  "transpileModules": [
61
63
  "#ansi-styles",
@@ -0,0 +1,19 @@
1
+ #!/bin/sh
2
+
3
+ if ! which cookiecutter >/dev/null 2>&1; then
4
+ if [ "$(uname 2>/dev/null | tr '[:upper:]' '[:lower:]' 2>/dev/null)" = "darwin" ] && which brew >/dev/null 2>&1; then
5
+ brew install cookiecutter
6
+ else
7
+ if which pipx >/dev/null 2>&1; then
8
+ pipx install cookiecutter
9
+ else
10
+ python3 -m pip install --user cookiecutter
11
+ fi
12
+ fi
13
+ fi
14
+ if ! which cookiecutter >/dev/null 2>&1; then
15
+ echo "Failed to install cookiecutter. Please install it manually." >&2
16
+ exit 1
17
+ fi
18
+
19
+ cookiecutter -f "$@"
package/scripts/init.sh CHANGED
@@ -1,3 +1,3 @@
1
1
  #!/bin/sh
2
2
 
3
- cookiecutter "$@"
3
+ $COOKIECUTTER "$@"
package/scripts/update.sh CHANGED
@@ -2,26 +2,13 @@
2
2
 
3
3
  set -e
4
4
 
5
- if ! (cat app/package.json | grep -q multiplatform.one); then
6
- echo "\033[0;31mError:\033[0m not a multiplatform.one project" >&2
7
- exit 1
8
- fi
9
- if ! git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
10
- echo "\033[0;31mError:\033[0m not inside a git repository" >&2
11
- exit 1
12
- fi
13
- cd "$(git rev-parse --show-toplevel)"
14
- if ! git diff --cached --exit-code > /dev/null; then
15
- echo "\033[0;31mError:\033[0m there are uncommitted changes" >&2
16
- exit 1
17
- fi
18
5
  git clean -fxd
19
6
  PROJECT_DIR="$(pwd)"
20
7
  TEMP_DIR="$(mktemp -d)"
21
8
  trap 'rm -rf "$TEMP_DIR"' EXIT
22
9
  echo "TEMP_DIR $TEMP_DIR"
23
10
  cd "$TEMP_DIR"
24
- cookiecutter "$@"
11
+ $COOKIECUTTER "$@"
25
12
  COOKIECUTTER_DIR="$TEMP_DIR/$(ls "$TEMP_DIR")"
26
13
  cd "$COOKIECUTTER_DIR"
27
14
  git add .
@@ -19,21 +19,57 @@
19
19
  * limitations under the License.
20
20
  */
21
21
 
22
+ import fs from 'fs/promises';
23
+ import inquirer from 'inquirer';
24
+ import os from 'os';
22
25
  import path from 'path';
26
+ import pkg from '@multiplatform.one/cli/package.json';
27
+ import type { CookieCutterConfig } from '../types';
23
28
  import { execa } from 'execa';
24
29
  import { fileURLToPath } from 'url';
25
30
  import { program } from 'commander';
26
31
 
32
+ process.env.COOKIECUTTER = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../scripts/cookiecutter.sh');
27
33
  program.name('multiplatform.one');
34
+ program.version(pkg.version);
28
35
 
29
36
  program
30
37
  .command('init')
31
38
  .argument('[remote]', 'the remote to use', 'https://gitlab.com/bitspur/multiplatform.one/cookiecutter')
39
+ .option('--name <name>', 'the name of the project')
32
40
  .description('init multiplatform.one')
33
41
  .action(async (remote) => {
34
- await execa('sh', [path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../scripts/init.sh'), remote], {
35
- stdio: 'inherit',
36
- });
42
+ if ((await execa('git', ['rev-parse', '--is-inside-work-tree'])).stdout.trim() === 'true') {
43
+ throw new Error('multiplatform.one cannot be initialized inside a git repository');
44
+ }
45
+ const cookieCutterConfig: CookieCutterConfig = {
46
+ name:
47
+ program.opts().name ||
48
+ (
49
+ await inquirer.prompt([
50
+ {
51
+ message: 'What is the project name?',
52
+ name: 'name',
53
+ type: 'input',
54
+ },
55
+ ])
56
+ )?.name,
57
+ };
58
+ const cookieCutterConfigFile = await fs.mkdtemp(path.join(os.tmpdir(), 'multiplatform-'));
59
+ await fs.writeFile(cookieCutterConfigFile, JSON.stringify(cookieCutterConfig, null, 2));
60
+ await execa(
61
+ 'sh',
62
+ [
63
+ path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../scripts/init.sh'),
64
+ '-f',
65
+ '--config-file',
66
+ cookieCutterConfigFile,
67
+ remote,
68
+ ],
69
+ {
70
+ stdio: 'inherit',
71
+ },
72
+ );
37
73
  });
38
74
 
39
75
  program
@@ -41,9 +77,41 @@ program
41
77
  .argument('[remote]', 'the remote to use', 'https://gitlab.com/bitspur/multiplatform.one/cookiecutter')
42
78
  .description('update multiplatform.one')
43
79
  .action(async (remote) => {
44
- await execa('sh', [path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../scripts/update.sh'), remote], {
45
- stdio: 'inherit',
46
- });
80
+ if ((await execa('git', ['rev-parse', '--is-inside-work-tree'])).stdout.trim() !== 'true') {
81
+ throw new Error('multiplatform.one cannot be updated outside of a git repository');
82
+ }
83
+ if ((await execa('git', ['diff', '--cached', '--quiet'])).stdout.trim() !== 'true') {
84
+ throw new Error('multiplatform.one cannot be updated with uncommitted changes');
85
+ }
86
+ const projectRoot = (await execa('git', ['rev-parse', '--show-toplevel'])).stdout.trim();
87
+ let cookieCutterConfig: CookieCutterConfig | undefined;
88
+ if (
89
+ (await fs.stat(path.resolve(projectRoot, 'package.json'))).isFile() &&
90
+ (await fs.stat(path.resolve(projectRoot, 'app/package.json'))).isFile() &&
91
+ JSON.parse(await fs.readFile(path.resolve(projectRoot, 'app/package.json'), 'utf8'))?.dependencies?.[
92
+ 'multiplatform.one'
93
+ ]?.length
94
+ ) {
95
+ const name = JSON.parse(await fs.readFile(path.resolve(projectRoot, 'package.json'), 'utf8'))?.name;
96
+ if (name) cookieCutterConfig = { name };
97
+ }
98
+ if (!cookieCutterConfig) throw new Error('not a multiplatform.one project');
99
+ const cookieCutterConfigFile = await fs.mkdtemp(path.join(os.tmpdir(), 'multiplatform-'));
100
+ await fs.writeFile(cookieCutterConfigFile, JSON.stringify(cookieCutterConfig, null, 2));
101
+ await execa(
102
+ 'sh',
103
+ [
104
+ path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../scripts/update.sh'),
105
+ '-f',
106
+ '--config-file',
107
+ cookieCutterConfigFile,
108
+ remote,
109
+ ],
110
+ {
111
+ stdio: 'inherit',
112
+ cwd: projectRoot,
113
+ },
114
+ );
47
115
  });
48
116
 
49
117
  program.parse(process.argv);
package/src/types.ts ADDED
@@ -0,0 +1,24 @@
1
+ /*
2
+ * File: /src/types.ts
3
+ * Project: @multiplatform.one/cli
4
+ * File Created: 23-06-2024 10:13:38
5
+ * Author: Clay Risser
6
+ * -----
7
+ * BitSpur (c) Copyright 2021 - 2024
8
+ *
9
+ * Licensed under the Apache License, Version 2.0 (the "License");
10
+ * you may not use this file except in compliance with the License.
11
+ * You may obtain a copy of the License at
12
+ *
13
+ * http://www.apache.org/licenses/LICENSE-2.0
14
+ *
15
+ * Unless required by applicable law or agreed to in writing, software
16
+ * distributed under the License is distributed on an "AS IS" BASIS,
17
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ * See the License for the specific language governing permissions and
19
+ * limitations under the License.
20
+ */
21
+
22
+ export interface CookieCutterConfig {
23
+ name: string;
24
+ }