scripts & tasks

This commit is contained in:
lovebird 2024-07-16 21:34:34 +02:00
parent d42037e4c1
commit 03ba1eee57
13 changed files with 455 additions and 25 deletions

View File

@ -1,48 +1,44 @@
{
"name": "@plastichub/pp-next",
"name": "osr-machines",
"version": "0.1.0",
"description": "creates templates - picked up later a form generator and some backend",
"main": "index.js",
"scripts": {
"dev-grunt": "tsc -p . -w",
"test": "echo \"Error: no test specified\" && exit 1",
"serve": "bundle exec jekyll serve --trace --port 8008 --incremental",
"dev": "bundle exec jekyll serve --config=_config.dev.yml --trace --port 8008 --incremental",
"dev-machines": "bundle exec jekyll serve --config=_config.dev.machines.yml --trace --port 8008 --incremental",
"dev-howtos": "bundle exec jekyll serve --config=_config.dev.howtos.yml --trace --port 8008 --incremental",
"build": "bundle exec jekyll build --profile --trace -d ../osr-plastic.org/httpdocs",
"library-release": "grunt library-release --env=library-release",
"build-lib": "bundle exec jekyll build --incremental --config _config-lib.yml --profile --trace -d ../precious-plastic.org/library.precious-plastic.org/",
"archives": "cd scripts && sh make-zips.sh && sh make-v4-zips.sh",
"compile:moulds": "grunt moulds:all --verbose --debug --env=library-release"
"build": "bundle exec jekyll build --profile --trace -d ../plastic-hub.com/",
"build-osr": "bundle exec jekyll build --profile --trace -d ../../osr-plastic.org/dev.osr-plastic.org/",
"archives": "sh scripts/mkArchives.sh"
},
"author": "",
"license": "ISC",
"dependencies": {
"@plastichub/content": "^0.2.8",
"@plastichub/core": "^0.0.19",
"@plastichub/fs": "^0.13.26",
"@plastichub/osr-cad": "^0.4.4",
"@plastichub/osr-sync": "^0.0.27",
"@plastichub/core": "^0.2.6",
"@plastichub/fs": "^0.13.32",
"@plastichub/osr-cache": "^0.4.5",
"@plastichub/osr-cli-commons": "^0.4.3",
"@plastichub/osr-fs-utils": "file:../osr-fs-utils",
"@plastichub/osr-tasks": "^0.5.2",
"@plastichub/osrl": "^0.5.3",
"@types/lodash": "^4.14.148",
"@types/node": "^12.12.8",
"@xblox/fs": "^0.13.19",
"@types/showdown": "^2.0.0",
"bluebird": "^3.7.2",
"cheerio": "^1.0.0-rc.10",
"electron-pdf": "^7.0.0",
"filenamify": "^5.1.0",
"chokidar": "^3.5.3",
"fast-glob": "^3.2.7",
"find-up": "^6.2.0",
"grunt": "^1.4.1",
"grunt-contrib-clean": "^2.0.0",
"grunt-extend-config": "^0.9.7",
"grunt-parallel": "^0.5.1",
"grunt-shell": "^3.0.1",
"jsdom": "^19.0.0",
"js-beautify": "^1.14.7",
"lodash": "^4.17.21",
"puppeteer": "^5.4.0",
"md5": "^2.3.0",
"recursive-merge": "^1.2.1",
"request": "^2.76.0",
"sanitize-filename": "^1.6.3",
"sharp": "^0.30.3",
"simple-git": "^2.6.0",
"uri-js": "^4.4.1"
"showdown": "^2.1.0",
"tslog": "^4.8.2",
"typescript": "^5.1.6"
}
}

View File

@ -0,0 +1,4 @@
osr-cad sw --src='./components/**/*Global*.+(SLDASM|SLDPRT|step)' --dst='${SRC_DIR}/${SRC_NAME}.+(html|step|jpg|x_t)' --logLevel=info
osr-cad sw --src='./extrusion/components/**/*Global*.+(SLDASM|SLDPRT|step)' --dst='${SRC_DIR}/${SRC_NAME}.+(html|step|jpg|x_t)' --logLevel=info
osr-cad sw --src='./injection/components/**/*Global*.+(SLDASM|SLDPRT|step)' --dst='${SRC_DIR}/${SRC_NAME}.+(html|step|jpg|x_t)' --logLevel=info
osr-cad sw --src='./sheetpress/components/**/*Global*.+(SLDASM|SLDPRT|step)' --dst='${SRC_DIR}/${SRC_NAME}.+(html|step|jpg|x_t)' --logLevel=info

