create-cs-object 0.1.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 +202 -0
- package/NOTICE +4 -0
- package/README.md +23 -0
- package/dist/cli.js +83 -0
- package/package.json +50 -0
- package/template/AGENTS.md +17 -0
- package/template/README.md +27 -0
- package/template/authoring.md +18 -0
- package/template/brief.md +9 -0
- package/template/calculations/report.cso.py +14 -0
- package/template/gitignore +8 -0
- package/template/references/README.md +5 -0
- package/template/requirements.txt +1 -0
- package/template/scripts/dev.ts +57 -0
- package/template/scripts/setup.ts +74 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Create a local calculation project
|
|
2
|
+
|
|
3
|
+
Use Node.js 24 or newer and Python 3.11 or newer. After the versioned npm and
|
|
4
|
+
Python dependencies are published:
|
|
5
|
+
|
|
6
|
+
```sh
|
|
7
|
+
npm create cs-object my-report
|
|
8
|
+
cd my-report
|
|
9
|
+
npm run dev
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
The initializer creates an owned project template, installs its exact CLI
|
|
13
|
+
dependency, prepares `.venv`, and installs Chromium. It preserves generated
|
|
14
|
+
files after setup failure; run `npm run setup` in the project to retry.
|
|
15
|
+
Existing destinations are never overwritten.
|
|
16
|
+
|
|
17
|
+
Use `--skip-install` to create files without installing dependencies.
|
|
18
|
+
The generated project contains a synthetic rectangle calculation, an editable
|
|
19
|
+
brief, reference storage, and agent-neutral authoring guidance. The CLI serves
|
|
20
|
+
the browser and report API. The initializer contains no server implementation.
|
|
21
|
+
|
|
22
|
+
Package tests execute a real npm archive in a temporary consumer. Full runtime
|
|
23
|
+
acceptance belongs to the repository's installed integration checks.
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/cli.ts
|
|
4
|
+
import { spawnSync } from "child_process";
|
|
5
|
+
import { cpSync, mkdirSync, renameSync, writeFileSync } from "fs";
|
|
6
|
+
import { join, resolve } from "path";
|
|
7
|
+
import { fileURLToPath } from "url";
|
|
8
|
+
var args = process.argv.slice(2);
|
|
9
|
+
var usage = "Usage: npm create cs-object <project-name> [--skip-install]\n";
|
|
10
|
+
var destination;
|
|
11
|
+
try {
|
|
12
|
+
if (args.length === 1 && ["--help", "-h"].includes(args[0])) {
|
|
13
|
+
process.stdout.write(usage);
|
|
14
|
+
} else {
|
|
15
|
+
const [name, ...options] = args;
|
|
16
|
+
if (!name || !/^[a-z0-9][a-z0-9._-]*$/.test(name) || name.length > 214 || ["node_modules", "favicon.ico"].includes(name) || options.length > 1 || options.some((option) => option !== "--skip-install"))
|
|
17
|
+
throw new Error(usage.trim());
|
|
18
|
+
if (Number(process.versions.node.split(".")[0]) < 24)
|
|
19
|
+
throw new Error("Node.js 24 or newer is required.");
|
|
20
|
+
const target = resolve(name);
|
|
21
|
+
mkdirSync(target);
|
|
22
|
+
destination = target;
|
|
23
|
+
cpSync(fileURLToPath(new URL("../template", import.meta.url)), target, {
|
|
24
|
+
recursive: true,
|
|
25
|
+
force: false,
|
|
26
|
+
errorOnExist: true
|
|
27
|
+
});
|
|
28
|
+
renameSync(join(target, "gitignore"), join(target, ".gitignore"));
|
|
29
|
+
writeFileSync(
|
|
30
|
+
join(target, "package.json"),
|
|
31
|
+
`${JSON.stringify(
|
|
32
|
+
{
|
|
33
|
+
name,
|
|
34
|
+
version: "0.1.0",
|
|
35
|
+
private: true,
|
|
36
|
+
type: "module",
|
|
37
|
+
engines: { node: ">=24" },
|
|
38
|
+
scripts: {
|
|
39
|
+
setup: "npm install && node scripts/setup.ts",
|
|
40
|
+
dev: "node scripts/dev.ts"
|
|
41
|
+
},
|
|
42
|
+
dependencies: { "@cs-object/cli": "0.1.0" }
|
|
43
|
+
},
|
|
44
|
+
null,
|
|
45
|
+
2
|
|
46
|
+
)}
|
|
47
|
+
`
|
|
48
|
+
);
|
|
49
|
+
if (!options.includes("--skip-install")) {
|
|
50
|
+
const npmPath = process.env.npm_execpath;
|
|
51
|
+
const result = spawnSync(
|
|
52
|
+
npmPath ? process.execPath : "npm",
|
|
53
|
+
[...npmPath ? [npmPath] : [], "run", "setup"],
|
|
54
|
+
{
|
|
55
|
+
cwd: target,
|
|
56
|
+
stdio: "inherit",
|
|
57
|
+
shell: !npmPath && process.platform === "win32"
|
|
58
|
+
}
|
|
59
|
+
);
|
|
60
|
+
if (result.error || result.status !== 0)
|
|
61
|
+
throw new Error(result.error?.message ?? "Project setup failed.");
|
|
62
|
+
}
|
|
63
|
+
process.stdout.write(
|
|
64
|
+
`Created ${name}.
|
|
65
|
+
|
|
66
|
+
cd ${name}
|
|
67
|
+
${options.includes("--skip-install") ? "npm run setup\n" : ""}npm run dev
|
|
68
|
+
`
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
} catch (error) {
|
|
72
|
+
process.stderr.write(
|
|
73
|
+
`${error instanceof Error ? error.message : String(error)}
|
|
74
|
+
`
|
|
75
|
+
);
|
|
76
|
+
if (destination)
|
|
77
|
+
process.stderr.write(
|
|
78
|
+
`Your project remains at ${destination}.
|
|
79
|
+
Run npm run setup in that directory to retry.
|
|
80
|
+
`
|
|
81
|
+
);
|
|
82
|
+
process.exitCode = 1;
|
|
83
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "create-cs-object",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Create a local CalculationSourceObject report project.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"create-cs-object": "./dist/cli.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"template",
|
|
13
|
+
"README.md",
|
|
14
|
+
"LICENSE",
|
|
15
|
+
"NOTICE"
|
|
16
|
+
],
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">=24"
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsup",
|
|
22
|
+
"prepack": "npm run build",
|
|
23
|
+
"pretest": "npm run build",
|
|
24
|
+
"test": "node --test tests/*.test.ts",
|
|
25
|
+
"typecheck": "tsc --noEmit --pretty false",
|
|
26
|
+
"lint": "biome lint src tests template/scripts"
|
|
27
|
+
},
|
|
28
|
+
"overrides": {
|
|
29
|
+
"esbuild": "0.28.2"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@biomejs/biome": "2.5.14",
|
|
33
|
+
"@types/node": "^26",
|
|
34
|
+
"tsup": "^8.5.1",
|
|
35
|
+
"typescript": "^5"
|
|
36
|
+
},
|
|
37
|
+
"repository": {
|
|
38
|
+
"type": "git",
|
|
39
|
+
"url": "git+https://github.com/viktar-b/CalculationSourceObject.git",
|
|
40
|
+
"directory": "packages/create-cs-object"
|
|
41
|
+
},
|
|
42
|
+
"homepage": "https://github.com/viktar-b/CalculationSourceObject#readme",
|
|
43
|
+
"bugs": {
|
|
44
|
+
"url": "https://github.com/viktar-b/CalculationSourceObject/issues"
|
|
45
|
+
},
|
|
46
|
+
"publishConfig": {
|
|
47
|
+
"access": "public",
|
|
48
|
+
"registry": "https://registry.npmjs.org/"
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Work on this calculation
|
|
2
|
+
|
|
3
|
+
Before changing formulas, read [brief.md](brief.md) and the relevant material in
|
|
4
|
+
[references](references/README.md). Ask about missing assumptions that change
|
|
5
|
+
the result, units, load case, or acceptance criteria. Record the agreed scope
|
|
6
|
+
in the brief and cite the source of each engineering requirement.
|
|
7
|
+
|
|
8
|
+
Edit formulas in `calculations/report.cso.py`; the browser edits numeric inputs.
|
|
9
|
+
Read [authoring.md](authoring.md) before changing source or notation. Keep inputs,
|
|
10
|
+
units, assumptions, intermediate steps, references, and outputs inspectable.
|
|
11
|
+
|
|
12
|
+
Run the calculation with representative inputs and review its rendered report.
|
|
13
|
+
Report source-to-document consistency, independent numerical agreement, and
|
|
14
|
+
human engineering approval separately. Establish expected reference values
|
|
15
|
+
independently of the execution under test. Inspect every PDF page before delivery.
|
|
16
|
+
|
|
17
|
+
This project runs on localhost. Deployment is outside its calculation workflow.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Run your calculation
|
|
2
|
+
|
|
3
|
+
Use Node.js 24 or newer and Python 3.11 or newer. The initializer installs the
|
|
4
|
+
Node dependencies, creates a private `.venv`, and installs Chromium for PDF output.
|
|
5
|
+
|
|
6
|
+
```sh
|
|
7
|
+
npm run dev
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
Open the localhost address printed in the terminal. Edit numeric inputs in the
|
|
11
|
+
browser, calculate, review the report, and download its PDF. Change formulas in
|
|
12
|
+
`calculations/report.cso.py`, then calculate again. If you change the declared
|
|
13
|
+
inputs, reload the browser page to rebuild its form. Existing report downloads
|
|
14
|
+
remain tied to their captured run until that run expires or the server stops.
|
|
15
|
+
|
|
16
|
+
To choose a port, run `npm run dev -- --port 4173`. Use port `0` to select an
|
|
17
|
+
available port. Stop the server with Ctrl+C and use the same command to restart.
|
|
18
|
+
|
|
19
|
+
If setup failed or you used `--skip-install`, run `npm run setup`.
|
|
20
|
+
Set `PYTHON` to a Python executable if automatic detection cannot find Python
|
|
21
|
+
3.11 or newer. Setup can be run again without replacing calculation files.
|
|
22
|
+
|
|
23
|
+
Before replacing the starter, update [the brief](brief.md), collect
|
|
24
|
+
[references](references/README.md), and read [the authoring notes](authoring.md).
|
|
25
|
+
Source-to-document consistency checks that the documented formulas agree with
|
|
26
|
+
the captured calculation. Independent reference checks and engineering approval
|
|
27
|
+
remain separate review steps. No deployment is needed.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Write scalar calculations
|
|
2
|
+
|
|
3
|
+
Use constrained Python in `calculations/report.cso.py`. Declare documented inputs
|
|
4
|
+
and assignments with `Annotated[float, symbol(...)]` or
|
|
5
|
+
`Annotated[int, symbol(...)]`. A plain `float` or `int` parameter needs a separate
|
|
6
|
+
documented `given()` assignment.
|
|
7
|
+
Use descriptive names and qualified glyphs such as `A_{rect}`. Define units and
|
|
8
|
+
explain each glyph qualifier. Return a dictionary that selects documented values.
|
|
9
|
+
|
|
10
|
+
Use finite scalar numbers and arithmetic `+`, `-`, `*`, `/`, and `**`.
|
|
11
|
+
Python booleans are not numeric inputs. Declare `float` for fractional results.
|
|
12
|
+
Exact integers must fit within ±(2**53 - 1). Keep assumptions and references in
|
|
13
|
+
literal `text(id=..., content=...)` calls so they appear in the report.
|
|
14
|
+
|
|
15
|
+
The [maintained authoring guide](https://github.com/viktar-b/CalculationSourceObject/blob/main/docs/authoring.md)
|
|
16
|
+
describes supported functions, composition, and document content. Unsupported
|
|
17
|
+
Python constructs must be replaced with supported scalar expressions before
|
|
18
|
+
the calculation can pass verification.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Calculation brief
|
|
2
|
+
|
|
3
|
+
The starter calculates the area of a flat rectangle in square metres.
|
|
4
|
+
Its width and height are positive lengths in metres, with defaults of 2 and 3.
|
|
5
|
+
The sides meet at right angles. The output is the product of those lengths.
|
|
6
|
+
|
|
7
|
+
Replace this example scope with the purpose, assumptions, input ranges, units,
|
|
8
|
+
required outputs, and acceptance criteria for your calculation. Put supporting
|
|
9
|
+
material in [references](references/README.md).
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from typing import Annotated
|
|
2
|
+
from cso_python import calculation, section, symbol, text
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
@calculation(id="rectangle-area", title="Rectangle area")
|
|
6
|
+
@section(title="Rectangle", root=True)
|
|
7
|
+
def calculate(
|
|
8
|
+
width: Annotated[float, symbol(glyph="w_{rect}", description="Rectangle width", unit="m")] = 2.0,
|
|
9
|
+
height: Annotated[float, symbol(glyph="h_{rect}", description="Rectangle height", unit="m")] = 3.0,
|
|
10
|
+
):
|
|
11
|
+
text(id="assumptions", content="Assume a flat rectangle with perpendicular sides and positive dimensions. The qualifier rect means rectangle.")
|
|
12
|
+
text(id="reference", content="Reference: the elementary rectangle relation, area equals width multiplied by height. See brief.md for the project scope.")
|
|
13
|
+
area: Annotated[float, symbol(glyph="A_{rect}", description="Rectangle area", unit="m^2")] = width * height
|
|
14
|
+
return {"area": area}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
cso-python==0.1.0
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
3
|
+
import { createRequire } from 'node:module';
|
|
4
|
+
import { dirname, join } from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
|
|
7
|
+
const project = fileURLToPath(new URL('..', import.meta.url));
|
|
8
|
+
const python = join(
|
|
9
|
+
project,
|
|
10
|
+
'.venv',
|
|
11
|
+
process.platform === 'win32' ? 'Scripts/python.exe' : 'bin/python',
|
|
12
|
+
);
|
|
13
|
+
try {
|
|
14
|
+
if (!existsSync(python))
|
|
15
|
+
throw new Error(
|
|
16
|
+
'Run npm run setup to prepare the project Python environment.',
|
|
17
|
+
);
|
|
18
|
+
const require = createRequire(import.meta.url);
|
|
19
|
+
const cli = join(
|
|
20
|
+
dirname(require.resolve('@cs-object/cli/package.json')),
|
|
21
|
+
'dist/cli.js',
|
|
22
|
+
);
|
|
23
|
+
const child = spawn(
|
|
24
|
+
process.execPath,
|
|
25
|
+
[
|
|
26
|
+
cli,
|
|
27
|
+
'dev',
|
|
28
|
+
'calculations/report.cso.py',
|
|
29
|
+
'--function',
|
|
30
|
+
'calculate',
|
|
31
|
+
...process.argv.slice(2),
|
|
32
|
+
],
|
|
33
|
+
{
|
|
34
|
+
cwd: project,
|
|
35
|
+
env: { ...process.env, PYTHON: python },
|
|
36
|
+
stdio: 'inherit',
|
|
37
|
+
},
|
|
38
|
+
);
|
|
39
|
+
const interrupt = () => child.kill('SIGINT');
|
|
40
|
+
const terminate = () => child.kill('SIGTERM');
|
|
41
|
+
process.on('SIGINT', interrupt);
|
|
42
|
+
process.on('SIGTERM', terminate);
|
|
43
|
+
child.once('error', (error) => {
|
|
44
|
+
process.stderr.write(`${error.message}\n`);
|
|
45
|
+
});
|
|
46
|
+
child.once('close', (code, signal) => {
|
|
47
|
+
process.off('SIGINT', interrupt);
|
|
48
|
+
process.off('SIGTERM', terminate);
|
|
49
|
+
process.exitCode =
|
|
50
|
+
code ?? (signal === 'SIGINT' ? 130 : signal === 'SIGTERM' ? 143 : 1);
|
|
51
|
+
});
|
|
52
|
+
} catch (error) {
|
|
53
|
+
process.stderr.write(
|
|
54
|
+
`${error instanceof Error ? error.message : String(error)}\n`,
|
|
55
|
+
);
|
|
56
|
+
process.exitCode = 1;
|
|
57
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
3
|
+
import { createRequire } from 'node:module';
|
|
4
|
+
import { dirname, join } from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
|
|
7
|
+
const project = fileURLToPath(new URL('..', import.meta.url));
|
|
8
|
+
const python = join(
|
|
9
|
+
project,
|
|
10
|
+
'.venv',
|
|
11
|
+
process.platform === 'win32' ? 'Scripts/python.exe' : 'bin/python',
|
|
12
|
+
);
|
|
13
|
+
function run(command: string, args: string[]) {
|
|
14
|
+
const result = spawnSync(command, args, { cwd: project, stdio: 'inherit' });
|
|
15
|
+
if (result.error || result.status !== 0)
|
|
16
|
+
throw new Error(
|
|
17
|
+
result.error?.message ?? `${command} failed with exit ${result.status}.`,
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
function supportedPython(command: string) {
|
|
21
|
+
return (
|
|
22
|
+
spawnSync(
|
|
23
|
+
command,
|
|
24
|
+
[
|
|
25
|
+
'-I',
|
|
26
|
+
'-c',
|
|
27
|
+
'import sys; sys.exit(0 if sys.version_info >= (3, 11) else 1)',
|
|
28
|
+
],
|
|
29
|
+
{ timeout: 10_000, stdio: 'ignore' },
|
|
30
|
+
).status === 0
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
try {
|
|
34
|
+
if (Number(process.versions.node.split('.')[0]) < 24)
|
|
35
|
+
throw new Error('Node.js 24 or newer is required.');
|
|
36
|
+
if (!existsSync(python)) {
|
|
37
|
+
const candidates = process.env.PYTHON
|
|
38
|
+
? [process.env.PYTHON]
|
|
39
|
+
: ['python3', 'python'];
|
|
40
|
+
const base = candidates.find(supportedPython);
|
|
41
|
+
if (!base)
|
|
42
|
+
throw new Error(
|
|
43
|
+
'Python 3.11 or newer is required. Install it or set PYTHON to its executable.',
|
|
44
|
+
);
|
|
45
|
+
run(base, ['-m', 'venv', join(project, '.venv')]);
|
|
46
|
+
}
|
|
47
|
+
if (!supportedPython(python))
|
|
48
|
+
throw new Error(
|
|
49
|
+
'The project .venv needs Python 3.11 or newer. Recreate .venv with a supported interpreter.',
|
|
50
|
+
);
|
|
51
|
+
run(python, [
|
|
52
|
+
'-m',
|
|
53
|
+
'pip',
|
|
54
|
+
'install',
|
|
55
|
+
'-r',
|
|
56
|
+
join(project, 'requirements.txt'),
|
|
57
|
+
]);
|
|
58
|
+
const require = createRequire(import.meta.url);
|
|
59
|
+
const cliRequire = createRequire(
|
|
60
|
+
require.resolve('@cs-object/cli/package.json'),
|
|
61
|
+
);
|
|
62
|
+
const playwright = dirname(cliRequire.resolve('playwright/package.json'));
|
|
63
|
+
run(process.execPath, [
|
|
64
|
+
join(playwright, 'cli.js'),
|
|
65
|
+
'install',
|
|
66
|
+
'chromium',
|
|
67
|
+
]);
|
|
68
|
+
process.stdout.write('Setup complete. Run npm run dev.\n');
|
|
69
|
+
} catch (error) {
|
|
70
|
+
process.stderr.write(
|
|
71
|
+
`${error instanceof Error ? error.message : String(error)}\nFix the error, then run npm run setup again. Your project files are preserved.\n`,
|
|
72
|
+
);
|
|
73
|
+
process.exitCode = 1;
|
|
74
|
+
}
|