@robineb/project-cli 1.1.0 → 1.1.2

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/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import path from "node:path";
3
3
  import fs from "node:fs/promises";
4
+ import { pathToFileURL } from "node:url";
4
5
  import { Command } from "commander";
5
6
  import * as p from "@clack/prompts";
6
7
  import { execa } from "execa";
@@ -26,7 +27,12 @@ const STACKS = [
26
27
  label: "PlatformIO / ESP32 (Arduino)",
27
28
  template: "esp32",
28
29
  },
29
- // TODO: hier deine weiteren Stacks eintragen (python, ...)
30
+ {
31
+ id: "python",
32
+ label: "Python Package (eigenes Template)",
33
+ template: "python",
34
+ },
35
+ // TODO: hier deine weiteren Stacks eintragen
30
36
  ];
31
37
  class GiteaProvider {
32
38
  baseUrl;
@@ -133,7 +139,7 @@ async function resolveGiteaCredentials() {
133
139
  // beginnen und enden. Leerzeichen wie in "esp 32" fallen damit sofort auf,
134
140
  // statt erst nach Scaffold + erstem Commit bei der Remote-Erstellung.
135
141
  const PROJECT_NAME_PATTERN = /^[A-Za-z0-9](?:[A-Za-z0-9._-]*[A-Za-z0-9])?$/;
136
- function validateProjectName(name) {
142
+ export function validateProjectName(name) {
137
143
  if (!name?.trim())
138
144
  return "Name darf nicht leer sein";
139
145
  if (!PROJECT_NAME_PATTERN.test(name)) {
@@ -152,7 +158,13 @@ async function scaffold(stack, targetDir, name) {
152
158
  const src = path.join(import.meta.dirname, "templates", stack.template);
153
159
  await fs.cp(src, targetDir, { recursive: true });
154
160
  await restoreGitignore(targetDir);
155
- await replacePlaceholders(targetDir, { projectName: name });
161
+ // pythonPackageName: Bindestriche/Punkte sind in Projektnamen erlaubt
162
+ // (Gitea/GitHub-Repo-Namen), aber kein gültiger Python-Bezeichner ->
163
+ // eigener, bereinigter Platzhalter fürs Python-Template.
164
+ await replacePlaceholders(targetDir, {
165
+ projectName: name,
166
+ pythonPackageName: name.toLowerCase().replace(/[^a-z0-9_]+/g, "_"),
167
+ });
156
168
  return;
157
169
  }
158
170
  throw new Error(`Stack ${stack.id} hat weder command noch template`);
@@ -165,7 +177,7 @@ async function restoreGitignore(targetDir) {
165
177
  const to = path.join(targetDir, ".gitignore");
166
178
  await fs.rename(from, to).catch(() => { });
167
179
  }
168
- async function replacePlaceholders(dir, vars) {
180
+ export async function replacePlaceholders(dir, vars) {
169
181
  const entries = await fs.readdir(dir, {
170
182
  withFileTypes: true,
171
183
  recursive: true,
@@ -188,6 +200,29 @@ async function replacePlaceholders(dir, vars) {
188
200
  if (replaced !== content)
189
201
  await fs.writeFile(full, replaced, "utf8");
190
202
  }
203
+ await renamePlaceholderPaths(dir, vars);
204
+ }
205
+ // Datei-/Ordnernamen mit Platzhaltern umbenennen (z.B. src/{{projectName}}/
206
+ // für ein Python-Package). Läuft rekursiv pro Verzeichnisebene von außen
207
+ // nach innen und fragt bei jedem Schritt den aktuellen Verzeichnisinhalt
208
+ // neu ab -> ein umbenannter Ordner wird mitsamt seinem (noch nicht
209
+ // umbenannten) Inhalt an die neue Stelle verschoben, bevor wir tiefer
210
+ // absteigen. Eine vorab gesammelte Pfadliste würde hier stale werden,
211
+ // sobald ein Vorfahre umbenannt ist.
212
+ async function renamePlaceholderPaths(dir, vars) {
213
+ const entries = await fs.readdir(dir, { withFileTypes: true });
214
+ for (const entry of entries) {
215
+ let renamedName = entry.name;
216
+ for (const [key, value] of Object.entries(vars)) {
217
+ renamedName = renamedName.replaceAll(`{{${key}}}`, value);
218
+ }
219
+ const oldPath = path.join(dir, entry.name);
220
+ const newPath = path.join(dir, renamedName);
221
+ if (renamedName !== entry.name)
222
+ await fs.rename(oldPath, newPath);
223
+ if (entry.isDirectory())
224
+ await renamePlaceholderPaths(newPath, vars);
225
+ }
191
226
  }
192
227
  async function initGit(targetDir) {
193
228
  const git = simpleGit(targetDir);
@@ -369,7 +404,13 @@ program
369
404
  .action(async () => {
370
405
  await addBoard(process.cwd());
371
406
  });
372
- program.parseAsync().catch((err) => {
373
- console.error(err instanceof Error ? err.message : err);
374
- process.exit(1);
375
- });
407
+ // Guard, damit ein Import dieser Datei (z.B. aus Tests) nicht sofort die
408
+ // interaktive CLI anwirft nur wenn die Datei direkt ausgeführt wird.
409
+ // pathToFileURL() statt string-Vergleich mit process.argv[1], weil das auf
410
+ // Windows sonst an Backslashes/URL-Encoding scheitert.
411
+ if (import.meta.url === pathToFileURL(process.argv[1] ?? "").href) {
412
+ program.parseAsync().catch((err) => {
413
+ console.error(err instanceof Error ? err.message : err);
414
+ process.exit(1);
415
+ });
416
+ }
@@ -0,0 +1 @@
1
+ * text=auto
@@ -0,0 +1,15 @@
1
+ # {{projectName}}
2
+
3
+ ## Entwicklung
4
+
5
+ python -m venv .venv
6
+ .venv\Scripts\activate # Windows
7
+ source .venv/bin/activate # macOS/Linux
8
+ pip install -e ".[dev]"
9
+
10
+ python -c "import {{pythonPackageName}}; {{pythonPackageName}}.main()"
11
+
12
+ ## Tests & Linting
13
+
14
+ pytest
15
+ ruff check .
@@ -0,0 +1,220 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[codz]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py.cover
50
+ *.lcov
51
+ .hypothesis/
52
+ .pytest_cache/
53
+ cover/
54
+
55
+ # Translations
56
+ *.mo
57
+ *.pot
58
+
59
+ # Django stuff:
60
+ *.log
61
+ local_settings.py
62
+ db.sqlite3
63
+ db.sqlite3-journal
64
+
65
+ # Flask stuff:
66
+ instance/
67
+ .webassets-cache
68
+
69
+ # Scrapy stuff:
70
+ .scrapy
71
+
72
+ # Sphinx documentation
73
+ docs/_build/
74
+
75
+ # PyBuilder
76
+ .pybuilder/
77
+ target/
78
+
79
+ # Jupyter Notebook
80
+ .ipynb_checkpoints
81
+
82
+ # IPython
83
+ profile_default/
84
+ ipython_config.py
85
+
86
+ # pyenv
87
+ # For a library or package, you might want to ignore these files since the code is
88
+ # intended to run in multiple environments; otherwise, check them in:
89
+ # .python-version
90
+
91
+ # pipenv
92
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
93
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
94
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
95
+ # install all needed dependencies.
96
+ # Pipfile.lock
97
+
98
+ # UV
99
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
100
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
101
+ # commonly ignored for libraries.
102
+ # uv.lock
103
+
104
+ # poetry
105
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
106
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
107
+ # commonly ignored for libraries.
108
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
109
+ # poetry.lock
110
+ # poetry.toml
111
+
112
+ # pdm
113
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
114
+ # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
115
+ # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
116
+ # pdm.lock
117
+ # pdm.toml
118
+ .pdm-python
119
+ .pdm-build/
120
+
121
+ # pixi
122
+ # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
123
+ # pixi.lock
124
+ # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
125
+ # in the .venv directory. It is recommended not to include this directory in version control.
126
+ .pixi/*
127
+ !.pixi/config.toml
128
+
129
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
130
+ __pypackages__/
131
+
132
+ # Celery stuff
133
+ celerybeat-schedule*
134
+ celerybeat.pid
135
+
136
+ # Redis
137
+ *.rdb
138
+ *.aof
139
+ *.pid
140
+
141
+ # RabbitMQ
142
+ mnesia/
143
+ rabbitmq/
144
+ rabbitmq-data/
145
+
146
+ # ActiveMQ
147
+ activemq-data/
148
+
149
+ # SageMath parsed files
150
+ *.sage.py
151
+
152
+ # Environments
153
+ .env
154
+ .envrc
155
+ .venv
156
+ env/
157
+ venv/
158
+ ENV/
159
+ env.bak/
160
+ venv.bak/
161
+
162
+ # Spyder project settings
163
+ .spyderproject
164
+ .spyproject
165
+
166
+ # Rope project settings
167
+ .ropeproject
168
+
169
+ # mkdocs documentation
170
+ /site
171
+
172
+ # mypy
173
+ .mypy_cache/
174
+ .dmypy.json
175
+ dmypy.json
176
+
177
+ # Pyre type checker
178
+ .pyre/
179
+
180
+ # pytype static type analyzer
181
+ .pytype/
182
+
183
+ # Cython debug symbols
184
+ cython_debug/
185
+
186
+ # PyCharm
187
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
188
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
189
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
190
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
191
+ # .idea/
192
+
193
+ # Abstra
194
+ # Abstra is an AI-powered process automation framework.
195
+ # Ignore directories containing user credentials, local state, and settings.
196
+ # Learn more at https://abstra.io/docs
197
+ .abstra/
198
+
199
+ # Visual Studio Code
200
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore that
201
+ # can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
202
+ # and can be added to the global gitignore or merged into this file. However, if you prefer, you
203
+ # could uncomment the following to ignore the entire vscode folder
204
+ # .vscode/
205
+ # Temporary file for partial code execution
206
+ tempCodeRunnerFile.py
207
+
208
+ # Ruff stuff:
209
+ .ruff_cache/
210
+
211
+ # PyPI configuration file
212
+ .pypirc
213
+
214
+ # Marimo
215
+ marimo/_static/
216
+ marimo/_lsp/
217
+ __marimo__/
218
+
219
+ # Streamlit
220
+ .streamlit/secrets.toml
@@ -0,0 +1,21 @@
1
+ [project]
2
+ name = "{{projectName}}"
3
+ version = "0.1.0"
4
+ requires-python = ">=3.12"
5
+ dependencies = []
6
+
7
+ [project.optional-dependencies]
8
+ dev = ["pytest>=8.0", "ruff>=0.6"]
9
+
10
+ [build-system]
11
+ requires = ["setuptools>=68"]
12
+ build-backend = "setuptools.build_meta"
13
+
14
+ [tool.setuptools.packages.find]
15
+ where = ["src"]
16
+
17
+ [tool.ruff]
18
+ line-length = 100
19
+
20
+ [tool.pytest.ini_options]
21
+ testpaths = ["tests"]
@@ -0,0 +1,2 @@
1
+ def main() -> None:
2
+ print("{{projectName}} läuft")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@robineb/project-cli",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "My own Project cli tool to start projecs",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -13,7 +13,7 @@
13
13
  "main": "./dist/index.js",
14
14
  "scripts": {
15
15
  "build": "tsc && node scripts/copy-templates.mjs",
16
- "test": "echo \"Error: no test specified\" && exit 1"
16
+ "test": "node --test index.test.ts"
17
17
  },
18
18
  "bin": {
19
19
  "project-cli": "dist/index.js"