View File

@ -0,0 +1,2 @@
osr-cad sw --src='./howtos/**/*.+(SLDASM)' --dst='${SRC_DIR}/${SRC_NAME}.+(x_t)' --verbose --debug --skip
osr-cad sw --src='./howtos/**/*.+(SLDASM|SLDPRT|step)' --dst='${SRC_DIR}/${SRC_NAME}.+(pdf|jpg|html|step)' --verbose --debug --skip

View File

@ -0,0 +1,2 @@
osr-cad sw --src='./$1/**/*.+(SLDASM|SLDPRT)' --dst='${SRC_DIR}/${SRC_NAME}.+(x_t)'
osr-cad sw --src='./$1/**/*.+(SLDASM|SLDPRT|step)' --dst='${SRC_DIR}/${SRC_NAME}.+(pdf|jpg|html|step)'

View File

@ -0,0 +1,2 @@
osr-cad sw --src='./moulds/**/*.+(SLDASM|SLDPRT)' --dst='${SRC_DIR}/${SRC_NAME}.+(x_t)' --verbose --debug --skip
osr-cad sw --src='./moulds/**/*.+(SLDASM|SLDPRT|step)' --dst='${SRC_DIR}/${SRC_NAME}.+(html|step)' --verbose --debug --skip

View File

@ -0,0 +1,2 @@
osr-cad sw --src="./$1/**/*.+(SLDASM)" --dst='${SRC_DIR}/${SRC_NAME}.+(x_t)' --verbose --debug
osr-cad sw --src="./$1/**/*.+(SLDASM)" --dst='${SRC_DIR}/${SRC_NAME}.+(pdf|jpg|html|step)' --verbose --debug

View File

@ -0,0 +1,7 @@
script_dir=$(dirname "$0")
$script_dir/update-dir.sh extrusion
$script_dir/update-dir.sh injection
$script_dir/update-dir.sh shredder
$script_dir/update-dir.sh sheetpress
$script_dir/components/update-meta.sh

98
cad/tasks/Gruntfile.ts Normal file
View File

@ -0,0 +1,98 @@
import * as path from 'path'
import { files, forward_slash } from '@plastichub/osr-cli-commons/glob'
import { IComponentConfig } from '@plastichub/osr-commons/'
import { isValidLibraryComponent, readOSRConfig } from '@plastichub/osr-fs-utils'
import { logger } from './'
import {
productCADTask,
productGitSyncTask
} from './component'
export const grunt = (grunt) => {
grunt.initConfig({
pkg: grunt.file.readJSON("package.json"),
sshexec: {
update: {
debug: true,
verbose: true,
commands: 'sh update-osr.sh'
}
}
})
grunt.loadNpmTasks("grunt-extend-config")
const cad_tasks = []
const git_tasks = []
const items = (category, includeProducts = false) => {
const componentsPath = path.resolve(category)
let components = files(componentsPath, '**/**/config.json') as string[]
// components = components.filter(isValidLibraryComponent)
components = components.filter((c) => {
try {
const config = readOSRConfig(c) as IComponentConfig
if (config) {
if(config.forum ===false){
return false
}
if (!includeProducts) {
return !config.code && !config.cscartId && !config.steps
} else {
}
}
return true
} catch (error) {
logger.error(`Invalid config : ${c}`)
}
})
return components
}
let components =
[
...items('./injection/components',true),
...items('./extrusion/components',true),
...items('./sheetpress/components', true),
...items('./sheetpress/', true),
...items('./shredder',true),
...items('./injection'),
...items('./compression'),
...items('./extrusion')
]
const root = path.resolve('.')
components = components.filter(isValidLibraryComponent)
components = components.map((c) => {
const dir = path.relative(root, path.parse(c).dir)
return forward_slash(dir)
})
const componentTasks = (items) => {
items.forEach((i) => {
productCADTask(grunt, i, {}, cad_tasks),
productGitSyncTask(grunt, i, {}, git_tasks)
})
}
logger.debug(`Registered component tasks for`, components)
componentTasks(components)
grunt.registerTask('components-update', [
'components-cad',
'components-git'
])
grunt.registerTask('default', [
'components-update'
])
require("@plastichub/osr-tasks").initConfig(grunt, {})
}
module.exports = grunt

