Skip to content

Commit fe93758

Browse files
committed
method-engine to improve design flow, method headline changes, improvements to create-apiops package
1 parent 09c0da4 commit fe93758

21 files changed

Lines changed: 1655 additions & 103 deletions

README.md

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
## Create a new APIOps project (CLI)
2+
3+
4+
```bash
5+
npm create apiops@latest
6+
```
7+
8+
This command runs the `create-apiops` initializer package and generates a starter APIOps project template in your current directory.
9+
10+
11+
112
# APIOps Cycles Method
213

314
This repository contains the source for the APIOps Cycles method, including resources such as canvases. It can be used for multiple purposes, such as the method website (https://www.apiopscycles.com/), which is generated from these files, and the Canvas Creator tool that allows creating, importing and exporting the canvases, and provides a UI. (https://canvascreator.apiopscycles.com/).
@@ -13,24 +24,35 @@ APIOps and APIOps Cycles are trademarks owned by Osaango Oy (https://www.osaango
1324
```
1425
├── src/
1526
│ ├── assets/ # APIOps Cycles logos and other core assets which you might need in your tooling or product
27+
│ ├── lib/ # Method-engine, "walks" developer or AI through the method starting from needs, also used by the CLI when using the create apiops template
1628
│ ├── data/method/ # The Method JSON files (structure, relationship, and guideline content)
1729
│ ├── data/method/canvas/ # The Canvases included in the method as JSON files (also used by tools like Canvas Creator)
1830
│ ├── snippets/ # Raw markdown files used for long content for resource docs (only essential extensions for the json files)
1931
├── scripts/ # Utility scripts
2032
└── package.json
33+
├── skills/ # AI skills that help use the method to design APIs
34+
├── packages/
35+
└── create-apiops # scaffolding template published as node module. Starts a new guided API design project with `npm create apiops@latest`
2136
```
2237

23-
## Requirements
38+
## Integrating the method in to tools, and developer workflows
2439

25-
You can use the JSON files as is and download a .zip file or clone the repository. You can also install them using `npm install apiops-cycles-method-data`.
40+
You can use the JSON files as is and download a .zip file or clone the repository. You can also install them using `npm install apiops-cycles-method-data`, or create a new API design and/or development project with `npm create apiops@latest`
2641

2742
The module exposes top-level exports so you can import the data files directly, for example:
2843

2944
```js
3045
import stations from "apiops-cycles-method-data/method/stations.json";
3146
import canvasData from "apiops-cycles-method-data/canvasData.json";
47+
import {
48+
buildStartData,
49+
buildStationResourceData,
50+
generateCanvases
51+
} from "apiops-cycles-method-data/method-engine";
3252
```
3353

54+
The `method-engine` export is intended for reusable APIOps workflow logic. It gives CLIs, AI agents, apps, and APIs the same station recommendation, resource lookup, and canvas generation behavior without reimplementing the method rules.
55+
3456
Validate the files locally with:
3557

3658
```bash
@@ -46,16 +68,6 @@ Install dependencies once with:
4668
npm install
4769
```
4870

49-
## Create a new APIOps project (CLI)
50-
51-
Once `create-apiops` is published to npm, you can scaffold a new project with:
52-
53-
```bash
54-
npm create apiops@latest
55-
```
56-
57-
This command runs the `create-apiops` initializer package and generates a starter APIOps project template in your current directory.
58-
5971
## Contributing
6072

6173
### Reporting issues or requesting features
@@ -64,7 +76,7 @@ If you spot a problem in the documentation or have an idea for new content, plea
6476

6577
### Editing or adding content
6678

67-
The main method files (instructions, guidelines, method structure) is located in the the JSON files at `src/data/method/`. These base files (`lines.json`, `stations.json`, `resources.json`, `criteria.json` and `station-criteria.json`) are not localized and live at the root of the folder. Textual values in them reference label keys. English labels are in `src/data/method/en-US` and translations are provided in `labels.lines.json`, `labels.stations.json`, `labels.resources.json` and `labels.criteria.json` under each locale folder. Some longer or more complex resource pages like the API Audit Checklist also use markdown snippets `src/snippets/` linked to the `resources.json`. Do not use any frontmatter in the snippet files. Any supported markdown markup is ok. See references from [Starlight markdown reference](https://starlight.astro.build/guides/authoring-content/) and [Extended markdown reference](https://www.markdownguide.org/extended-syntax/).
79+
The main method content files (instructions, guidelines, method structure) are located in the the JSON files at `src/data/method/`. These base files (`lines.json`, `stations.json`, `resources.json`, `criteria.json` and `station-criteria.json`) are not localized and live at the root of the folder. Textual values in them reference label keys. English labels are in `src/data/method/en-US` and translations are provided in `labels.lines.json`, `labels.stations.json`, `labels.resources.json` and `labels.criteria.json` under each locale folder. Some longer or more complex resource pages like the API Audit Checklist also use markdown snippets `src/snippets/` linked to the `resources.json`. Do not use any frontmatter in the snippet files. Any supported markdown markup is ok. See references from [Starlight markdown reference](https://starlight.astro.build/guides/authoring-content/) and [Extended markdown reference](https://www.markdownguide.org/extended-syntax/).
6880

6981
Each station links to specific entry criteria followed by the next core station's criteria as exit criteria.`criteria.json`, `station-criteria.json` and `labels.criteria.json`
7082

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"files": [
88
"skills",
99
"AGENTS.md",
10+
"src/lib",
1011
"src/data",
1112
"src/snippets",
1213
"src/assets/",
@@ -17,6 +18,7 @@
1718
"packages/*"
1819
],
1920
"exports": {
21+
"./method-engine": "./src/lib/method-engine.js",
2022
"./canvasData.json": "./src/data/canvas/canvasData.json",
2123
"./localizedData.json": "./src/data/canvas/localizedData.json",
2224
"./method/stations.json": "./src/data/method/stations.json",

packages/create-apiops/bin/create-apiops-project.js

Lines changed: 32 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ function replaceInFile(filePath, replacements) {
9999

100100
function getScripts(locale, apiStyle) {
101101
const base = {
102+
"method": "node ./node_modules/apiops-cycles-method-data/packages/create-apiops/bin/method-cli.js",
103+
"method:start": `node ./node_modules/apiops-cycles-method-data/packages/create-apiops/bin/method-cli.js start --locale ${locale}`,
104+
"method:resources:strategy": `node ./node_modules/apiops-cycles-method-data/packages/create-apiops/bin/method-cli.js resources --station api-product-strategy --locale ${locale}`,
105+
"method:canvases:new-api": `node ./node_modules/apiops-cycles-method-data/packages/create-apiops/bin/method-cli.js generate-canvases --preset new-api --style "${apiStyle}" --locale ${locale} --output ./specs/canvases`,
102106
"method:stations": `node ./node_modules/apiops-cycles-method-data/skills/new-api-guide/scripts/get-core-stations.cjs ${locale}`,
103107
"method:resource:audit": `node ./node_modules/apiops-cycles-method-data/skills/new-api-guide/scripts/get-resource-metadata.cjs api-audit-checklist ${locale}`
104108
};
@@ -119,52 +123,6 @@ function getScripts(locale, apiStyle) {
119123
return base;
120124
}
121125

122-
function createStarterCanvas(targetDir, locale = "en", canvasId = "domainCanvas") {
123-
const canvasDataPath = path.join(
124-
targetDir,
125-
"node_modules",
126-
"apiops-cycles-method-data",
127-
"canvasData.json"
128-
);
129-
130-
if (!fs.existsSync(canvasDataPath)) {
131-
return;
132-
}
133-
134-
const canvasData = JSON.parse(fs.readFileSync(canvasDataPath, "utf8"));
135-
const canvas = canvasData[canvasId];
136-
137-
if (!canvas) {
138-
return;
139-
}
140-
141-
const starter = {
142-
templateId: canvasId,
143-
locale,
144-
metadata: {
145-
source: "APIOps Cycles method",
146-
license: "CC-BY-SA 4.0",
147-
authors: ["Project team"],
148-
website: "www.apiopscycles.com",
149-
date: new Date().toISOString()
150-
},
151-
sections: canvas.sections.map((section) => ({
152-
sectionId: section.id,
153-
stickyNotes: [
154-
{
155-
content: "Placeholder",
156-
size: 80,
157-
color: "#FFF399"
158-
}
159-
]
160-
}))
161-
};
162-
163-
const outPath = path.join(targetDir, "specs", "canvases", "example.json");
164-
fs.mkdirSync(path.dirname(outPath), { recursive: true });
165-
fs.writeFileSync(outPath, `${JSON.stringify(starter, null, 2)}\n`);
166-
}
167-
168126
function hasMissingFlagValue(args) {
169127
return ["name", "locale", "style"].some((key) => args[key] === undefined && process.argv.includes(`--${key}`));
170128
}
@@ -223,7 +181,8 @@ async function main() {
223181
const replacements = {
224182
"__PROJECT_NAME__": projectName,
225183
"__LOCALE__": locale,
226-
"__API_TITLE__": projectName.replace(/[-_]/g, " ")
184+
"__API_TITLE__": projectName.replace(/[-_]/g, " "),
185+
"__API_STYLE__": apiStyle
227186
};
228187

229188
replaceInFile(path.join(targetDir, "README.md"), replacements);
@@ -251,15 +210,37 @@ async function main() {
251210
process.exit(result.status || 1);
252211
}
253212

254-
createStarterCanvas(targetDir, locale, "domainCanvas");
213+
const canvasInit = spawnSync(
214+
"node",
215+
[
216+
"./node_modules/apiops-cycles-method-data/packages/create-apiops/bin/method-cli.js",
217+
"generate-canvases",
218+
"--preset", "new-api",
219+
"--style", apiStyle,
220+
"--locale", locale,
221+
"--output", "./specs/canvases"
222+
],
223+
{
224+
cwd: targetDir,
225+
stdio: "inherit",
226+
shell: true
227+
}
228+
);
229+
230+
if (canvasInit.status !== 0) {
231+
console.error("Starter canvas generation failed");
232+
process.exit(canvasInit.status || 1);
233+
}
255234
} else {
256-
console.log("\nStarter canvas was not generated yet.");
257-
console.log("Run `npm install` first, then regenerate it with the scaffolder or a helper command.");
235+
console.log("\nStarter canvases were not generated yet.");
236+
console.log("Run `npm install` first, then `npm run method:canvases:new-api`.");
258237
}
259238

260239
console.log("\nNext steps:");
261240
console.log(` cd ${projectName}`);
262-
console.log(" npm run method:stations");
241+
console.log(" npm run method:start");
242+
console.log(" npm run method:resources:strategy");
243+
console.log(" npm run method:canvases:new-api");
263244
}
264245

265246
main().catch((err) => {

0 commit comments

Comments
 (0)