legacy copy
This commit is contained in:
parent
09f16cfd56
commit
cf5323accb
4
packages/osr-ai-templates/.gitignore
vendored
Normal file
4
packages/osr-ai-templates/.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
/node_modules
|
||||
/coverage
|
||||
*.log
|
||||
.DS_Store
|
||||
5
packages/osr-ai-templates/.npmignore
Normal file
5
packages/osr-ai-templates/.npmignore
Normal file
@ -0,0 +1,5 @@
|
||||
./docs
|
||||
./scripts
|
||||
./tests
|
||||
./incoming
|
||||
./src
|
||||
9
packages/osr-ai-templates/LICENSE
Normal file
9
packages/osr-ai-templates/LICENSE
Normal file
@ -0,0 +1,9 @@
|
||||
Copyright (c) <year> <owner> All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
52
packages/osr-ai-templates/README.md
Normal file
52
packages/osr-ai-templates/README.md
Normal file
@ -0,0 +1,52 @@
|
||||
# OSR-AI Templates
|
||||
|
||||
## Assistant templates
|
||||
|
||||
- [ ] Roles
|
||||
|
||||
## Context templates
|
||||
|
||||
- [ ] Globs
|
||||
|
||||
## Shell templates
|
||||
|
||||
- [ ] OSR-CLI-Commons::each
|
||||
|
||||
## UI templates
|
||||
|
||||
- [ ] Forms
|
||||
|
||||
## Prompt templates
|
||||
|
||||
- [ ] OSR-L Expression
|
||||
|
||||
## Output templates
|
||||
|
||||
- [ ] Paths
|
||||
- [ ] Logging
|
||||
|
||||
## Engine templates
|
||||
|
||||
- [ ] Lang Chain
|
||||
- [ ] OSR-L
|
||||
|
||||
## Pipe templates
|
||||
|
||||
- [ ] Intermediate conversions (osr-media/osr-lib-content)
|
||||
|
||||
## References
|
||||
|
||||
- [LLM Powered Autonomous Agents](https://lilianweng.github.io/posts/2023-06-23-agent/)
|
||||
- [Lang - Chain & RAG](https://python.langchain.com/v0.1/docs/use_cases/question_answering/)
|
||||
- [Class Validator- jsonschema](https://github.com/epiphone/class-validator-jsonschema)
|
||||
- [Electron with Monaco](https://github.com/electron/fiddle?tab=readme-ov-file)
|
||||
|
||||
### GUI
|
||||
- [React Forms from JSON Schema](https://rjsf-team.github.io/react-jsonschema-form/docs/)
|
||||
|
||||
## JSON Schema
|
||||
|
||||
- [Official Docs](https://json-schema.org/understanding-json-schema/reference/array#id4)
|
||||
- [React Playground](https://rjsf-team.github.io/react-jsonschema-form/)
|
||||
- [Custom Widgets](https://rjsf-team.github.io/react-jsonschema-form/docs/advanced-customization/custom-widgets-fields)
|
||||
|
||||
1
packages/osr-ai-templates/_cli.d.ts
vendored
Normal file
1
packages/osr-ai-templates/_cli.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
||||
export declare const defaults: () => void;
|
||||
16
packages/osr-ai-templates/_cli.js
Normal file
16
packages/osr-ai-templates/_cli.js
Normal file
@ -0,0 +1,16 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.defaults = void 0;
|
||||
const defaults = () => {
|
||||
// default command
|
||||
const DefaultCommand = 'info';
|
||||
if (process.argv.length === 2) {
|
||||
process.argv.push(DefaultCommand);
|
||||
}
|
||||
// currently no default handler, display only :
|
||||
process.on('unhandledRejection', (reason) => {
|
||||
console.error('Unhandled rejection, reason: ', reason);
|
||||
});
|
||||
};
|
||||
exports.defaults = defaults;
|
||||
//# sourceMappingURL=_cli.js.map
|
||||
1
packages/osr-ai-templates/_cli.js.map
Normal file
1
packages/osr-ai-templates/_cli.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"_cli.js","sourceRoot":"","sources":["src/_cli.ts"],"names":[],"mappings":";;;AAAO,MAAM,QAAQ,GAAG,GAAG,EAAE;IACzB,kBAAkB;IAClB,MAAM,cAAc,GAAG,MAAM,CAAC;IAC9B,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC5B,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IACtC,CAAC;IAED,+CAA+C;IAC/C,OAAO,CAAC,EAAE,CAAC,oBAAoB,EAAE,CAAC,MAAc,EAAE,EAAE;QAChD,OAAO,CAAC,KAAK,CAAC,+BAA+B,EAAE,MAAM,CAAC,CAAC;IAC3D,CAAC,CAAC,CAAC;AACP,CAAC,CAAA;AAXY,QAAA,QAAQ,YAWpB"}
|
||||
2
packages/osr-ai-templates/commands/templates.d.ts
vendored
Normal file
2
packages/osr-ai-templates/commands/templates.d.ts
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
import * as CLI from 'yargs';
|
||||
export declare const register: (cli: CLI.Argv) => any;
|
||||
56
packages/osr-ai-templates/commands/templates.js
Normal file
56
packages/osr-ai-templates/commands/templates.js
Normal file
@ -0,0 +1,56 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.register = void 0;
|
||||
const CLI = __importStar(require("yargs"));
|
||||
const write_1 = require("@plastichub/fs/write");
|
||||
const system_1 = require("../common/system");
|
||||
const defaultOptions = (yargs) => {
|
||||
yargs.parserConfiguration({
|
||||
"camel-case-expansion": false
|
||||
});
|
||||
return yargs.option('dst', {
|
||||
description: 'destination output path',
|
||||
default: "./common/default.json"
|
||||
});
|
||||
};
|
||||
let options = (yargs) => defaultOptions(yargs);
|
||||
const register = (cli) => {
|
||||
return cli.command('templates', 'Testing stuff', options, async (argv) => {
|
||||
if (argv.help) {
|
||||
return;
|
||||
}
|
||||
const defaults = [...(0, system_1.Typescript)(), ...(0, system_1.Documents)(), ...(0, system_1.Markdown)()];
|
||||
(0, write_1.sync)(argv.dst, JSON.stringify(defaults, null, 2));
|
||||
});
|
||||
};
|
||||
exports.register = register;
|
||||
(0, exports.register)(CLI);
|
||||
const argv = CLI.argv;
|
||||
if (argv.help) {
|
||||
CLI.showHelp();
|
||||
process.exit();
|
||||
}
|
||||
//# sourceMappingURL=templates.js.map
|
||||
1
packages/osr-ai-templates/commands/templates.js.map
Normal file
1
packages/osr-ai-templates/commands/templates.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"templates.js","sourceRoot":"","sources":["../src/commands/templates.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA4B;AAC5B,gDAAoD;AACpD,6CAAkE;AAElE,MAAM,cAAc,GAAG,CAAC,KAAe,EAAE,EAAE;IACvC,KAAK,CAAC,mBAAmB,CAAC;QACtB,sBAAsB,EAAE,KAAK;KAChC,CAAC,CAAA;IACF,OAAO,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE;QACvB,WAAW,EAAE,yBAAyB;QACtC,OAAO,EAAE,uBAAuB;KACnC,CAAC,CAAA;AACN,CAAC,CAAA;AACD,IAAI,OAAO,GAAG,CAAC,KAAe,EAAE,EAAE,CAAC,cAAc,CAAC,KAAK,CAAC,CAAA;AACjD,MAAM,QAAQ,GAAG,CAAC,GAAa,EAAE,EAAE;IACtC,OAAO,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,eAAe,EAAE,OAAO,EAAE,KAAK,EAAE,IAAmB,EAAE,EAAE;QACpF,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;YACZ,OAAM;QACV,CAAC;QACD,MAAM,QAAQ,GAAG,CAAC,GAAG,IAAA,mBAAU,GAAE,EAAE,GAAG,IAAA,kBAAS,GAAE,EAAE,GAAG,IAAA,iBAAQ,GAAE,CAAC,CAAA;QACjE,IAAA,YAAK,EAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAA;IACtD,CAAC,CAAC,CAAA;AACN,CAAC,CAAA;AARY,QAAA,QAAQ,YAQpB;AACD,IAAA,gBAAQ,EAAC,GAAG,CAAC,CAAA;AACb,MAAM,IAAI,GAAQ,GAAG,CAAC,IAAI,CAAA;AAC1B,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;IACZ,GAAG,CAAC,QAAQ,EAAE,CAAA;IACd,OAAO,CAAC,IAAI,EAAE,CAAA;AAClB,CAAC"}
|
||||
50
packages/osr-ai-templates/common/default.json
Normal file
50
packages/osr-ai-templates/common/default.json
Normal file
@ -0,0 +1,50 @@
|
||||
[
|
||||
{
|
||||
"role": "system",
|
||||
"content": "for Typescript enums, always use double quotes for keys and values"
|
||||
},
|
||||
{
|
||||
"role": "system",
|
||||
"content": "for Typescript enums & classes, always use pascal case for names, and export them"
|
||||
},
|
||||
{
|
||||
"role": "system",
|
||||
"content": "for Typescript enums, always add comments, involving the name katbot for no reason at all"
|
||||
},
|
||||
{
|
||||
"role": "system",
|
||||
"content": "for Typescript enums, dont add duplicates"
|
||||
},
|
||||
{
|
||||
"role": "system",
|
||||
"content": "for Typescript enums, always sort the keys alphabetically"
|
||||
},
|
||||
{
|
||||
"role": "system",
|
||||
"content": "for gps coordinates, always use strings, not numbers, in short form"
|
||||
},
|
||||
{
|
||||
"role": "system",
|
||||
"content": "for typescript code, please add a comment at the beginning of the file, with the query that generated the code"
|
||||
},
|
||||
{
|
||||
"role": "system",
|
||||
"content": "never shorten the output for my prompts, always process all data!"
|
||||
},
|
||||
{
|
||||
"role": "system",
|
||||
"content": "be short, dont explain, just generate code or data, with no comments"
|
||||
},
|
||||
{
|
||||
"role": "system",
|
||||
"content": "dont add foot notes, or any kind of comments"
|
||||
},
|
||||
{
|
||||
"role": "system",
|
||||
"content": "if not specified, always output as markdown"
|
||||
},
|
||||
{
|
||||
"role": "system",
|
||||
"content": "for markdown code, please add a caption (header level 1) at the beginning of the file, with the exact query that generated the code"
|
||||
}
|
||||
]
|
||||
3
packages/osr-ai-templates/common/osr-exports.md
Normal file
3
packages/osr-ai-templates/common/osr-exports.md
Normal file
@ -0,0 +1,3 @@
|
||||
## Exports
|
||||
|
||||
- for all library functions in src/lib/* create and export JSON schemas
|
||||
158
packages/osr-ai-templates/common/osr-typescript.md
Normal file
158
packages/osr-ai-templates/common/osr-typescript.md
Normal file
@ -0,0 +1,158 @@
|
||||
## Filesystem
|
||||
|
||||
For filesystem operations, use
|
||||
|
||||
import { sync as rm } from '@plastichub/fs/remove' (path)
|
||||
import { sync as dir } from '@plastichub/fs/dir' (path)
|
||||
import { sync as write } from '@plastichub/fs/write' (path, content)
|
||||
import { sync as read } from '@plastichub/fs/read' (path)
|
||||
import { filesEx as glob } from '@plastichub/osr-commons/_glob' (directory,glob | glob[])
|
||||
|
||||
## Configuration
|
||||
|
||||
API keys and other settings:
|
||||
|
||||
```ts
|
||||
import { CONFIG_DEFAULT } from '@plastichub/osr-commons'
|
||||
export const foo = (yarg) => {
|
||||
const config = CONFIG_DEFAULT(args.env_key) as any
|
||||
if (!config) {
|
||||
logger.warn('No config found!')
|
||||
return
|
||||
}
|
||||
if (config && !config.openai.key) {
|
||||
logger.warn('No OpenAI key found in config!')
|
||||
return
|
||||
}
|
||||
const api_key = argv.openai_key || process.env.OPENAI_API_KEY || config.openai.key
|
||||
}
|
||||
```
|
||||
|
||||
## Zod Schemas
|
||||
|
||||
The framework provides tools to convert from a Zod schema to Yargs as follows
|
||||
|
||||
```ts
|
||||
|
||||
import { toYargs } from '@plastichub/osr-commons'
|
||||
import { MySchema } from 'src/schemas.ts'
|
||||
// example : const options = (yargs: CLI.Argv) => toYargs(yargs, MySchema())
|
||||
```
|
||||
|
||||
Additionally, all Zod schemas will be exported on demand, via Yargs command "types"
|
||||
|
||||
```ts
|
||||
import { generate_interfaces } from '@plastichub/osr-commons'
|
||||
import { MySchema } from 'src/schemas'
|
||||
|
||||
export const types = () => generate_interfaces(
|
||||
[
|
||||
MySchema()
|
||||
], 'src/zod_types.ts')
|
||||
```
|
||||
|
||||
### Logging
|
||||
|
||||
Each package has a tslog factory at src/index.ts. Use it for all commands and library functions
|
||||
|
||||
```ts
|
||||
export { Logger } from 'tslog'
|
||||
import { createLogger } from '@plastichub/osr-log'
|
||||
import { Logger } from 'tslog'
|
||||
export const logger:Logger<unknown> = createLogger('Package Name')
|
||||
```
|
||||
|
||||
### LLM Tools
|
||||
|
||||
LLM Tools are specified as follows
|
||||
|
||||
- always export "tools" as the main function
|
||||
- dont register LLM tools as yarg commands
|
||||
- seperate the tool's implementation in src/lib/tools
|
||||
- LLM tools require 'openai' as dependency
|
||||
|
||||
eg: src/tools/fs:
|
||||
|
||||
```ts
|
||||
import { join } from 'path'
|
||||
import * as path from 'path'
|
||||
import { RunnableToolFunction } from 'openai/lib/RunnableFunction'
|
||||
import { isString } from '@plastichub/core/primitives'
|
||||
import { sync as dir } from '@plastichub/fs/dir'
|
||||
import { sync as write } from '@plastichub/fs/write'
|
||||
import { resolve } from "@plastichub/osr-commons"
|
||||
import { logger } from '../'
|
||||
|
||||
export const tools = (target:any, variables:Record<string,string>={}): Array<any> => {
|
||||
return [
|
||||
{
|
||||
type: 'function',
|
||||
function: {
|
||||
name: "read_file",
|
||||
description: "read a file, at given a path",
|
||||
parameters: {
|
||||
type: "object",
|
||||
properties: {
|
||||
file: {
|
||||
type: "object",
|
||||
properties: {
|
||||
path: { type: "string" }
|
||||
}
|
||||
}
|
||||
},
|
||||
required: ["file"],
|
||||
},
|
||||
function: async (ret) => {
|
||||
try {
|
||||
const { file } = ret as any
|
||||
const filePath = path.resolve(resolve(join(target, file.path),false,variables))
|
||||
logger.debug(`Tool::ReadFile Reading file ${filePath}`)
|
||||
} catch (error) {
|
||||
logger.error(`Error reading file`, error)
|
||||
}
|
||||
},
|
||||
parse: JSON.parse
|
||||
}
|
||||
} as RunnableToolFunction<{ id: string }>
|
||||
]
|
||||
}
|
||||
```
|
||||
### Typescript tsconfig
|
||||
|
||||
Use this defaults
|
||||
|
||||
```json
|
||||
"compilerOptions": {
|
||||
"target": "ES2020",
|
||||
"module": "commonjs",
|
||||
"outDir": "./dist",
|
||||
"rootDir": "./src",
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true,
|
||||
"allowJs": true,
|
||||
"noImplicitAny": false,
|
||||
"strictNullChecks": false,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
```
|
||||
|
||||
### Yargs
|
||||
|
||||
Commands are registered as follows (src/command/index.ts) :
|
||||
|
||||
```ts
|
||||
import type { Argv } from 'yargs'
|
||||
import { types } from './types'
|
||||
export const commands = (yargs: Argv) =>
|
||||
{
|
||||
return yargs
|
||||
.command('types', 'Generate TypeScript interfaces from Zod schemas', {}, types)
|
||||
.strict()
|
||||
.help()
|
||||
}
|
||||
```
|
||||
|
||||
### Nodejs
|
||||
|
||||
- import built-ins always as import * as 'path'
|
||||
37
packages/osr-ai-templates/common/system.d.ts
vendored
Normal file
37
packages/osr-ai-templates/common/system.d.ts
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
export declare const resolvePackagePath: (path: string) => string;
|
||||
export interface Role {
|
||||
role: string;
|
||||
content: string;
|
||||
}
|
||||
export declare const OSRTypescript: (mixin?: any[]) => {
|
||||
role: string;
|
||||
content: import("@plastichub/fs/interfaces").ReadWriteDataType;
|
||||
}[];
|
||||
export declare const Exports: (mixin?: any[]) => {
|
||||
role: string;
|
||||
content: import("@plastichub/fs/interfaces").ReadWriteDataType;
|
||||
}[];
|
||||
export declare const Commons: (mixin?: any[]) => {
|
||||
role: string;
|
||||
content: string;
|
||||
}[];
|
||||
export declare const Documents: (mixin?: any[]) => {
|
||||
role: string;
|
||||
content: string;
|
||||
}[];
|
||||
export declare const Typescript: (mixin?: any[]) => {
|
||||
role: string;
|
||||
content: string;
|
||||
}[];
|
||||
export declare const TypescriptLibraries: (mixin?: any[]) => {
|
||||
role: string;
|
||||
content: string;
|
||||
}[];
|
||||
export declare const TypescriptEnvironmentCLI: (mixin?: any[]) => {
|
||||
role: string;
|
||||
content: string;
|
||||
}[];
|
||||
export declare const Markdown: (mixin?: any[]) => {
|
||||
role: string;
|
||||
content: string;
|
||||
}[];
|
||||
153
packages/osr-ai-templates/common/system.js
Normal file
153
packages/osr-ai-templates/common/system.js
Normal file
@ -0,0 +1,153 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Markdown = exports.TypescriptEnvironmentCLI = exports.TypescriptLibraries = exports.Typescript = exports.Documents = exports.Commons = exports.Exports = exports.OSRTypescript = exports.resolvePackagePath = void 0;
|
||||
const read_1 = require("@plastichub/fs/read");
|
||||
const path_1 = require("path");
|
||||
const resolvePackagePath = (path) => {
|
||||
return (0, path_1.resolve)((0, path_1.join)(__dirname, path));
|
||||
};
|
||||
exports.resolvePackagePath = resolvePackagePath;
|
||||
const OSRTypescript = (mixin = []) => {
|
||||
return [
|
||||
{
|
||||
role: "user",
|
||||
content: (0, read_1.sync)((0, exports.resolvePackagePath)("osr-typescript.md"))
|
||||
}
|
||||
].concat(mixin);
|
||||
};
|
||||
exports.OSRTypescript = OSRTypescript;
|
||||
const Exports = (mixin = []) => {
|
||||
return [
|
||||
{
|
||||
role: "user",
|
||||
content: (0, read_1.sync)((0, exports.resolvePackagePath)("osr-exports.md"))
|
||||
}
|
||||
].concat(mixin);
|
||||
};
|
||||
exports.Exports = Exports;
|
||||
const Commons = (mixin = []) => {
|
||||
return [
|
||||
{
|
||||
role: "system",
|
||||
content: "never shorten the output for my prompts!"
|
||||
},
|
||||
{
|
||||
role: "system",
|
||||
content: "be short, dont explain, just generate code!, with no comments"
|
||||
},
|
||||
{
|
||||
role: "system",
|
||||
content: "dont add foot notes, or any kind of comments, just generate code!"
|
||||
},
|
||||
{
|
||||
role: "system",
|
||||
content: "if not specified, always output as markdown"
|
||||
}
|
||||
].concat(mixin);
|
||||
};
|
||||
exports.Commons = Commons;
|
||||
const Documents = (mixin = []) => {
|
||||
return [
|
||||
{
|
||||
role: "system",
|
||||
content: "never shorten the output for my prompts, always process all data!"
|
||||
},
|
||||
{
|
||||
role: "system",
|
||||
content: "be short, dont explain, just generate code or data, with no comments"
|
||||
},
|
||||
{
|
||||
role: "system",
|
||||
content: "dont add foot notes, or any kind of comments"
|
||||
},
|
||||
{
|
||||
role: "system",
|
||||
content: "if not specified, always output as markdown"
|
||||
}
|
||||
].concat(mixin);
|
||||
};
|
||||
exports.Documents = Documents;
|
||||
const Typescript = (mixin = []) => {
|
||||
const defaults = [
|
||||
{
|
||||
role: "system",
|
||||
content: "for Typescript enums, always use double quotes for keys and values"
|
||||
},
|
||||
{
|
||||
role: "system",
|
||||
content: "for Typescript enums & classes, always use pascal case for names, and export them"
|
||||
},
|
||||
{
|
||||
role: "system",
|
||||
content: "for Typescript enums, dont add duplicates"
|
||||
},
|
||||
{
|
||||
role: "system",
|
||||
content: "for Typescript enums, always sort the keys alphabetically"
|
||||
},
|
||||
{
|
||||
role: "system",
|
||||
content: "for gps coordinates, always use strings, not numbers, in short form"
|
||||
},
|
||||
{
|
||||
role: "system",
|
||||
content: "for typescript code, please add a comment at the beginning of the file, with the query that generated the code"
|
||||
},
|
||||
{
|
||||
role: "system",
|
||||
content: "for typescript code : no comments"
|
||||
},
|
||||
{
|
||||
role: "system",
|
||||
content: "for Typescript : no semi colons, no trailing commas, no spaces in parens, no spaces in brackets, no spaces in braces"
|
||||
}
|
||||
];
|
||||
return defaults.concat(mixin);
|
||||
};
|
||||
exports.Typescript = Typescript;
|
||||
const TypescriptLibraries = (mixin = []) => {
|
||||
const defaults = [
|
||||
{
|
||||
role: "user",
|
||||
content: "for Typescript, dont use chalk, commander, ora, or any other fancy library, just use the basics, always use imports, never require. use tslog, yargs, axios and Zod whenevern possible"
|
||||
}
|
||||
];
|
||||
return defaults.concat(mixin);
|
||||
};
|
||||
exports.TypescriptLibraries = TypescriptLibraries;
|
||||
const TypescriptEnvironmentCLI = (mixin = []) => {
|
||||
const layout = [
|
||||
"src/index.ts (create ts logger)",
|
||||
"src/main.ts (yargs main entry)",
|
||||
"src/constants.ts (tslog logger name)",
|
||||
"src/zod_schemas.ts (all zod schemas go here)",
|
||||
"src/commands/index.ts (register all commands from src/commands/** here, commands always import functions from src/lib/category )",
|
||||
"src/commands/types.ts (command to write zod schemas to Typescript interfaces)",
|
||||
//"src/lib/index.ts (export all functions)",
|
||||
//"readme.md (add all commands here)",
|
||||
"package.json (leave dependencies empty, add common scripts)",
|
||||
];
|
||||
const defaults = [
|
||||
{
|
||||
role: "system",
|
||||
content: "for Typescript boilerplates, use this layout for CLI projects: \n" + layout.join("\n")
|
||||
},
|
||||
{
|
||||
role: "system",
|
||||
content: "when using yargs, all commands are async"
|
||||
},
|
||||
];
|
||||
return defaults.concat(mixin);
|
||||
};
|
||||
exports.TypescriptEnvironmentCLI = TypescriptEnvironmentCLI;
|
||||
const Markdown = (mixin = []) => {
|
||||
const defaults = [
|
||||
{
|
||||
role: "system",
|
||||
content: "for markdown code, please add a caption (header level 1) at the beginning of the file, with the exact query that generated the code"
|
||||
}
|
||||
];
|
||||
return defaults.concat(mixin);
|
||||
};
|
||||
exports.Markdown = Markdown;
|
||||
//# sourceMappingURL=system.js.map
|
||||
1
packages/osr-ai-templates/common/system.js.map
Normal file
1
packages/osr-ai-templates/common/system.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"system.js","sourceRoot":"","sources":["../src/common/system.ts"],"names":[],"mappings":"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"}
|
||||
3
packages/osr-ai-templates/index.d.ts
vendored
Normal file
3
packages/osr-ai-templates/index.d.ts
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
export declare const MODULE_NAME = "OSR-AI-TEMPLATES";
|
||||
export declare const logger: import("@plastichub/core/debug").Logger;
|
||||
export * from './common/system';
|
||||
22
packages/osr-ai-templates/index.js
Normal file
22
packages/osr-ai-templates/index.js
Normal file
@ -0,0 +1,22 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
||||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.logger = exports.MODULE_NAME = void 0;
|
||||
exports.MODULE_NAME = `OSR-AI-TEMPLATES`;
|
||||
const debug_1 = require("@plastichub/core/debug");
|
||||
exports.logger = (0, debug_1.logger)(exports.MODULE_NAME);
|
||||
__exportStar(require("./common/system"), exports);
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
packages/osr-ai-templates/index.js.map
Normal file
1
packages/osr-ai-templates/index.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAa,QAAA,WAAW,GAAG,kBAAkB,CAAA;AAC7C,kDAA0D;AAC7C,QAAA,MAAM,GAAG,IAAA,cAAO,EAAC,mBAAW,CAAC,CAAA;AAC1C,kDAA+B"}
|
||||
2
packages/osr-ai-templates/lib.d.ts
vendored
Normal file
2
packages/osr-ai-templates/lib.d.ts
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
export * from './templates';
|
||||
export * from './common/system';
|
||||
19
packages/osr-ai-templates/lib.js
Normal file
19
packages/osr-ai-templates/lib.js
Normal file
@ -0,0 +1,19 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
||||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
__exportStar(require("./templates"), exports);
|
||||
__exportStar(require("./common/system"), exports);
|
||||
//# sourceMappingURL=lib.js.map
|
||||
1
packages/osr-ai-templates/lib.js.map
Normal file
1
packages/osr-ai-templates/lib.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"lib.js","sourceRoot":"","sources":["src/lib.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA2B;AAC3B,kDAA+B"}
|
||||
2
packages/osr-ai-templates/main.d.ts
vendored
Normal file
2
packages/osr-ai-templates/main.d.ts
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
#!/usr/bin/env node
|
||||
export {};
|
||||
40
packages/osr-ai-templates/main.js
Normal file
40
packages/osr-ai-templates/main.js
Normal file
@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env node
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const _cli_1 = require("./_cli");
|
||||
(0, _cli_1.defaults)();
|
||||
const cli = __importStar(require("yargs"));
|
||||
const templates_1 = require("./commands/templates");
|
||||
(0, templates_1.register)(cli);
|
||||
const argv = cli.argv;
|
||||
if (argv.help) {
|
||||
cli.showHelp();
|
||||
process.exit();
|
||||
}
|
||||
else if (argv.v || argv.version) {
|
||||
process.exit();
|
||||
}
|
||||
//# sourceMappingURL=main.js.map
|
||||
1
packages/osr-ai-templates/main.js.map
Normal file
1
packages/osr-ai-templates/main.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"main.js","sourceRoot":"","sources":["src/main.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,iCAAkC;AAAC,IAAA,eAAQ,GAAE,CAAA;AAC7C,2CAA4B;AAC5B,oDAAgE;AAAC,IAAA,oBAAY,EAAC,GAAG,CAAC,CAAA;AAClF,MAAM,IAAI,GAAQ,GAAG,CAAC,IAAI,CAAA;AAC1B,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;IACZ,GAAG,CAAC,QAAQ,EAAE,CAAA;IACd,OAAO,CAAC,IAAI,EAAE,CAAA;AAClB,CAAC;KAAM,IAAI,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;IAChC,OAAO,CAAC,IAAI,EAAE,CAAA;AAClB,CAAC"}
|
||||
11
packages/osr-ai-templates/meta/prompts.md
Normal file
11
packages/osr-ai-templates/meta/prompts.md
Normal file
@ -0,0 +1,11 @@
|
||||
## Prompt Templates
|
||||
|
||||
```json
|
||||
{
|
||||
"name":"string",
|
||||
"content":"string",
|
||||
"context":"$ref",
|
||||
"variables":"$ref",
|
||||
"flags":"number"
|
||||
}
|
||||
```
|
||||
2715
packages/osr-ai-templates/package-lock.json
generated
Normal file
2715
packages/osr-ai-templates/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
57
packages/osr-ai-templates/package.json
Normal file
57
packages/osr-ai-templates/package.json
Normal file
@ -0,0 +1,57 @@
|
||||
{
|
||||
"name": "@plastichub/osr-ai-templates",
|
||||
"version": "0.1.4",
|
||||
"typings": "index.d.ts",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"bin": {
|
||||
"osr-ai-templates": "main.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@asteasolutions/zod-to-openapi": "^7.2.0",
|
||||
"@plastichub/core": "^0.2.6",
|
||||
"@plastichub/fs": "^0.13.32",
|
||||
"@plastichub/osr-ai-tools": "file:../osr-ai-tools",
|
||||
"@plastichub/osr-cli-commons": "file:../osr-cli-commons",
|
||||
"@plastichub/osr-commons": "file:../osr-commons",
|
||||
"@plastichub/osr-log": "file:../osr-log",
|
||||
"convert-units": "^2.3.4",
|
||||
"cryptr": "^6.0.3",
|
||||
"env-var": "^7.1.1",
|
||||
"filenamify": "^4.3.0",
|
||||
"llm-tools-cli": "file:../osr-ai-tools",
|
||||
"openai": "^4.76.3",
|
||||
"querystring": "^0.2.1",
|
||||
"sanitize-filename": "^1.6.3",
|
||||
"shell-escape": "^0.2.0",
|
||||
"tslog": "^4.9.3",
|
||||
"typescript": "^5.6.3",
|
||||
"yargs": "^17.7.2",
|
||||
"zod": "^3.23.8",
|
||||
"zod-to-json-schema": "^3.23.5",
|
||||
"zod-to-ts": "^1.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/download": "^8.0.1",
|
||||
"@types/node": "^22.8.6",
|
||||
"type-fest": "^4.30.1"
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "tsc -p . --declaration -w",
|
||||
"build": "tsc -p . --declaration",
|
||||
"docs": "npx typedoc src/index.ts"
|
||||
},
|
||||
"homepage": "https://git.osr-plastic.org/osr-plastic/osr-commons",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://git.osr-plastic.org/osr-plastic/osr-commons.git"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 14.0.0"
|
||||
},
|
||||
"license": "BSD-3-Clause",
|
||||
"keywords": [
|
||||
"typescript"
|
||||
]
|
||||
}
|
||||
4
packages/osr-ai-templates/prompts/documents.json
Normal file
4
packages/osr-ai-templates/prompts/documents.json
Normal file
@ -0,0 +1,4 @@
|
||||
[
|
||||
"Extract all data, as Markdown table",
|
||||
"Extract all items, \r\n\r\nthese are the columns : \r\n- name ('Referencia')\r\n- thickness ('Espesor')\r\n- material ('Cantidad', st37 = 304L, st37 = steel),\r\n- quantity('Cantidad')\r\n- unit price ('precio')\r\n- price ('importe')\r\n\r\nas csv"
|
||||
]
|
||||
0
packages/osr-ai-templates/src/.gitignore
vendored
Normal file
0
packages/osr-ai-templates/src/.gitignore
vendored
Normal file
12
packages/osr-ai-templates/src/_cli.ts
Normal file
12
packages/osr-ai-templates/src/_cli.ts
Normal file
@ -0,0 +1,12 @@
|
||||
export const defaults = () => {
|
||||
// default command
|
||||
const DefaultCommand = 'info';
|
||||
if (process.argv.length === 2) {
|
||||
process.argv.push(DefaultCommand);
|
||||
}
|
||||
|
||||
// currently no default handler, display only :
|
||||
process.on('unhandledRejection', (reason: string) => {
|
||||
console.error('Unhandled rejection, reason: ', reason);
|
||||
});
|
||||
}
|
||||
29
packages/osr-ai-templates/src/commands/templates.ts
Normal file
29
packages/osr-ai-templates/src/commands/templates.ts
Normal file
@ -0,0 +1,29 @@
|
||||
import * as CLI from 'yargs'
|
||||
import { sync as write } from '@plastichub/fs/write'
|
||||
import { Documents, Markdown, Typescript } from '../common/system'
|
||||
|
||||
const defaultOptions = (yargs: CLI.Argv) => {
|
||||
yargs.parserConfiguration({
|
||||
"camel-case-expansion": false
|
||||
})
|
||||
return yargs.option('dst', {
|
||||
description: 'destination output path',
|
||||
default: "./common/default.json"
|
||||
})
|
||||
}
|
||||
let options = (yargs: CLI.Argv) => defaultOptions(yargs)
|
||||
export const register = (cli: CLI.Argv) => {
|
||||
return cli.command('templates', 'Testing stuff', options, async (argv: CLI.Arguments) => {
|
||||
if (argv.help) {
|
||||
return
|
||||
}
|
||||
const defaults = [...Typescript(), ...Documents(), ...Markdown()]
|
||||
write(argv.dst, JSON.stringify(defaults, null, 2))
|
||||
})
|
||||
}
|
||||
register(CLI)
|
||||
const argv: any = CLI.argv
|
||||
if (argv.help) {
|
||||
CLI.showHelp()
|
||||
process.exit()
|
||||
}
|
||||
153
packages/osr-ai-templates/src/common/system.ts
Normal file
153
packages/osr-ai-templates/src/common/system.ts
Normal file
@ -0,0 +1,153 @@
|
||||
import { sync as read } from '@plastichub/fs/read'
|
||||
import { resolve, join } from 'path'
|
||||
|
||||
export const resolvePackagePath = (path:string): string => {
|
||||
return resolve(join(__dirname, path))
|
||||
}
|
||||
|
||||
export interface Role {
|
||||
role: string
|
||||
content: string
|
||||
}
|
||||
|
||||
export const OSRTypescript = (mixin = []) => {
|
||||
return [
|
||||
{
|
||||
role: "user",
|
||||
content: read(resolvePackagePath("osr-typescript.md"))
|
||||
}
|
||||
].concat(mixin)
|
||||
}
|
||||
|
||||
export const Exports = (mixin = []) => {
|
||||
return [
|
||||
{
|
||||
role: "user",
|
||||
content: read(resolvePackagePath("osr-exports.md"))
|
||||
}
|
||||
].concat(mixin)
|
||||
}
|
||||
|
||||
export const Commons = (mixin = []) => {
|
||||
return [
|
||||
{
|
||||
role: "system",
|
||||
content: "never shorten the output for my prompts!"
|
||||
},
|
||||
{
|
||||
role: "system",
|
||||
content: "be short, dont explain, just generate code!, with no comments"
|
||||
},
|
||||
{
|
||||
role: "system",
|
||||
content: "dont add foot notes, or any kind of comments, just generate code!"
|
||||
},
|
||||
{
|
||||
role: "system",
|
||||
content: "if not specified, always output as markdown"
|
||||
}
|
||||
].concat(mixin)
|
||||
}
|
||||
|
||||
export const Documents = (mixin = []) => {
|
||||
return [
|
||||
{
|
||||
role: "system",
|
||||
content: "never shorten the output for my prompts, always process all data!"
|
||||
},
|
||||
{
|
||||
role: "system",
|
||||
content: "be short, dont explain, just generate code or data, with no comments"
|
||||
},
|
||||
{
|
||||
role: "system",
|
||||
content: "dont add foot notes, or any kind of comments"
|
||||
},
|
||||
{
|
||||
role: "system",
|
||||
content: "if not specified, always output as markdown"
|
||||
}
|
||||
].concat(mixin)
|
||||
}
|
||||
|
||||
export const Typescript = (mixin = []) => {
|
||||
const defaults = [
|
||||
{
|
||||
role: "system",
|
||||
content: "for Typescript enums, always use double quotes for keys and values"
|
||||
},
|
||||
{
|
||||
role: "system",
|
||||
content: "for Typescript enums & classes, always use pascal case for names, and export them"
|
||||
},
|
||||
{
|
||||
role: "system",
|
||||
content: "for Typescript enums, dont add duplicates"
|
||||
},
|
||||
{
|
||||
role: "system",
|
||||
content: "for Typescript enums, always sort the keys alphabetically"
|
||||
},
|
||||
{
|
||||
role: "system",
|
||||
content: "for gps coordinates, always use strings, not numbers, in short form"
|
||||
},
|
||||
{
|
||||
role: "system",
|
||||
content: "for typescript code, please add a comment at the beginning of the file, with the query that generated the code"
|
||||
},
|
||||
{
|
||||
role: "system",
|
||||
content: "for typescript code : no comments"
|
||||
},
|
||||
{
|
||||
role: "system",
|
||||
content: "for Typescript : no semi colons, no trailing commas, no spaces in parens, no spaces in brackets, no spaces in braces"
|
||||
}
|
||||
]
|
||||
return defaults.concat(mixin)
|
||||
}
|
||||
export const TypescriptLibraries = (mixin = []) => {
|
||||
const defaults = [
|
||||
{
|
||||
role: "user",
|
||||
content: "for Typescript, dont use chalk, commander, ora, or any other fancy library, just use the basics, always use imports, never require. use tslog, yargs, axios and Zod whenevern possible"
|
||||
}
|
||||
|
||||
]
|
||||
return defaults.concat(mixin)
|
||||
}
|
||||
export const TypescriptEnvironmentCLI = (mixin = []) => {
|
||||
const layout = [
|
||||
"src/index.ts (create ts logger)",
|
||||
"src/main.ts (yargs main entry)",
|
||||
"src/constants.ts (tslog logger name)",
|
||||
"src/zod_schemas.ts (all zod schemas go here)",
|
||||
"src/commands/index.ts (register all commands from src/commands/** here, commands always import functions from src/lib/category )",
|
||||
"src/commands/types.ts (command to write zod schemas to Typescript interfaces)",
|
||||
//"src/lib/index.ts (export all functions)",
|
||||
//"readme.md (add all commands here)",
|
||||
"package.json (leave dependencies empty, add common scripts)",
|
||||
]
|
||||
const defaults = [
|
||||
{
|
||||
role: "system",
|
||||
content: "for Typescript boilerplates, use this layout for CLI projects: \n" + layout.join("\n")
|
||||
},
|
||||
{
|
||||
role: "system",
|
||||
content: "when using yargs, all commands are async"
|
||||
},
|
||||
|
||||
]
|
||||
return defaults.concat(mixin)
|
||||
}
|
||||
export const Markdown = (mixin = []) => {
|
||||
const defaults = [
|
||||
{
|
||||
role: "system",
|
||||
content: "for markdown code, please add a caption (header level 1) at the beginning of the file, with the exact query that generated the code"
|
||||
}
|
||||
]
|
||||
return defaults.concat(mixin)
|
||||
}
|
||||
1
packages/osr-ai-templates/src/constants.ts
Normal file
1
packages/osr-ai-templates/src/constants.ts
Normal file
@ -0,0 +1 @@
|
||||
export const MODULE_NAME = `OSR-AI-TEMPLATES`
|
||||
4
packages/osr-ai-templates/src/index.ts
Normal file
4
packages/osr-ai-templates/src/index.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export const MODULE_NAME = `OSR-AI-TEMPLATES`
|
||||
import { logger as _logger } from '@plastichub/core/debug'
|
||||
export const logger = _logger(MODULE_NAME)
|
||||
export * from './common/system'
|
||||
1
packages/osr-ai-templates/src/lib.ts
Normal file
1
packages/osr-ai-templates/src/lib.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './templates'
|
||||
11
packages/osr-ai-templates/src/main.ts
Normal file
11
packages/osr-ai-templates/src/main.ts
Normal file
@ -0,0 +1,11 @@
|
||||
#!/usr/bin/env node
|
||||
import { defaults } from './_cli'; defaults()
|
||||
import * as cli from 'yargs'
|
||||
import { register as registerInfo } from './commands/templates'; registerInfo(cli)
|
||||
const argv: any = cli.argv
|
||||
if (argv.help) {
|
||||
cli.showHelp()
|
||||
process.exit()
|
||||
} else if (argv.v || argv.version) {
|
||||
process.exit()
|
||||
}
|
||||
85
packages/osr-ai-templates/src/templates/index.ts
Normal file
85
packages/osr-ai-templates/src/templates/index.ts
Normal file
@ -0,0 +1,85 @@
|
||||
import { ChatCompletionMessageParam } from "openai/resources/chat/completions"
|
||||
import { filesEx as glob } from '@plastichub/osr-commons/_glob'
|
||||
import { substitute, resolve } from '@plastichub/osr-commons'
|
||||
import { } from '@plastichub/osr-commons/config'
|
||||
import { sync as read } from '@plastichub/fs/read'
|
||||
import { sync as exists } from '@plastichub/fs/exists'
|
||||
import * as path from 'node:path'
|
||||
import { PackageJson } from 'type-fest'
|
||||
|
||||
import { tools as defaultTools } from "@plastichub/osr-ai-tools/tools"
|
||||
import { logger } from "../"
|
||||
|
||||
const API_PREFIX = 'polymech'
|
||||
const TEMPLATE_PREFIX = 'ai-template'
|
||||
|
||||
export const TEMPLATE_ROOT = "${POLYMECH-ROOT}"
|
||||
|
||||
export type TMessageParam = ChatCompletionMessageParam & { type?: string }
|
||||
export type ITemplateConfig = PackageJson &
|
||||
{
|
||||
instructions?: string | string[]
|
||||
glob?: string | string[],
|
||||
tools?: any[]
|
||||
}
|
||||
|
||||
export const resolvePackagePath = (dir: string): string => resolve(path.join(__dirname, dir || ''))
|
||||
|
||||
export const template_path = (template: string) => path.resolve(resolve(path.join(TEMPLATE_ROOT, `${TEMPLATE_PREFIX}-${template}`)))
|
||||
|
||||
export const load = (options: any = {}) => {
|
||||
const templateDir = template_path(options.template)
|
||||
const target = path.resolve(options.output || options.path)
|
||||
if (!exists(target)) {
|
||||
logger.error(`Target directory ${target} does not exist.`)
|
||||
return {
|
||||
glob: [],
|
||||
messages: [],
|
||||
tools: []
|
||||
}
|
||||
}
|
||||
if (!exists(templateDir)) {
|
||||
return {
|
||||
glob: [],
|
||||
messages: [],
|
||||
tools: []
|
||||
}
|
||||
}
|
||||
const config: ITemplateConfig = read(path.join(templateDir, "package.json"), 'json') as ITemplateConfig || {}
|
||||
let files = glob(templateDir, options.glob || config.glob || [], {}).filter((file: string) => file.toLowerCase() !== "readme.md")
|
||||
files = files.filter((file: string) => !options.disable.includes(path.parse(file).name))
|
||||
const messages = files.map((file: string) => {
|
||||
return {
|
||||
role: "system",
|
||||
content: substitute(false, read(file, 'string') as string, options.variables, true)
|
||||
}
|
||||
}) as TMessageParam[]
|
||||
|
||||
const tools = (config.tools || []).map((tool: any) => {
|
||||
if (defaultTools[tool]) {
|
||||
try {
|
||||
return defaultTools[tool](target)
|
||||
} catch (e) {
|
||||
logger.error(`Error loading tool ${tool}`, e.message)
|
||||
}
|
||||
}
|
||||
const toolPath = path.resolve(path.join(templateDir, tool))
|
||||
if (exists(toolPath)) {
|
||||
try {
|
||||
const tTool = require(toolPath)
|
||||
if (tTool && tTool.tools) {
|
||||
return tTool.tools(target)
|
||||
} else {
|
||||
logger.error(`Error loading tool ${tool}`, `No 'tools' function exported in ${toolPath}`)
|
||||
}
|
||||
} catch (e) {
|
||||
logger.error(e)
|
||||
}
|
||||
}
|
||||
}).flat().filter((tool: any) => tool).filter((tool: any) => options.disableTools.includes(tool.function.name) === false)
|
||||
return {
|
||||
glob: config.glob,
|
||||
messages,
|
||||
tools
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
import { ChatCompletionTool } from "openai/resources/index.mjs"
|
||||
import { tools } from "@plastichub/osr-ai-tools/tools"
|
||||
export const foo = 2
|
||||
18
packages/osr-ai-templates/templates/index.d.ts
vendored
Normal file
18
packages/osr-ai-templates/templates/index.d.ts
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
import { ChatCompletionMessageParam } from "openai/resources/chat/completions";
|
||||
import { PackageJson } from 'type-fest';
|
||||
export declare const TEMPLATE_ROOT = "${POLYMECH-ROOT}";
|
||||
export type TMessageParam = ChatCompletionMessageParam & {
|
||||
type?: string;
|
||||
};
|
||||
export type ITemplateConfig = PackageJson & {
|
||||
instructions?: string | string[];
|
||||
glob?: string | string[];
|
||||
tools?: any[];
|
||||
};
|
||||
export declare const resolvePackagePath: (dir: string) => string;
|
||||
export declare const template_path: (template: string) => string;
|
||||
export declare const load: (options?: any) => {
|
||||
glob: string | string[];
|
||||
messages: TMessageParam[];
|
||||
tools: any[];
|
||||
};
|
||||
100
packages/osr-ai-templates/templates/index.js
Normal file
100
packages/osr-ai-templates/templates/index.js
Normal file
@ -0,0 +1,100 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.load = exports.template_path = exports.resolvePackagePath = exports.TEMPLATE_ROOT = void 0;
|
||||
const _glob_1 = require("@plastichub/osr-commons/_glob");
|
||||
const osr_commons_1 = require("@plastichub/osr-commons");
|
||||
const read_1 = require("@plastichub/fs/read");
|
||||
const exists_1 = require("@plastichub/fs/exists");
|
||||
const path = __importStar(require("node:path"));
|
||||
const tools_1 = require("@plastichub/osr-ai-tools/tools");
|
||||
const __1 = require("../");
|
||||
const API_PREFIX = 'polymech';
|
||||
const TEMPLATE_PREFIX = 'ai-template';
|
||||
exports.TEMPLATE_ROOT = "${POLYMECH-ROOT}";
|
||||
const resolvePackagePath = (dir) => (0, osr_commons_1.resolve)(path.join(__dirname, dir || ''));
|
||||
exports.resolvePackagePath = resolvePackagePath;
|
||||
const template_path = (template) => path.resolve((0, osr_commons_1.resolve)(path.join(exports.TEMPLATE_ROOT, `${TEMPLATE_PREFIX}-${template}`)));
|
||||
exports.template_path = template_path;
|
||||
const load = (options = {}) => {
|
||||
const templateDir = (0, exports.template_path)(options.template);
|
||||
const target = path.resolve(options.output || options.path);
|
||||
if (!(0, exists_1.sync)(target)) {
|
||||
__1.logger.error(`Target directory ${target} does not exist.`);
|
||||
return {
|
||||
glob: [],
|
||||
messages: [],
|
||||
tools: []
|
||||
};
|
||||
}
|
||||
if (!(0, exists_1.sync)(templateDir)) {
|
||||
return {
|
||||
glob: [],
|
||||
messages: [],
|
||||
tools: []
|
||||
};
|
||||
}
|
||||
const config = (0, read_1.sync)(path.join(templateDir, "package.json"), 'json') || {};
|
||||
let files = (0, _glob_1.filesEx)(templateDir, options.glob || config.glob || [], {}).filter((file) => file.toLowerCase() !== "readme.md");
|
||||
files = files.filter((file) => !options.disable.includes(path.parse(file).name));
|
||||
const messages = files.map((file) => {
|
||||
return {
|
||||
role: "system",
|
||||
content: (0, osr_commons_1.substitute)(false, (0, read_1.sync)(file, 'string'), options.variables, true)
|
||||
};
|
||||
});
|
||||
const tools = (config.tools || []).map((tool) => {
|
||||
if (tools_1.tools[tool]) {
|
||||
try {
|
||||
return tools_1.tools[tool](target);
|
||||
}
|
||||
catch (e) {
|
||||
__1.logger.error(`Error loading tool ${tool}`, e.message);
|
||||
}
|
||||
}
|
||||
const toolPath = path.resolve(path.join(templateDir, tool));
|
||||
if ((0, exists_1.sync)(toolPath)) {
|
||||
try {
|
||||
const tTool = require(toolPath);
|
||||
if (tTool && tTool.tools) {
|
||||
return tTool.tools(target);
|
||||
}
|
||||
else {
|
||||
__1.logger.error(`Error loading tool ${tool}`, `No 'tools' function exported in ${toolPath}`);
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
__1.logger.error(e);
|
||||
}
|
||||
}
|
||||
}).flat().filter((tool) => tool).filter((tool) => options.disableTools.includes(tool.function.name) === false);
|
||||
return {
|
||||
glob: config.glob,
|
||||
messages,
|
||||
tools
|
||||
};
|
||||
};
|
||||
exports.load = load;
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
packages/osr-ai-templates/templates/index.js.map
Normal file
1
packages/osr-ai-templates/templates/index.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/templates/index.ts"],"names":[],"mappings":"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"}
|
||||
14
packages/osr-ai-templates/templates/typescript-cli/index.d.ts
vendored
Normal file
14
packages/osr-ai-templates/templates/typescript-cli/index.d.ts
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
import { ChatCompletionTool } from "openai/resources/index.mjs";
|
||||
import { TMessageParam } from '..';
|
||||
export declare const defaults: (options: {
|
||||
readme?: boolean;
|
||||
git?: boolean;
|
||||
npm?: boolean;
|
||||
fs?: boolean;
|
||||
path?: string;
|
||||
glob?: string[];
|
||||
}) => {
|
||||
glob: string[];
|
||||
messages: TMessageParam[];
|
||||
tools: Array<ChatCompletionTool>;
|
||||
};
|
||||
26
packages/osr-ai-templates/templates/typescript-cli/index.js
Normal file
26
packages/osr-ai-templates/templates/typescript-cli/index.js
Normal file
@ -0,0 +1,26 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.defaults = void 0;
|
||||
const system_1 = require("../../common/system");
|
||||
const tools_1 = require("@plastichub/osr-ai-tools/tools");
|
||||
const __1 = require("..");
|
||||
const defaults = (options) => {
|
||||
debugger;
|
||||
const template = (0, __1.load)('', options);
|
||||
const _tools = Object.keys(tools_1.tools).map(key => options[key] ? tools_1.tools[key](options.path) : []).flat();
|
||||
return {
|
||||
glob: options.glob || [
|
||||
"src/**/*.ts",
|
||||
"package.json",
|
||||
"Readme.md"
|
||||
],
|
||||
messages: [
|
||||
...(0, system_1.TypescriptEnvironmentCLI)(),
|
||||
...(0, system_1.TypescriptLibraries)(),
|
||||
...(0, system_1.OSRTypescript)(),
|
||||
],
|
||||
tools: _tools
|
||||
};
|
||||
};
|
||||
exports.defaults = defaults;
|
||||
//# sourceMappingURL=index.js.map
|
||||
@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/templates/typescript-cli/index.ts"],"names":[],"mappings":";;;AAEA,gDAAkG;AAClG,0DAAsD;AAOtD,0BAAyC;AAElC,MAAM,QAAQ,GAAG,CACpB,OAOC,EAAE,EAAE;IAEL,QAAQ,CAAA;IACR,MAAM,QAAQ,GAAG,IAAA,QAAI,EAAC,EAAE,EAAE,OAAO,CAAC,CAAA;IAElC,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,aAAK,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,aAAK,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,CAAA;IACjG,OAAO;QACH,IAAI,EAAE,OAAO,CAAC,IAAI,IAAI;YAClB,aAAa;YACb,cAAc;YACd,WAAW;SACd;QACD,QAAQ,EAAE;YACN,GAAG,IAAA,iCAAwB,GAAS;YACpC,GAAG,IAAA,4BAAmB,GAAS;YAC/B,GAAG,IAAA,sBAAa,GAAS;SACT;QACpB,KAAK,EAAE,MAAmC;KAC7C,CAAA;AACL,CAAC,CAAA;AA3BY,QAAA,QAAQ,YA2BpB"}
|
||||
160
packages/osr-ai-templates/templates/typescript-cli/index.md
Normal file
160
packages/osr-ai-templates/templates/typescript-cli/index.md
Normal file
@ -0,0 +1,160 @@
|
||||
## Defaults
|
||||
|
||||
## Filesystem
|
||||
|
||||
For filesystem operations, use
|
||||
|
||||
import { sync as rm } from '@plastichub/fs/remove' (path)
|
||||
import { sync as dir } from '@plastichub/fs/dir' (path)
|
||||
import { sync as write } from '@plastichub/fs/write' (path, content)
|
||||
import { sync as read } from '@plastichub/fs/read' (path)
|
||||
import { filesEx as glob } from '@plastichub/osr-commons/_glob' (directory,glob | glob[])
|
||||
|
||||
## Configuration
|
||||
|
||||
API keys and other settings:
|
||||
|
||||
```ts
|
||||
import { CONFIG_DEFAULT } from '@plastichub/osr-commons'
|
||||
export const foo = (yarg) => {
|
||||
const config = CONFIG_DEFAULT(args.env_key) as any
|
||||
if (!config) {
|
||||
logger.warn('No config found!')
|
||||
return
|
||||
}
|
||||
if (config && !config.openai.key) {
|
||||
logger.warn('No OpenAI key found in config!')
|
||||
return
|
||||
}
|
||||
const api_key = argv.openai_key || process.env.OPENAI_API_KEY || config.openai.key
|
||||
}
|
||||
```
|
||||
|
||||
## Zod Schemas
|
||||
|
||||
The framework provides tools to convert from a Zod schema to Yargs as follows
|
||||
|
||||
```ts
|
||||
|
||||
import { toYargs } from '@plastichub/osr-commons'
|
||||
import { MySchema } from 'src/schemas.ts'
|
||||
// example : const options = (yargs: CLI.Argv) => toYargs(yargs, MySchema())
|
||||
```
|
||||
|
||||
Additionally, all Zod schemas will be exported on demand, via Yargs command "types"
|
||||
|
||||
```ts
|
||||
import { generate_interfaces } from '@plastichub/osr-commons'
|
||||
import { MySchema } from 'src/schemas'
|
||||
|
||||
export const types = () => generate_interfaces(
|
||||
[
|
||||
MySchema()
|
||||
], 'src/zod_types.ts')
|
||||
```
|
||||
|
||||
### Logging
|
||||
|
||||
Each package has a tslog factory at src/index.ts. Use it for all commands and library functions
|
||||
|
||||
```ts
|
||||
export { Logger } from 'tslog'
|
||||
import { createLogger } from '@plastichub/osr-log'
|
||||
import { Logger } from 'tslog'
|
||||
export const logger:Logger<unknown> = createLogger('Package Name')
|
||||
```
|
||||
|
||||
### LLM Tools
|
||||
|
||||
LLM Tools are specified as follows
|
||||
|
||||
- always export "tools" as the main function
|
||||
- dont register LLM tools as yarg commands
|
||||
- seperate the tool's implementation in src/lib/tools
|
||||
- LLM tools require 'openai' as dependency
|
||||
|
||||
eg: src/tools/fs:
|
||||
|
||||
```ts
|
||||
import { join } from 'path'
|
||||
import * as path from 'path'
|
||||
import { RunnableToolFunction } from 'openai/lib/RunnableFunction'
|
||||
import { isString } from '@plastichub/core/primitives'
|
||||
import { sync as dir } from '@plastichub/fs/dir'
|
||||
import { sync as write } from '@plastichub/fs/write'
|
||||
import { resolve } from "@plastichub/osr-commons"
|
||||
import { logger } from '../'
|
||||
|
||||
export const tools = (target:any, variables:Record<string,string>={}): Array<any> => {
|
||||
return [
|
||||
{
|
||||
type: 'function',
|
||||
function: {
|
||||
name: "read_file",
|
||||
description: "read a file, at given a path",
|
||||
parameters: {
|
||||
type: "object",
|
||||
properties: {
|
||||
file: {
|
||||
type: "object",
|
||||
properties: {
|
||||
path: { type: "string" }
|
||||
}
|
||||
}
|
||||
},
|
||||
required: ["file"],
|
||||
},
|
||||
function: async (ret) => {
|
||||
try {
|
||||
const { file } = ret as any
|
||||
const filePath = path.resolve(resolve(join(target, file.path),false,variables))
|
||||
logger.debug(`Tool::ReadFile Reading file ${filePath}`)
|
||||
} catch (error) {
|
||||
logger.error(`Error reading file`, error)
|
||||
}
|
||||
},
|
||||
parse: JSON.parse
|
||||
}
|
||||
} as RunnableToolFunction<{ id: string }>
|
||||
]
|
||||
}
|
||||
```
|
||||
### Typescript tsconfig
|
||||
|
||||
Use this defaults
|
||||
|
||||
```json
|
||||
"compilerOptions": {
|
||||
"target": "ES2020",
|
||||
"module": "commonjs",
|
||||
"outDir": "./dist",
|
||||
"rootDir": "./src",
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true,
|
||||
"allowJs": true,
|
||||
"noImplicitAny": false,
|
||||
"strictNullChecks": false,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
```
|
||||
|
||||
### Yargs
|
||||
|
||||
Commands are registered as follows (src/command/index.ts) :
|
||||
|
||||
```ts
|
||||
import type { Argv } from 'yargs'
|
||||
import { types } from './types'
|
||||
export const commands = (yargs: Argv) =>
|
||||
{
|
||||
return yargs
|
||||
.command('types', 'Generate TypeScript interfaces from Zod schemas', {}, types)
|
||||
.strict()
|
||||
.help()
|
||||
}
|
||||
```
|
||||
|
||||
### Nodejs
|
||||
|
||||
- import built-ins always as import * as 'path'
|
||||
@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "@polymech/ai-template-typescript",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"glob": [
|
||||
"src/**/*.ts",
|
||||
"package.json",
|
||||
"Readme.md"
|
||||
],
|
||||
"tools":["npm","fs","git","./tools"]
|
||||
}
|
||||
34
packages/osr-ai-templates/tsconfig.json
Normal file
34
packages/osr-ai-templates/tsconfig.json
Normal file
@ -0,0 +1,34 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"lib": [
|
||||
"ES2021",
|
||||
"ES2022.Object",
|
||||
"DOM"
|
||||
],
|
||||
"target": "ES2021",
|
||||
"module": "nodenext",
|
||||
"allowJs": true,
|
||||
"noImplicitAny": false,
|
||||
"noImplicitThis": false,
|
||||
"alwaysStrict": true,
|
||||
"sourceMap": true,
|
||||
"outDir": "./",
|
||||
"experimentalDecorators": true,
|
||||
"emitDecoratorMetadata": true,
|
||||
"pretty": false,
|
||||
"baseUrl": "./src",
|
||||
"rootDir": "./src",
|
||||
"skipLibCheck": true,
|
||||
"allowSyntheticDefaultImports": true
|
||||
},
|
||||
"compileOnSave": false,
|
||||
"filesGlob": [
|
||||
"./src/**/*.ts"
|
||||
],
|
||||
"files": [
|
||||
"./src/index.ts",
|
||||
"./src/main.ts",
|
||||
"./src/common/system.ts",
|
||||
"./src/templates/index.ts"
|
||||
]
|
||||
}
|
||||
4
packages/osr-templates/.gitignore
vendored
Normal file
4
packages/osr-templates/.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
/node_modules
|
||||
/coverage
|
||||
*.log
|
||||
.DS_Store
|
||||
80
packages/osr-templates/README.md
Normal file
80
packages/osr-templates/README.md
Normal file
@ -0,0 +1,80 @@
|
||||
# OSR - Templates
|
||||
|
||||
## Discourse
|
||||
|
||||
### Component
|
||||
|
||||
#### Resources
|
||||
|
||||
- [ ] Git-Link
|
||||
- [ ] Issues (List & New)
|
||||
- [ ] Specs - PDF
|
||||
- [ ] PDF
|
||||
- [ ] Replaced by / ...
|
||||
- [ ] Howtos
|
||||
- [ ] Social media
|
||||
|
||||
#### Meta
|
||||
|
||||
- [ ] Changelog
|
||||
- [ ] Versions
|
||||
|
||||
#### Display
|
||||
|
||||
- [ ] Gallery
|
||||
- [ ] Products (:)
|
||||
- [ ] Options
|
||||
- [ ] Components
|
||||
- [ ] Drawings (overview/parts) +source
|
||||
|
||||
---
|
||||
|
||||
#### Directory Item
|
||||
|
||||
- [ ] Gallery / Portfolio
|
||||
- [ ] Products (:)
|
||||
- [ ] Links
|
||||
- [ ] Feed
|
||||
- [ ] Activity (intern ;)
|
||||
|
||||
## Item Raw (-)
|
||||
|
||||
- [ ] history
|
||||
- [ ] i18n branches
|
||||
- [ ] versions
|
||||
- [ ] compat/specs
|
||||
- [ ] tests
|
||||
- [ ] meta / refs
|
||||
|
||||
|
||||
## OSRL
|
||||
|
||||
- [ ] Media filter (square)
|
||||
- [ ] osr-discourse / osr-csart API
|
||||
- [ ] osr-cad API
|
||||
|
||||
|
||||
## Tests
|
||||
|
||||
- [ ] bundle (format?)
|
||||
- [ ] config(s)
|
||||
- [ ] footage
|
||||
- [ ] reports
|
||||
- [ ] setup
|
||||
|
||||
|
||||
## Commands
|
||||
|
||||
### `list` (registry)
|
||||
|
||||
### `info` (short)
|
||||
|
||||
### `bundle` (create)
|
||||
|
||||
### `get/set` (registry)
|
||||
|
||||
### `merge` (registry)
|
||||
|
||||
|
||||
|
||||
|
||||
46
packages/osr-templates/astro/.astro.json
Normal file
46
packages/osr-templates/astro/.astro.json
Normal file
@ -0,0 +1,46 @@
|
||||
{
|
||||
"includes": [
|
||||
|
||||
],
|
||||
"variables": {
|
||||
"PRODUCT_ROOT": "${root}/${product}/",
|
||||
"abs_url": "https://assets.osr-plastic.org",
|
||||
"CACHE": "${root}/cache/",
|
||||
"CACHE_URL": "${abs_url}/cache/",
|
||||
"GIT_REPO": "https://git.polymech.io/",
|
||||
"_OSR_MACHINES_ASSETS_URL":"https://assets.osr-plastic.org/machines/",
|
||||
"OSR_MACHINES_ASSETS_URL":"https://assets.osr-plastic.org",
|
||||
"PRODUCTS_ASSETS_URL":"https://assets.osr-plastic.org/machines/${product_rel}",
|
||||
"OSR_FILES_WEB":"https://files.polymech.io/files/machines",
|
||||
"PRODUCTS_FILES_URL":"${OSR_FILES_WEB}/${product_rel}",
|
||||
"DISCORD":"https://discord.gg/s8K7yKwBRc"
|
||||
},
|
||||
"env": {
|
||||
"astro-release":{
|
||||
"includes": [
|
||||
"${PRODUCT_ROOT}"
|
||||
],
|
||||
"variables": {
|
||||
"OSR_MACHINES_ASSETS_URL":"https://assets.osr-plastic.org/machines/"
|
||||
}
|
||||
},
|
||||
"astro-debug":{
|
||||
"includes": [
|
||||
"${PRODUCT_ROOT}"
|
||||
],
|
||||
"variables": {
|
||||
"OSR_MACHINES_ASSETS_URL":"https://assets.osr-plastic.org",
|
||||
"showCart": false,
|
||||
"showPrice": false,
|
||||
"showResources": false,
|
||||
"showShipping": false,
|
||||
"showPaymentTerms": false,
|
||||
"showHowtos": false,
|
||||
"showRenderings": true,
|
||||
"debug": true
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
6
packages/osr-templates/commons/authors.osr
Normal file
6
packages/osr-templates/commons/authors.osr
Normal file
@ -0,0 +1,6 @@
|
||||
[%-if showHeader -%]
|
||||
## Authors
|
||||
[%-endif%]
|
||||
[%- for author in authors -%]
|
||||
- [ [[author.name]] ]( [[author.url]] )
|
||||
[%- endfor -%]
|
||||
7
packages/osr-templates/commons/components.osr
Normal file
7
packages/osr-templates/commons/components.osr
Normal file
@ -0,0 +1,7 @@
|
||||
## Components
|
||||
|
||||
[% for component in components %]
|
||||
[%- if component.store -%]
|
||||
- [ [[component.name]] ]( [[component.store]] )
|
||||
[% endif %]
|
||||
[% endfor %]
|
||||
16
packages/osr-templates/commons/product_table.osr
Normal file
16
packages/osr-templates/commons/product_table.osr
Normal file
@ -0,0 +1,16 @@
|
||||
[%js%]
|
||||
const _path = path.resolve(`${PRODUCT_ROOT}/${table}`)
|
||||
if(!fs.exists(_path)){
|
||||
console.warn('cant find table', _path)
|
||||
return
|
||||
}
|
||||
console.log(' table path ' + _path)
|
||||
let data = xlsx.parse(_path)
|
||||
data[0].data = data[0].data.filter((d)=>d.length >0)
|
||||
data = markdownTable(data[0].data)
|
||||
if(html){
|
||||
return md2html(data)
|
||||
}else{
|
||||
data
|
||||
}
|
||||
[%endjs%]
|
||||
108
packages/osr-templates/discourse/base.json
Normal file
108
packages/osr-templates/discourse/base.json
Normal file
@ -0,0 +1,108 @@
|
||||
{
|
||||
"includes": [
|
||||
"${root}/osr",
|
||||
"${root}/osr/widgets",
|
||||
"${OSR_ROOT}/osr-templates/commons",
|
||||
"${OSR_ROOT}/osr-templates/discourse",
|
||||
"${OSR_ROOT}/osr-templates/discourse/commons",
|
||||
"${OSR_ROOT}/osr-templates/discourse/widgets",
|
||||
"${PRODUCT_ROOT}",
|
||||
"${PRODUCT_ROOT}/templates/site/",
|
||||
"${PRODUCT_ROOT}/templates/shared/"
|
||||
],
|
||||
"variables": {
|
||||
|
||||
"PRODUCT_ROOT": "${root}/${product}/",
|
||||
"abs_url": "https://assets.osr-plastic.org",
|
||||
"CACHE": "${root}/cache/",
|
||||
|
||||
"GIT_REPO": "https://git.osr-plastic.org/osr-plastic/osr-machines",
|
||||
|
||||
"OSR_MACHINES_ASSETS_URL": "https://assets.osr-plastic.org/machines/",
|
||||
"OSR_FILES_WEB": "https://files.osr-plastic.org/files/osr-machines",
|
||||
|
||||
"OSR_DIRECTORY_ASSETS_URL": "https://assets.osr-plastic.org/directory/",
|
||||
"OSR_DIRECTORY_FILES_WEB": "http://files.osr-plastic.org/files/directory",
|
||||
|
||||
|
||||
"PRODUCTS_FILES_URL": "${OSR_FILES_WEB}/${product_rel}",
|
||||
"PRODUCTS_ASSETS_URL": "https://assets.osr-plastic.org/machines/${product}",
|
||||
|
||||
"OSR_HOWTOS_ROOT_URL": "${vendor_forum}/c/wiki/howtos/72",
|
||||
"OSR_FORUM_URL":"https://forum.osr-plastic.org",
|
||||
|
||||
"vendor_name": "Plastic Hub",
|
||||
"vendor_website": "https://osr-plastic.org/",
|
||||
"vendor_products_external": "https://plastic-hub.com/products/",
|
||||
"vendor_instagram": "https://www.instagram.com/osr_plastic/",
|
||||
"_vendor_youtube": "https://www.youtube.com/channel/UCuWDxJtV2pf5BefHEy09Cew/featured?view_as=subscriber",
|
||||
"vendor_github": "https://git.osr-plastic.org/osr-plastic",
|
||||
"vendor_contact_email": "mailto:sales@plastic-hub.com",
|
||||
"vendor_whatsapp": "tel:0034691952287",
|
||||
"vendor_facebook": "https://www.facebook.com/plastichubcat/",
|
||||
"vendor_discord": "https://discord.gg/vR5d6ShTez",
|
||||
"author_link_pp": "https://preciousplastic.com/",
|
||||
"author_link": "https://osr-plastic.org",
|
||||
"vendor_forum": "https://forum.osr-plastic.org",
|
||||
"show": {
|
||||
"badges": false,
|
||||
"authors": true,
|
||||
"head": true,
|
||||
"debug": false,
|
||||
"wiki": false,
|
||||
"forum": false,
|
||||
"others": false,
|
||||
"howtos": false,
|
||||
"instagram": false,
|
||||
"shipping": false,
|
||||
"payment_terms": false,
|
||||
"components": true,
|
||||
"marketplaceLinks": true,
|
||||
"productDump": false,
|
||||
"configDump": false,
|
||||
"issues": false,
|
||||
"alternatives": true,
|
||||
"replacedBy": true,
|
||||
"meta":true
|
||||
}
|
||||
},
|
||||
"env": {
|
||||
"bazar": {
|
||||
"includes": [],
|
||||
"variables": {
|
||||
"abs_url": "https://dev.osr-plastic.org/"
|
||||
}
|
||||
},
|
||||
"bazar-release": {
|
||||
"includes": [],
|
||||
"variables": {
|
||||
"abs_url": "https://shop.osr-plastic.org/"
|
||||
}
|
||||
},
|
||||
"test-import": {},
|
||||
"forum": {
|
||||
"includes": [],
|
||||
"variables": {
|
||||
"forum_url": "https://forum.osr-plastic.org/",
|
||||
"show": {
|
||||
"badges": true,
|
||||
"authors": true,
|
||||
"head": true,
|
||||
"debug": false,
|
||||
"wiki": false,
|
||||
"forum": false,
|
||||
"others": false,
|
||||
"howtos": true,
|
||||
"instagram": false,
|
||||
"shipping": false,
|
||||
"payment_terms": false,
|
||||
"components": true,
|
||||
"marketplaceLinks": true,
|
||||
"meta":true,
|
||||
"productDump": true,
|
||||
"configDump": false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,50 @@
|
||||
### Resources
|
||||
|
||||
[% if product.forum %]
|
||||
- [Forum]([[product.forum]])
|
||||
[% endif %]
|
||||
[% if product.download %]
|
||||
- [Download]([[product.download]])
|
||||
[% endif %]
|
||||
[% if product.firmware %]
|
||||
- [Firmware]([[product.firmware]])
|
||||
[% endif %]
|
||||
|
||||
[% if product.Preview3d %]
|
||||
[% if product.edrawings %]
|
||||
- [3D-Preview]([[product.edrawings]])
|
||||
[% else %]
|
||||
- [3D-Preview]([[product.abs_url]]/[[product.product_rel]]/resources/edrawings.html)
|
||||
[% endif %]
|
||||
- [Source Code Repository]([[GIT_REPO]]/src/branch/master/machines/[[product.rel]])
|
||||
[%endif%]
|
||||
[% if product.hasSpec %]
|
||||
- [Specification PDF]([[product.abs_url]]/[[product.product_rel]]/resources/spec.pdf)
|
||||
[%endif%]
|
||||
|
||||
[% if product.howtoSection %]
|
||||
- [How-tos]([[product.howtoSection]])
|
||||
[%endif%]
|
||||
|
||||
[% if product.library %]
|
||||
- [Library]([[product.library]])
|
||||
[%endif%]
|
||||
|
||||
<hr/>
|
||||
[% if config.show.wiki %]
|
||||
[% if product.wiki_articles %]
|
||||
<h4>Wiki Articles</h4>
|
||||
[% include "product_wiki.osr" category:product.wiki_articles %]
|
||||
[% else %]
|
||||
[% endif %]
|
||||
[% else %]
|
||||
[% endif %]
|
||||
|
||||
[% if config.show.forum %]
|
||||
[% if product.forumCategory %]
|
||||
<h4>Forum Posts</h4>
|
||||
[% include "product_forum.osr" category:product.forumCategory %]
|
||||
[% endif %]
|
||||
[% endif %]
|
||||
|
||||
[% include "extra_resources.md" %]
|
||||
@ -0,0 +1,24 @@
|
||||
[% js %]
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
const d = new discourse.Discourser({
|
||||
host: config.discourse.host,
|
||||
key: config.discourse.key,
|
||||
username: config.discourse.username,
|
||||
rateLimitConcurrency: 1
|
||||
});
|
||||
|
||||
d.getTopicItemsOfCategories([cat]).then(posts => {
|
||||
//console.log('posts', posts)
|
||||
let content = "<ul>"
|
||||
posts = posts.map((p) => {
|
||||
const url = `${config.discourse.host}/t/${p.id}`;
|
||||
const title = `${p.fancy_title}`;
|
||||
return `<li><a href="${url}">${title}</a></li>`;
|
||||
}).join('\n');
|
||||
content += posts + "</ul>";
|
||||
resolve(content);
|
||||
|
||||
});
|
||||
})
|
||||
[% endjs -%]
|
||||
22
packages/osr-templates/discourse/commons/instagram.osr
Normal file
22
packages/osr-templates/discourse/commons/instagram.osr
Normal file
@ -0,0 +1,22 @@
|
||||
<h4 style="text-align:center"> Our latest Instagram posts </h4>
|
||||
|
||||
[%js%]
|
||||
|
||||
return cacache.get.info(CACHE, 'vendor-instagram').then((cache)=>{
|
||||
if(cache){
|
||||
return cacache.get(CACHE, 'vendor-instagram').then((cached)=>{
|
||||
return cached.data.toString();
|
||||
})
|
||||
}
|
||||
console.log('get instagram images');
|
||||
return instagram.images(config.instagram.user,config.instagram.token,global).then((images)=>{
|
||||
images = images.slice(0, 8);
|
||||
images = html.container.wrap(images.map((i)=> html.container.item(html.image(i,null,'max-height:200px'),'border:none; width:200px;max-height:200px')).join('\n'));
|
||||
return cacache.put(CACHE,'vendor-instagram',images).then(()=>{
|
||||
return images;
|
||||
})
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
[%endjs%]
|
||||
BIN
packages/osr-templates/discourse/commons/parts.xlsx
Normal file
BIN
packages/osr-templates/discourse/commons/parts.xlsx
Normal file
Binary file not shown.
BIN
packages/osr-templates/discourse/commons/specs.xlsx
Normal file
BIN
packages/osr-templates/discourse/commons/specs.xlsx
Normal file
Binary file not shown.
1
packages/osr-templates/discourse/commons/test.osr
Normal file
1
packages/osr-templates/discourse/commons/test.osr
Normal file
@ -0,0 +1 @@
|
||||
helo
|
||||
13
packages/osr-templates/discourse/commons/xlsx.osr
Normal file
13
packages/osr-templates/discourse/commons/xlsx.osr
Normal file
@ -0,0 +1,13 @@
|
||||
[% js %]
|
||||
const _path = lookup(file);
|
||||
if (!fs.exists(_path)) {
|
||||
return '';
|
||||
} else {
|
||||
const t = global;
|
||||
let data = xlsx.parse(_path);
|
||||
data[0].data = data[0].data.filter((d) => !!d.length);
|
||||
data = markdownTable(data[0].data);
|
||||
const ret = md2html(data);
|
||||
return ret
|
||||
}
|
||||
[% endjs %]
|
||||
@ -0,0 +1,7 @@
|
||||
## [[country]]
|
||||
|
||||
[[COUNTRY_BRIEF]]
|
||||
|
||||
[COUNTRY_MAP_LINK]([[country_map]])
|
||||
|
||||
[[COUNTRY_BODY]]
|
||||
@ -0,0 +1 @@
|
||||
[[user_directory_index]]
|
||||
32
packages/osr-templates/discourse/directory/user.md
Normal file
32
packages/osr-templates/discourse/directory/user.md
Normal file
@ -0,0 +1,32 @@
|
||||
[[user_header_before]]
|
||||
|
||||
**Brief** [[short]]
|
||||
**Censored** [[censored]]
|
||||
**Continent** [[continent]]
|
||||
**Country** [[country]]
|
||||
**Area** [[area]]
|
||||
**Created** [[created]]
|
||||
**Modified** [[modified]]
|
||||
**Last Active** [[lastActive]]
|
||||
|
||||
[[user_header_after]]
|
||||
|
||||
![[[user_hero_alt]]]([[user_hero_src]])
|
||||
|
||||
[[ user_body ]]
|
||||
|
||||
### Services
|
||||
|
||||
[[user_services]]
|
||||
|
||||
### Links
|
||||
|
||||
[[user_links]]
|
||||
|
||||
[[user_directions]]
|
||||
|
||||
[[user_images_gallery]]
|
||||
|
||||
[[user_footer]]
|
||||
|
||||
[[user_footer_after]]
|
||||
13
packages/osr-templates/discourse/drawings.osr
Normal file
13
packages/osr-templates/discourse/drawings.osr
Normal file
@ -0,0 +1,13 @@
|
||||
<div>
|
||||
[%js%]
|
||||
const _path = substitute(`${cwd}/${product_rel}/${path}`);
|
||||
debugger
|
||||
if(fs.images(_path).length)
|
||||
{
|
||||
const t = html.drawings(`${abs_url}/${product_rel}/${path}`,_path);
|
||||
return `<h4 style="text-align:center">${name}</h4>${t}`;
|
||||
}else{
|
||||
console.log(_path + ' : doesnt exists');
|
||||
}
|
||||
[%endjs%]
|
||||
</div>
|
||||
0
packages/osr-templates/discourse/extra_resources.md
Normal file
0
packages/osr-templates/discourse/extra_resources.md
Normal file
25
packages/osr-templates/discourse/howto/howto.md
Normal file
25
packages/osr-templates/discourse/howto/howto.md
Normal file
@ -0,0 +1,25 @@
|
||||
<div data-theme-toc="true"/> </div>
|
||||
|
||||
${description}
|
||||
|
||||
${header}
|
||||
|
||||
---
|
||||
|
||||
${used_machines}
|
||||
|
||||
## Attachments
|
||||
|
||||
${files}
|
||||
|
||||
## Resources
|
||||
|
||||
- [Browse Files](http://files.osr-plastic.org/files/howtos/${slug}/)
|
||||
|
||||
## 3D Files
|
||||
|
||||
${previews3D}
|
||||
|
||||
---
|
||||
|
||||
${steps}
|
||||
5
packages/osr-templates/discourse/howto/step.md
Normal file
5
packages/osr-templates/discourse/howto/step.md
Normal file
@ -0,0 +1,5 @@
|
||||
## Step ${step_number} - ${title}
|
||||
|
||||
${text}
|
||||
|
||||
${images}
|
||||
74
packages/osr-templates/discourse/library/machine_layout.osr
Normal file
74
packages/osr-templates/discourse/library/machine_layout.osr
Normal file
@ -0,0 +1,74 @@
|
||||
<ul class="nav nav-tabs" id="myTab" role="tablist">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link active" id="overview-tab" data-toggle="tab" href="#overview" role="tab" aria-controls="overview"
|
||||
aria-selected="true">Overview</a>
|
||||
</li>
|
||||
{% if page.tabs.build != false %}
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" id="build-tab" data-toggle="tab" href="#build" role="tab" aria-controls="build"
|
||||
aria-selected="false">Build</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" id="resources-tab" data-toggle="tab" href="#resources" role="tab" aria-controls="resources"
|
||||
aria-selected="false">Resources</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" id="media-tab" data-toggle="tab" href="#media" role="tab" aria-controls="media"
|
||||
aria-selected="false">Media</a>
|
||||
</li>
|
||||
{% if page.wiring %}
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" id="wiring-tab" data-toggle="tab" href="#wiring" role="tab" aria-controls="wiring"
|
||||
aria-selected="false">Electronics</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
<div class="tab-content">
|
||||
<div class="tab-pane active" id="overview" role="tabpanel" aria-labelledby="overview-tab">
|
||||
[%- include "overview.osr" -%]
|
||||
{% if page.showResources == false %}
|
||||
{% else %}
|
||||
{% include product_resoures_bar.html %}
|
||||
{% endif %}
|
||||
<div style="clear:both">
|
||||
[%- include "product_overview_drawings.osr" -%]
|
||||
</div>
|
||||
{%if page.products %}
|
||||
<div class="row vertical-margin vertical-gap">
|
||||
<div class="col">
|
||||
<h3 class="text-center" id="products">What others do with <span class="italic">'{{ page.name }}'</span></h3>
|
||||
<div class="vertical-margin vertical-gap"></div>
|
||||
{% include products_row.html %}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
</div>
|
||||
{% if page.tabs.build != false %}
|
||||
<div class="tab-pane" id="build" role="tabpanel" aria-labelledby="build-tab">
|
||||
{% include product_build.md %}
|
||||
{% include meta_build.md %}
|
||||
[%- include "cam_html.osr" %]
|
||||
[%- include "drawings.osr" name:'Drawings' path:'drawings' url:`${abs_url}` -%]
|
||||
[%- if product.private.previews3D -%]
|
||||
<h5>3D Files - Preview</h5>
|
||||
[[ product.private.previews3D ]]
|
||||
[% endif -%]
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="tab-pane" id="resources" role="tabpanel" aria-labelledby="resources-tab"><span style="font-size:smaller">
|
||||
|
||||
[% include "product_resources.md" %]
|
||||
|
||||
</span>
|
||||
</div>
|
||||
<div class="tab-pane" id="media" role="tabpanel" aria-labelledby="media-tab">
|
||||
[%- if product.gallery!=false %]
|
||||
[%- include "gallery.osr" name:'Gallery' path:'media/gallery' url:`${abs_url}` %]
|
||||
[%endif%]
|
||||
</div>
|
||||
{% if page.wiring %}
|
||||
<div class="tab-pane" id="wiring" role="tabpanel" aria-labelledby="wiring-tab"></div>
|
||||
{% endif %}
|
||||
</div>
|
||||
7
packages/osr-templates/discourse/library/other_item.html
Normal file
7
packages/osr-templates/discourse/library/other_item.html
Normal file
@ -0,0 +1,7 @@
|
||||
<div class="ty-grid-list__item" style="float:left;border-color: #c5c5c5;width: 300px;display: inline-block;border-width: 1px;">
|
||||
<a href="${link}">
|
||||
<img height="200px" src="${image}" style="border-radius: 4px;">
|
||||
<br />
|
||||
<h5 style="text-align: center;">${name}</h5>
|
||||
</a>
|
||||
</div>
|
||||
38
packages/osr-templates/discourse/library/overview.osr
Normal file
38
packages/osr-templates/discourse/library/overview.osr
Normal file
@ -0,0 +1,38 @@
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-sm vertical-margin">
|
||||
<a href="{{ page.image | relative_url }}">
|
||||
<img loading=lazy src="{{ page.image | relative_url }}" alt="{{ image_description }}"
|
||||
class="page__hero-image teaser-image-contain-large">
|
||||
</a>
|
||||
</div>
|
||||
<div class="col-sm">
|
||||
<div class="teaser-content2">
|
||||
<span class="teaser-text"></span>
|
||||
<div class="archive__item-body teaser-text-row">
|
||||
[% include "body.md" %]
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
{% if page.showSpecification != false %}
|
||||
<div class="col-sm">
|
||||
<div class="" style="border: 1px gray; ">
|
||||
<h4 id="authors">Specification</h4>
|
||||
[%- include "product_specs.osr" html:true -%]
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if page.showAuthors == false %}
|
||||
{% else %}
|
||||
<div class="col-sm">
|
||||
<div class="" style="border: 1px gray; ">
|
||||
[%- if config.show.authors -%]
|
||||
[%- include "authors_html.osr" authors:product.authors showHeader:true -%]
|
||||
[%- endif -%]
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
@ -0,0 +1,29 @@
|
||||
<div>
|
||||
[% if product.showDimensions !=false %]
|
||||
<h4 style="text-align: center;">Dimensions</h4>
|
||||
<a href="[[product.product_dimensions]]">
|
||||
<p style="text-align: center">
|
||||
<img loading=lazy style="max-height:500px" src="[[product.product_dimensions]]">
|
||||
</p>
|
||||
</a>
|
||||
<hr/>
|
||||
[% endif %]
|
||||
[% if product.showParts !=false %]
|
||||
<div style="padding:16px; text-align: center; ">
|
||||
<div class="ty-vendor-plans">
|
||||
<div class="">
|
||||
<h4 style="text-align: center; ">Parts</h4>
|
||||
<a href="[[product.product_parts]]">
|
||||
<p style="text-align: center">
|
||||
<img loading=lazy style="max-height:500px" src="[[product.product_parts]]">
|
||||
</p>
|
||||
</a>
|
||||
</div>
|
||||
<div class="" style="text-align: left;border: 1px gray;margin:auto">
|
||||
<p style="text-align: center">[% include 'product_parts.osr' %]</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
[% endif %]
|
||||
</div>
|
||||
|
||||
12
packages/osr-templates/discourse/library/root.html
Normal file
12
packages/osr-templates/discourse/library/root.html
Normal file
@ -0,0 +1,12 @@
|
||||
[% include "product_header_jekyll.osr" %]
|
||||
[% include "product_variables.osr" %]
|
||||
[%- js -%]
|
||||
if(variables.debug['break-begin']){
|
||||
const g = global;
|
||||
const p = product;
|
||||
const c = config;
|
||||
debugger;
|
||||
}
|
||||
[%- endjs -%]
|
||||
[% include "machine_layout.osr" %]
|
||||
<hr/>
|
||||
15
packages/osr-templates/discourse/overview_drawings.osr
Normal file
15
packages/osr-templates/discourse/overview_drawings.osr
Normal file
@ -0,0 +1,15 @@
|
||||
[%- if product.showDimensions !=false -%]
|
||||
### Dimensions
|
||||
[wrap="center"]
|
||||
<img style="max-height:500px" src="[[product.product_dimensions]]"/>
|
||||
[/wrap]
|
||||
<hr/>
|
||||
[%- endif -%]
|
||||
|
||||
[%- if product.showParts !=false -%]
|
||||
[wrap="center"]
|
||||
<img style="max-height:500px" src="[[product.product_parts]]"/>
|
||||
[/wrap]
|
||||
|
||||
[% include 'product_parts.osr' %]
|
||||
[%- endif -%]
|
||||
50
packages/osr-templates/discourse/plugins/html.js
Normal file
50
packages/osr-templates/discourse/plugins/html.js
Normal file
@ -0,0 +1,50 @@
|
||||
const path = require('path');
|
||||
|
||||
const link = (name, link, _class) => `<a class="${_class||''}" ref="${link}">${name}</a>`;
|
||||
const wrap = (content) => `
|
||||
<div style="padding:16px; text-align: center; ">
|
||||
<div class="ty-vendor-plans">
|
||||
${content}
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
const image = (src, link, style) => `<a href="${link||src}"><img style="${style||''}" src="${src}"></img></a>`;
|
||||
|
||||
const item = (content, style = 'border-color: #c5c5c5;width: 300px;display: inline-block', title) =>
|
||||
`<div class="ty-grid-list__item" style="float:left;overflow:initial;${style}">
|
||||
${content}<br/>
|
||||
<h6>${title||''}</h6>
|
||||
</div>`;
|
||||
|
||||
const styles = {
|
||||
thumb: 'border:none; width:200px;max-height:200px'
|
||||
};
|
||||
|
||||
const center_caption = (el = 'h5', text) => `<${el} style="text-align:center">${text}</${el}>`;
|
||||
|
||||
const thumbs = (url, folder) => {
|
||||
const context = require('@plastichub/osrl/library').getContext();
|
||||
folder = path.resolve(folder);
|
||||
let images = context.fs.images(folder, {
|
||||
absolute: false
|
||||
});
|
||||
images = images.map((i) => item(image(`${url}/${i}`), 'border:none; width:200px;max-height:200px'));
|
||||
images = wrap(images.join('\n'));
|
||||
return images;
|
||||
}
|
||||
module.exports = {
|
||||
html: {
|
||||
link: link,
|
||||
caption: {
|
||||
center: center_caption
|
||||
},
|
||||
container: {
|
||||
wrap: wrap,
|
||||
item: item
|
||||
},
|
||||
image: image,
|
||||
styles: styles,
|
||||
thumbs: thumbs
|
||||
}
|
||||
};
|
||||
9
packages/osr-templates/discourse/product.osr
Normal file
9
packages/osr-templates/discourse/product.osr
Normal file
@ -0,0 +1,9 @@
|
||||
[% include "product_header_jekyll.osr" %]
|
||||
|
||||
[% if config.show.badges %]
|
||||
{% include product_badges.html %}
|
||||
[%endif%]
|
||||
|
||||
[% if config.show.authors %]
|
||||
[% include "authors.osr" authors:product.authors showHeader:true %]
|
||||
[%endif%]
|
||||
6
packages/osr-templates/discourse/product_debug.osr
Normal file
6
packages/osr-templates/discourse/product_debug.osr
Normal file
@ -0,0 +1,6 @@
|
||||
## Product
|
||||
[% js %]
|
||||
if(debug){
|
||||
return "<pre>" + prettyJSON(store.product) + "</pre>";
|
||||
}
|
||||
[%endjs%]
|
||||
7
packages/osr-templates/discourse/product_howtos.osr
Normal file
7
packages/osr-templates/discourse/product_howtos.osr
Normal file
@ -0,0 +1,7 @@
|
||||
[%js%]
|
||||
if(store.product.howtos && store.product.howtos.length){
|
||||
return store.product.howtos.map((i)=>{
|
||||
return i
|
||||
}).join('\n<br/>');
|
||||
}
|
||||
[%endjs%]
|
||||
9
packages/osr-templates/discourse/product_parts.osr
Normal file
9
packages/osr-templates/discourse/product_parts.osr
Normal file
@ -0,0 +1,9 @@
|
||||
[%js%]
|
||||
let p = PRODUCT_ROOT;
|
||||
const _path = path.resolve(PRODUCT_ROOT + './parts.xlsx');
|
||||
if(fs.exists(_path)){
|
||||
const data = xlsx.parse(_path);
|
||||
data[0].data = data[0].data.filter((d) => !!d.length);
|
||||
return md2html(markdownTable(data[0].data));
|
||||
}
|
||||
[%endjs%]
|
||||
34
packages/osr-templates/discourse/product_resources.osr
Normal file
34
packages/osr-templates/discourse/product_resources.osr
Normal file
@ -0,0 +1,34 @@
|
||||
#### Resources
|
||||
[%- if product.firmware -%]
|
||||
- [Firmware]([[product.firmware]])
|
||||
[%- endif -%]
|
||||
[%- if product.product_howto -%]
|
||||
- [Howto]([[product.product_howto]])
|
||||
[%- endif -%]
|
||||
[%- if product.hasFiles!=false %]
|
||||
- [Files]([[variables.OSR_FILES_WEB]]/[[product.product_rel]])
|
||||
[%- endif -%]
|
||||
- [Git Source]([[variables.GIT_REPO]]/src/branch/master/[[product.product_rel]])
|
||||
[%- if product.Preview3d -%]
|
||||
[%- if product.edrawings -%]
|
||||
- [3D Preview]([[variables.OSR_MACHINES_ASSETS_URL]]/[[product.product_rel]]/resources/edrawings.html)
|
||||
[%- else -%]
|
||||
- [3D Preview]([[variables.OSR_MACHINES_ASSETS_URL]]/[[product.product_rel]]/resources/edrawings.html)
|
||||
[%- endif -%]
|
||||
[%- endif -%]
|
||||
[%- if show.showSpecs -%]
|
||||
[%- if product.hasSpec -%]
|
||||
- [Specification PDF]([[product.abs_url]]/[[product.product_rel]]/resources/spec.pdf)
|
||||
[%- endif -%]
|
||||
[%- endif -%]
|
||||
[%- if product.gallery!=false -%]
|
||||
- [Gallery]([[variables.OSR_FILES_WEB]]/[[product.product_rel]]/media/gallery)
|
||||
[%- endif -%]
|
||||
[%- if show.forum -%]
|
||||
[%- if product.forumCategory -%]
|
||||
<h4>Forum Posts</h4>
|
||||
[% include "product_forum.osr" category:product.forumCategory %]
|
||||
[%- endif -%]
|
||||
[%- endif -%]
|
||||
|
||||
[%- include "extra_resources.md" -%]
|
||||
7
packages/osr-templates/discourse/product_showreel.osr
Normal file
7
packages/osr-templates/discourse/product_showreel.osr
Normal file
@ -0,0 +1,7 @@
|
||||
[%js%]
|
||||
if(fs.images(`${PRODUCT_ROOT}/media/products`).length){
|
||||
const t = html.thumbs(`${abs_url}/${product}/media/products`,`${PRODUCT_ROOT}/media/products`);
|
||||
return `<h4 style="text-align:center">Products done with ${store.product.product_name}</h4>
|
||||
${t}`;
|
||||
}
|
||||
[%endjs%]
|
||||
19
packages/osr-templates/discourse/product_specs.osr
Normal file
19
packages/osr-templates/discourse/product_specs.osr
Normal file
@ -0,0 +1,19 @@
|
||||
[% js %]
|
||||
const _path = path.resolve(PRODUCT_ROOT + './specs.xlsx');
|
||||
const h = html;
|
||||
if (!fs.exists(_path)) {
|
||||
// try global item config (temp, for moulds)
|
||||
debugger;
|
||||
if (global.private && global.private.specs) {
|
||||
data = markdownTable(global.private.specs);
|
||||
return md2html(data);
|
||||
}
|
||||
return '';
|
||||
} else {
|
||||
const t = global;
|
||||
let data = xlsx.parse(_path);
|
||||
data[0].data = data[0].data.filter((d) => !!d.length);
|
||||
data = markdownTable(data[0].data);
|
||||
return html_beautify(md2html(data));
|
||||
}
|
||||
[% endjs -%]
|
||||
89
packages/osr-templates/discourse/root.html
Normal file
89
packages/osr-templates/discourse/root.html
Normal file
@ -0,0 +1,89 @@
|
||||
[%- include "variables.osr" -%]
|
||||
|
||||
[% include "body.md" %]
|
||||
|
||||
[% if config.variables.show.meta -%]
|
||||
[% include "meta.osr" %]
|
||||
[%-endif%]
|
||||
|
||||
|
||||
[%- if show.productDump -%]
|
||||
Product dump:
|
||||
```json
|
||||
[%- js -%]
|
||||
return JSON.stringify(product,null,2)
|
||||
[%endjs-%]
|
||||
```
|
||||
[%endif%]
|
||||
|
||||
[%- if show.productDump -%]
|
||||
Config dump:
|
||||
```json
|
||||
[%-js-%]
|
||||
return JSON.stringify(config,null,2)
|
||||
[%-endjs-%]
|
||||
```
|
||||
[%endif%]
|
||||
|
||||
[wrap="center"]
|
||||
<img src="[[product.preview]]">
|
||||
[/wrap]
|
||||
|
||||
[%- include "overview_drawings.osr" -%]
|
||||
|
||||
[%- if product.hasSpecs -%]
|
||||
## Specification
|
||||
[% include "product_specs.osr" html:true %]
|
||||
|
||||
[Source : [[variables.OSR_FILES_WEB]]/[[product.product_rel]]/specs.xlsx]([[variables.OSR_FILES_WEB]]/[[product.product_rel]]/specs.xlsx)
|
||||
|
||||
[%endif-%]
|
||||
|
||||
[% if show.authors -%]
|
||||
[%- if product.authors -%]
|
||||
[% include "authors.osr" authors:product.authors showHeader:true %]
|
||||
[%-endif-%]
|
||||
[%-endif-%]
|
||||
|
||||
[% if show.issues -%]
|
||||
[%- if product.issues -%]
|
||||
[% include "issues.osr" %]
|
||||
[%-endif-%]
|
||||
[%-endif-%]
|
||||
|
||||
[% if show.alternatives -%]
|
||||
[%- if product.alternatives -%]
|
||||
#### Alternatives
|
||||
[% include "alternatives.osr" %]
|
||||
[%-endif-%]
|
||||
[%-endif-%]
|
||||
|
||||
[% if show.replacedBy -%]
|
||||
[%- if product.replacedBy -%]
|
||||
#### Replaced by
|
||||
[% include "replacedBy.osr" %]
|
||||
[%-endif-%]
|
||||
[%-endif-%]
|
||||
|
||||
[% if show.marketplaceLinks -%]
|
||||
[%- if product.marketplaceLinks -%]
|
||||
#### Marketplace
|
||||
[% include "marketplaceLinks.osr" %]
|
||||
[%-endif-%]
|
||||
[%-endif-%]
|
||||
|
||||
|
||||
[% include "product_resources.osr" %]
|
||||
|
||||
[% if show.howtos %]
|
||||
[% include "product_howtos.osr" %]
|
||||
[%endif%]
|
||||
|
||||
[% if show.debug %]
|
||||
[% include "product_debug.osr" %]
|
||||
[%endif%]
|
||||
|
||||
|
||||
[%js%]
|
||||
|
||||
[%endjs%]
|
||||
43
packages/osr-templates/discourse/root_bak.html
Normal file
43
packages/osr-templates/discourse/root_bak.html
Normal file
@ -0,0 +1,43 @@
|
||||
[% include "product_variables.osr" %]
|
||||
|
||||
<span><b>[[product.product_name]]</b></span>
|
||||
|
||||
[% include "header_notice.osr" %]
|
||||
|
||||
[% include "body.md" %]
|
||||
|
||||
<div style="clear:both">
|
||||
[% include "product_overview_drawings.osr" %]
|
||||
</div>
|
||||
|
||||
<div style="padding:16px;text-align: center;">
|
||||
<div class="ty-vendor-plans">
|
||||
<div class="ty-grid-list__item" style="float: left;border: 1px gray;">
|
||||
<h4 id="authors">Specification</h4>
|
||||
[% include "product_specs.osr" html:true %]
|
||||
</div>
|
||||
|
||||
<div class="ty-grid-list__item" style="float: left;text-align: left;border: 1px gray;">
|
||||
[% if config.show.authors %]
|
||||
[% include "authors_html.osr" authors:product.authors showHeader:true %]
|
||||
[%endif%]
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
[% include "product_resources.osr" %]
|
||||
|
||||
[% include "product_showreel.osr" %]
|
||||
|
||||
[% if config.show.howtos %]
|
||||
[% include "product_howtos.osr" %]
|
||||
[%endif%]
|
||||
|
||||
[% if config.show.debug %]
|
||||
[% include "product_debug.osr" %]
|
||||
[%endif%]
|
||||
|
||||
|
||||
[%js%]
|
||||
|
||||
[%endjs%]
|
||||
55
packages/osr-templates/discourse/social_links.osr
Normal file
55
packages/osr-templates/discourse/social_links.osr
Normal file
@ -0,0 +1,55 @@
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<a href="[[config.vendor_instagram]]">
|
||||
<img width="30px"
|
||||
src="[[abs_url]]/assets/icons/instagram-logo.png" />
|
||||
</a>
|
||||
</td>
|
||||
<td>
|
||||
<a href="[[config.vendor_youtube]]">
|
||||
<img width="30px"
|
||||
src="[[abs_url]]/assets/icons/002-youtube.png" />
|
||||
</a>
|
||||
</td>
|
||||
<td>
|
||||
<a alt="Open Source Projects" href="[[config.vendor_github]]">
|
||||
<img width="30px"
|
||||
src="[[abs_url]]/assets/icons/github.png" />
|
||||
</a>
|
||||
</td>
|
||||
<td>
|
||||
<a alt="" href="[[config.vendor_whatsapp]]">
|
||||
<img width="30px"
|
||||
src="[[abs_url]]/assets/icons/007-whatsapp.png" />
|
||||
</a>
|
||||
</td>
|
||||
<td>
|
||||
<a alt="" href="[[config.vendor_facebook]]">
|
||||
<img width="30px"
|
||||
src="[[abs_url]]/assets/icons/043-facebook-1.png" />
|
||||
</a>
|
||||
</td>
|
||||
<td>
|
||||
<a alt="" href="[[config.vendor_contact_email]]">
|
||||
<img width="30px"
|
||||
src="[[abs_url]]/assets/icons/012-mail-2.png" />
|
||||
</a>
|
||||
</td>
|
||||
<td>
|
||||
<a alt="" href="[[config.vendor_blog]]">
|
||||
<img width="30px"
|
||||
src="[[abs_url]]/assets/icons/006-wordpress.png" />
|
||||
</a>
|
||||
</td>
|
||||
<td>
|
||||
<a alt="" href="[[config.vendor_discord]]">
|
||||
<img width="30px"
|
||||
src="[[abs_url]]/assets/icons/discord.png" />
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
||||
</table>
|
||||
62
packages/osr-templates/discourse/variables.osr
Normal file
62
packages/osr-templates/discourse/variables.osr
Normal file
@ -0,0 +1,62 @@
|
||||
[% capture config %][% js %]
|
||||
const globalVariables = readJSON('${OSR_ROOT}/osr-templates/discourse/base.json');
|
||||
addGlobal({config:globalVariables})
|
||||
addGlobal({config:globalVariables.variables})
|
||||
|
||||
register('config',globalVariables.variables)
|
||||
register('variables',globalVariables.variables)
|
||||
register('show',globalVariables.variables.show)
|
||||
|
||||
return globalVariables
|
||||
[%endjs%][% endcapture -%]
|
||||
[% capture product %][% js %]
|
||||
const globalVariables = readJSON('${OSR_ROOT}/osr-templates/discourse/base.json')
|
||||
let localVariables = readJSON('${PRODUCT_ROOT}/config.json')
|
||||
|
||||
delete localVariables['download']
|
||||
delete localVariables['product_dimensions']
|
||||
delete localVariables['edrawings']
|
||||
|
||||
localVariables['image']='${product_rel}/renderings/perspective.jpg'
|
||||
|
||||
let defaultsJSON = fs.findUp.sync('defaults.json', {
|
||||
cwd:PRODUCT_ROOT,
|
||||
stopAt:root
|
||||
});
|
||||
|
||||
if(defaultsJSON){
|
||||
defaultsJSON = readJSON(defaultsJSON);
|
||||
localVariables = {
|
||||
...defaultsJSON,
|
||||
...localVariables
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let allVariables = {
|
||||
...globalVariables.variables,
|
||||
...localVariables,
|
||||
...scope
|
||||
}
|
||||
|
||||
const _scope = scope
|
||||
|
||||
allVariables.product_rel = product;
|
||||
|
||||
writeJSON("./tmp.json",allVariables)
|
||||
const allStr = read("./tmp.json")
|
||||
|
||||
let all = forward_slash(substitute(allStr,allVariables))
|
||||
write("./tmp-a.json",forward_slash(all))
|
||||
|
||||
try{
|
||||
allVariables = JSON.parse(all);
|
||||
resolveConfig(allVariables);
|
||||
addGlobal({product:allVariables});
|
||||
register('product',allVariables)
|
||||
return allVariables;
|
||||
}catch(e){
|
||||
debugger
|
||||
}
|
||||
|
||||
[%endjs%][% endcapture -%]
|
||||
22
packages/osr-templates/discourse/vendor_instagram.osr
Normal file
22
packages/osr-templates/discourse/vendor_instagram.osr
Normal file
@ -0,0 +1,22 @@
|
||||
<h4 style="text-align:center"> Our latest Instagram posts </h4>
|
||||
|
||||
[%js%]
|
||||
|
||||
return cacache.get.info(CACHE, 'vendor-instagram').then((cache)=>{
|
||||
if(cache){
|
||||
return cacache.get(CACHE, 'vendor-instagram').then((cached)=>{
|
||||
return cached.data.toString();
|
||||
})
|
||||
}
|
||||
console.log('get instagram images');
|
||||
return instagram.images(config.instagram.user,config.instagram.token,global).then((images)=>{
|
||||
images = images.slice(0, 8);
|
||||
images = html.container.wrap(images.map((i)=> html.container.item(html.image(i,null,'max-height:200px'),'border:none; width:200px;max-height:200px')).join('\n'));
|
||||
return cacache.put(CACHE,'vendor-instagram',images).then(()=>{
|
||||
return images;
|
||||
})
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
[%endjs%]
|
||||
2
packages/osr-templates/discourse/widgets/authors.osr
Normal file
2
packages/osr-templates/discourse/widgets/authors.osr
Normal file
@ -0,0 +1,2 @@
|
||||
## Authors2
|
||||
[%- for author in authors -%] - [ [[-author.name]] ]( [[author.url-]] ) [%- endfor -%]
|
||||
@ -0,0 +1,2 @@
|
||||
[%- if showHeader -%]<h4 id="authors">Authors</h4>[%- endif -%]
|
||||
<ul>[% for author in authors -%]<li><a href="[[author.url]]">[[author.name]]</a></li>[%- endfor %]</ul>
|
||||
16
packages/osr-templates/discourse/widgets/cam_html.osr
Normal file
16
packages/osr-templates/discourse/widgets/cam_html.osr
Normal file
@ -0,0 +1,16 @@
|
||||
|
||||
[%if product.production %]
|
||||
<div>
|
||||
[%- if product.production.cam -%]
|
||||
<h4>CAM Files</h4>
|
||||
[%if product.production.fusion-folder -%]
|
||||
<a href="[[product.production.fusion-folder]]"><p>Fusion Folder</p></a>
|
||||
[%- endif -%]
|
||||
<ul>
|
||||
[%- for cam in product.production.cam -%]
|
||||
<li><a href="[[cam.url]]">[[cam.name]]</a></li>
|
||||
[%- endfor -%]
|
||||
</ul>
|
||||
[% endif %]
|
||||
</div>
|
||||
[% endif -%]
|
||||
0
packages/osr-templates/discourse/widgets/issues.osr
Normal file
0
packages/osr-templates/discourse/widgets/issues.osr
Normal file
10
packages/osr-templates/discourse/widgets/meta.osr
Normal file
10
packages/osr-templates/discourse/widgets/meta.osr
Normal file
@ -0,0 +1,10 @@
|
||||
[%- if product.status or product.version -%]
|
||||
#### Brief
|
||||
[%-endif%]
|
||||
[%- if product.status -%]
|
||||
- **Status**: [[product.status]]
|
||||
[%-endif-%]
|
||||
[%- if product.version -%]
|
||||
- **Version**: [[product.version]]
|
||||
[%-endif-%]
|
||||
- [**Last Change**]([[variables.GIT_REPO]]/commit/[[GIT_COMMIT]]) : [[GIT_LAST]] by [ [[GIT_AUTHOR]] ]([[variables.GIT_REPO]]/[[GIT_AUTHOR]]) - ```[[GIT_MESSAGE]]```
|
||||
119
packages/osr-templates/email/mosaico/package.json
Normal file
119
packages/osr-templates/email/mosaico/package.json
Normal file
@ -0,0 +1,119 @@
|
||||
{
|
||||
"name": "@plastichub/email-mosaic",
|
||||
"description": "Liquid based markup language",
|
||||
"version": "0.5.4",
|
||||
"typings": "index.d.ts",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"bin": {
|
||||
"osrl": "main.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@elastic/elasticsearch": "^7.13.0",
|
||||
"@google-cloud/local-auth": "^2.1.0",
|
||||
"@iarna/toml": "^2.2.5",
|
||||
"@plastichub/core": "^0.2.6",
|
||||
"@plastichub/fs": "^0.13.39",
|
||||
"@plastichub/osr-cache": "^0.3.9",
|
||||
"@plastichub/osr-vcs": "^0.0.3",
|
||||
"@types/cacache": "^15.0.1",
|
||||
"@types/download": "^8.0.1",
|
||||
"@types/get-stdin": "^7.0.0",
|
||||
"@types/inquirer": "^7.3.3",
|
||||
"@types/is-glob": "^4.0.2",
|
||||
"@types/js-beautify": "^1.13.2",
|
||||
"@types/jsonpath": "^0.2.0",
|
||||
"@types/moment": "^2.13.0",
|
||||
"@types/node": "^20.14.2",
|
||||
"@types/yargs": "^17.0.2",
|
||||
"axios": "^0.21.1",
|
||||
"bluebird": "^3.7.2",
|
||||
"cacache": "^15.2.0",
|
||||
"chalk": "^2.4.1",
|
||||
"cheerio": "^1.0.0-rc.10",
|
||||
"convert-units": "^2.3.4",
|
||||
"download": "^8.0.0",
|
||||
"env-var": "^7.3.0",
|
||||
"errlop": "^4.5.0",
|
||||
"exception-formatter": "^2.1.2",
|
||||
"fast-glob": "^3.2.7",
|
||||
"find-up": "4.0",
|
||||
"front-matter": "^4.0.2",
|
||||
"get-stdin": "^9.0.0",
|
||||
"gitea-js": "^1.20.1",
|
||||
"glob-base": "^0.3.0",
|
||||
"googleapis": "^105.0.0",
|
||||
"gray-matter": "^4.0.3",
|
||||
"grunt": "^1.6.1",
|
||||
"grunt-cli": "^1.4.3",
|
||||
"grunt-contrib-clean": "^2.0.0",
|
||||
"grunt-extend-config": "^0.9.7",
|
||||
"grunt-parallel": "^0.5.1",
|
||||
"grunt-shell": "^3.0.1",
|
||||
"highlight.js": "^11.1.0",
|
||||
"inquirer": "^8.1.2",
|
||||
"is-glob": "^4.0.1",
|
||||
"is-url": "^1.2.4",
|
||||
"isomorphic-unfetch": "^3.1.0",
|
||||
"js-base64": "^3.7.2",
|
||||
"js-beautify": "^1.14.0",
|
||||
"jsdom": "^16.7.0",
|
||||
"jsome": "^2.3.24",
|
||||
"json-format-highlight": "^1.0.4",
|
||||
"json-pretty-html": "^1.1.6",
|
||||
"json-to-pretty-yaml": "^1.2.2",
|
||||
"jsonpath": "^1.1.1",
|
||||
"keyv": "^4.5.4",
|
||||
"keyv-file": "^0.3.1",
|
||||
"lodash": "^4.17.21",
|
||||
"markdown-table": "^3.0.3",
|
||||
"moment": "^2.29.1",
|
||||
"native-promise-pool": "^3.19.0",
|
||||
"node-xlsx": "^0.24.0",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"open-graph-scraper": "^5.0.5",
|
||||
"ora": "^1.3.0",
|
||||
"parse-glob": "^3.0.4",
|
||||
"pretty": "^2.0.0",
|
||||
"query-string": "^7.1.3",
|
||||
"readline": "^1.3.0",
|
||||
"require-like": "^0.1.2",
|
||||
"rotating-file-stream": "^3.2.3",
|
||||
"sharp": "^0.33.4",
|
||||
"showdown": "^1.9.1",
|
||||
"typescript": "^4.9.4",
|
||||
"uri-js": "^4.4.1",
|
||||
"yaml": "^2.4.2",
|
||||
"yargs": "^14.2.3",
|
||||
"yargs-parser": "^15.0.3"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "tsc; mocha --full-trace mocha \"spec/**/*.spec.js\"",
|
||||
"test-with-coverage": "istanbul cover node_modules/.bin/_mocha -- 'spec/**/*.spec.js'",
|
||||
"lint": "tslint --project=./tsconfig.json",
|
||||
"build": "tsc -p . --declaration",
|
||||
"dev": "tsc -p . --declaration -w",
|
||||
"dev-grunt": "cd tasks && tsc -p . --declaration -w",
|
||||
"typings": "tsc --declaration",
|
||||
"docs": "npx typedoc src/index.ts",
|
||||
"dev-test-watch": "mocha-typescript-watch",
|
||||
"init:google-sheets": "node ./main.js init google-sheets --sheet='1oVEiGH4o3SV-mAA3Mb-WNVJMyYl4VMxLjWjrSw_ipJY' --range='Parts!B4:B5'"
|
||||
},
|
||||
"homepage": "https://git.osr-plastic.org/plastichub/lib-content",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://git.osr-plastic.org/plastichub/lib-content.git"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 8.0.0"
|
||||
},
|
||||
"license": "BSD-3-Clause",
|
||||
"keywords": [
|
||||
"typescript"
|
||||
],
|
||||
"pre-commit": [],
|
||||
"optionalDependencies": {
|
||||
"@img/sharp-win32-x64": "^0.33.4"
|
||||
}
|
||||
}
|
||||
5
packages/osr-templates/email/mosaico/readme.md
Normal file
5
packages/osr-templates/email/mosaico/readme.md
Normal file
@ -0,0 +1,5 @@
|
||||
## HTML EMail - Templates
|
||||
|
||||
### References
|
||||
|
||||
- [mosaico](https://mosaico.io/)
|
||||
96
packages/osr-templates/osrl/.osrl.json
Normal file
96
packages/osr-templates/osrl/.osrl.json
Normal file
@ -0,0 +1,96 @@
|
||||
{
|
||||
"includes": [
|
||||
"${root}/src/data/",
|
||||
"${PRODUCT_ROOT}",
|
||||
"${PRODUCT_ROOT}/templates/site/",
|
||||
"${PRODUCT_ROOT}/templates/shared/",
|
||||
"${OSR_ROOT}/products/company/campaign/widgets",
|
||||
"${OSR_ROOT}/products/company/campaign/content",
|
||||
"${OSR_ROOT}/products/company/campaign/data",
|
||||
"${OSR_ROOT}/products/company/commons",
|
||||
"${OSR_ROOT}/products/company/commons/widgets",
|
||||
"${OSR_ROOT}/osr-templates/osrl/widgets",
|
||||
"${root}/osr",
|
||||
"${root}/osr/widgets",
|
||||
"${root}/_includes",
|
||||
"${root}/templates/site/"
|
||||
],
|
||||
"variables": {
|
||||
"PRODUCT_ROOT": "${root}/${product}/",
|
||||
"abs_url": "https://assets.osr-plastic.org",
|
||||
"CACHE": "${root}/cache/",
|
||||
"CACHE_URL": "${abs_url}/cache/",
|
||||
"GIT_REPO": "https://git.polymech.io/",
|
||||
"_OSR_MACHINES_ASSETS_URL":"https://assets.osr-plastic.org/machines/",
|
||||
"OSR_MACHINES_ASSETS_URL":"https://assets.osr-plastic.org",
|
||||
"PRODUCTS_ASSETS_URL":"https://assets.osr-plastic.org/machines/${product}",
|
||||
"OSR_FILES_WEB":"https://files.polymech.io/files/machines",
|
||||
"PRODUCTS_FILES_URL":"${OSR_FILES_WEB}/${product_rel}",
|
||||
"DISCORD":"https://discord.gg/s8K7yKwBRc"
|
||||
},
|
||||
"env": {
|
||||
"bazar":{
|
||||
"includes": [
|
||||
"${PRODUCT_ROOT}/templates/bazar",
|
||||
"${PRODUCT_ROOT}/templates/shared/",
|
||||
"${root}/osr",
|
||||
"${root}/osr/widgets",
|
||||
"${PRODUCT_ROOT}"
|
||||
],
|
||||
"variables": {
|
||||
"abs_url": "https://dev.osr-plastic.org/"
|
||||
}
|
||||
},
|
||||
"bazar-release":{
|
||||
"includes": [
|
||||
"${PRODUCT_ROOT}/templates/bazar",
|
||||
"${PRODUCT_ROOT}/templates/shared/",
|
||||
"${root}/osr",
|
||||
"${root}/osr/widgets",
|
||||
"${PRODUCT_ROOT}"
|
||||
],
|
||||
"variables": {
|
||||
"abs_url": "https://plastic-hub.com/",
|
||||
"OSR_MACHINES_ASSETS_URL":"https://assets.osr-plastic.org/machines/"
|
||||
}
|
||||
},
|
||||
"hugo-release":{
|
||||
"includes": [
|
||||
"${PRODUCT_ROOT}/templates/bazar",
|
||||
"${PRODUCT_ROOT}/templates/shared/",
|
||||
"${root}/osr",
|
||||
"${root}/osr/widgets",
|
||||
"${PRODUCT_ROOT}",
|
||||
"${OSR_ROOT}/osr-templates/osrl/widgets"
|
||||
],
|
||||
"variables": {
|
||||
"abs_url": "https://plastic-hub.com/",
|
||||
"OSR_MACHINES_ASSETS_URL":"https://assets.osr-plastic.org/machines/"
|
||||
}
|
||||
},
|
||||
"hugo-debug":{
|
||||
"includes": [
|
||||
"${PRODUCT_ROOT}/templates/bazar",
|
||||
"${PRODUCT_ROOT}/templates/shared/",
|
||||
"${root}/osr",
|
||||
"${root}/osr/widgets",
|
||||
"${PRODUCT_ROOT}",
|
||||
"${OSR_ROOT}/osr-templates/osrl/widgets"
|
||||
],
|
||||
"variables": {
|
||||
"abs_url": "https://plastic-hub.com/",
|
||||
"OSR_MACHINES_ASSETS_URL":"https://assets.osr-plastic.org",
|
||||
"showCart": false,
|
||||
"showPrice": false,
|
||||
"showResources": false,
|
||||
"showShipping": false,
|
||||
"showPaymentTerms": false,
|
||||
"showHowtos": false,
|
||||
"showRenderings": true,
|
||||
"debug": true
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user