View File

@ -0,0 +1,97 @@
export interface ICompileOptions {
language: string;
debug: number;
profile: Profile;
output: string;
plugins: string[];
env: string;
cwd: string;
source: string;
variables: PathVariablesClass;
srcInfo: Info;
targetInfo: Info;
pathVariables: PathVariablesClass;
}
export interface PathVariablesClass {
OSR_ROOT: string;
PRODUCT_ROOT: string;
OA_ROOT: string;
KB_ROOT: string;
OSR_CACHE: string;
OSR_LIBRARY_MACHINES: string;
OSR_USER_ASSETS: string;
OSR_PRIVATE: string;
OSR_TEMPLATES: string;
OSR_CONTENT: string;
root: string;
cwd: string;
product: string;
debug: number;
env: string;
SRC_PATH: string;
SRC_DIR: string;
SRC_NAME: string;
SRC_FILE_NAME: string;
SRC_FILE_EXT: string;
SRC_IS_FILE: boolean;
SRC_IS_FOLDER: boolean;
SRC_IS_EXPRESSION: boolean;
SRC_IS_GLOB: boolean;
SRC_FILES: string[];
abs_url: string;
CACHE: string;
CACHE_URL: string;
GIT_REPO: string;
DST_PATH: string;
DST_DIR: string;
DST_NAME: string;
DST_FILE_NAME: string;
DST_FILE_EXT: string;
DST_IS_FILE: boolean;
DST_IS_FOLDER: boolean;
DST_IS_EXPRESSION: boolean;
DST_IS_GLOB: boolean;
DST_FILES: string[];
}
export interface Profile {
includes: string[];
variables: ProfileVariables;
env: Env;
}
export interface Env {
bazar: Bazar;
"bazar-release": Bazar;
}
export interface Bazar {
includes: string[];
variables: BazarVariables;
}
export interface BazarVariables {
abs_url: string;
}
export interface ProfileVariables {
PRODUCT_ROOT: string;
abs_url: string;
CACHE: string;
CACHE_URL: string;
GIT_REPO: string;
}
export interface Info {
PATH: string;
DIR: string;
NAME: string;
FILE_NAME: string;
FILE_EXT: string;
IS_FILE: boolean;
IS_FOLDER: boolean;
IS_EXPRESSION: boolean;
IS_GLOB: boolean;
FILES: string[];
}

140
cad/tasks/component.ts Normal file
View File

@ -0,0 +1,140 @@
import * as path from 'path'
import { resolve } from '@plastichub/osr-cli-commons/fs'
import { files, forward_slash } from '@plastichub/osr-cli-commons/glob'
import { sync as cp } from '@plastichub/fs/copy'
import { sync as rm } from '@plastichub/fs/remove'
import { sync as exists } from '@plastichub/fs/exists'
import {
componentContentOptions as componentContentOptions
} from './library'
import { logger } from './'
const COMPONENT_TEMPLATE = './osr/bazar/root.html'
const debug = true
const verbose = false
let DEFAULT_CAD_OUTPUTS = '${SRC_DIR}/${SRC_NAME}.+(json|html|step|x_t)'
const HTML_DEFAULT_PATH = 'resources/edrawings.html'
export const productLaserTask = (grunt, product, options: any = {}, laser_tasks) => {
const config = {}
const slug = path.parse(product).base
config[`component-${slug}`] = {
src: [product],
options: {
clear: true,
debug,
verbose
}
}
grunt.extendConfig({
laser: config
})
grunt.registerTask(`component-${slug}`, `laser:component-${slug}`)
laser_tasks.push(`laser:component-${slug}`)
grunt.registerTask(`products-laser`, laser_tasks)
}
export const productCADTask = (grunt, component, options: any = {}, cad_tasks) => {
const config = {}
const slug = path.parse(component).base
component = path.resolve(path.join(process.cwd(), component))
const rel = forward_slash(path.relative(path.resolve('.'), component))
let glob = `${rel}/cad/*Global*.+(SLDASM)`
const filesSolidworks = files(path.resolve('.'), glob)
if (!filesSolidworks.length) {
return
}
config[`component-${slug}`] = {
src: [`${component}/cad/*Global*.+(SLDASM)`],
output: DEFAULT_CAD_OUTPUTS,
options: {
debug,
verbose,
skip:true,
onNode: (data => {
try {
options.debug && logger.info(`Converted ${data.src} to ${data.target}`)
const parts = path.parse(data.target)
if (parts.ext === '.html' && parts.name.toLowerCase().indexOf('global') !== -1) {
const target = path.join(component, HTML_DEFAULT_PATH)
if(exists(target)){
rm(target)
}
cp(data.target, target, {})
}
} catch (error) {
logger.info(`Error copying ${data.src} to ${HTML_DEFAULT_PATH}`, error)
}
})
}
}
grunt.extendConfig({
cad: config
})
grunt.registerTask(`component-${slug}`, `cad:component-${slug}`)
cad_tasks.push(`cad:component-${slug}`)
grunt.registerTask(`components-cad`, cad_tasks)
}
export const productBazarTask = (grunt, component, options: any = {}, cscart_tasks) => {
if (!component) {
logger.error('Invalid component')
}
const config = {}
const slug = path.parse(component).base
config[`component-${slug}`] = {
src: [COMPONENT_TEMPLATE],
options: componentContentOptions(component)
}
grunt.extendConfig({
compile: config
})
grunt.registerTask(`component-${slug}`, `compile:component-${slug}`)
cscart_tasks.push(`compile:component-${slug}`)
grunt.registerTask(`products-bazar`, cscart_tasks)
}
export const productGitSyncTask = (grunt, component, options: any = {}, git_tasks) => {
const config = {}
const opts = {
clean: true,
debug,
verbose,
cwd: '${OSR_ROOT}/osr-machines/',
rel: component.replace('products/', '')
}
const slug = path.parse(component).base
config[`component-${slug}`] = opts
grunt.extendConfig({
git: config
})
grunt.registerTask(`git-component-${slug}`, `git:component-${slug}`)
git_tasks.push(`git:component-${slug}`)
grunt.registerTask(`components-git`, git_tasks)
}

1
cad/tasks/constants.ts Normal file
View File

@ -0,0 +1 @@
export const MODULE_NAME = `OSR-Machines`

10
cad/tasks/index.ts Normal file
View File

@ -0,0 +1,10 @@
import { logger as _logger } from '@plastichub/core/debug'
import { MODULE_NAME } from './constants'
export const logger = _logger(MODULE_NAME)
import { substitute as _substitute , substituteAlt as _substituteAlt } from "@plastichub/core/strings"
import { IObjectLiteral } from "@plastichub/core"
export const substitute = (alt:boolean, template:string, vars:IObjectLiteral) => alt ? _substituteAlt(template,vars) : _substitute(template, vars);

69
cad/tasks/library.ts Normal file
View File

@ -0,0 +1,69 @@
import * as path from 'path'
import { files } from '@plastichub/osr-cli-commons/glob'
import { Converter } from 'showdown'
const cheerio = require('cheerio')
export const addAssembly = (item) => `${item}/cad/**/Global*.+(SLDASM)`
export const componentContentOptions = (product) => {
console.log('Create product compile options for ', product)
product = '' + product
const product_rel = product.replace('products/', '')
return {
debug: false,
watch: false,
root: '.',
env: 'bazar-release',
profile: '${root}/.osrl.json',
output: '${product}/bazar/raw.html',
format: 'html',
module: 'plastichub-products',
cwd: path.resolve('.'),
cache: false,
onCompiled: onComponent,
onCompileDone: onComponentCompiled,
variables: {
product,
product_rel,
root: path.resolve('.'),
product_relative: '' + product_rel
}
}
}
export const MainAssembly = (dir) => {
const mains = files(dir, '**/cad/**/*Global*.+(SLDASM)') as string[]
return mains[0];
}
export const file_path_with_ext = (file, ext) => {
const parts = path.parse(file);
return path.join(parts.dir, parts.name + '.' + ext);
}
export const unique_by = (arr, key) => {
return [...new Map(arr.map(item => [item[key], item])).values()]
}
export const onComponent = (src, dst, content) => {
const $ = cheerio.load(content, {
xmlMode: true
});
$('a').each(function () {
$(this).attr("style", "color:#4C74B9");
})
$('table').each(function () {
$(this).attr("style", "display:table;width:auto;margin-left:auto;margin-right:auto");
})
return Promise.resolve($.html())
}
export const onComponentCompiled = (src, dst, options, content) => Promise.resolve()