From 03ba1eee570eee499231c9da9b97487092a11724 Mon Sep 17 00:00:00 2001 From: lovebird Date: Tue, 16 Jul 2024 21:34:34 +0200 Subject: [PATCH] scripts & tasks --- cad/package.json | 46 +++--- cad/scripts/scripts/components/update-meta.sh | 4 + cad/scripts/scripts/howtos/update-meta.sh | 2 + cad/scripts/scripts/machines/update-meta.sh | 2 + cad/scripts/scripts/moulds/update-meta.sh | 2 + cad/scripts/scripts/update-dir.sh | 2 + cad/scripts/scripts/update-machines.sh | 7 + cad/tasks/Gruntfile.ts | 98 ++++++++++++ cad/tasks/compileOptions.ts | 97 ++++++++++++ cad/tasks/component.ts | 140 ++++++++++++++++++ cad/tasks/constants.ts | 1 + cad/tasks/index.ts | 10 ++ cad/tasks/library.ts | 69 +++++++++ 13 files changed, 455 insertions(+), 25 deletions(-) create mode 100644 cad/scripts/scripts/components/update-meta.sh create mode 100644 cad/scripts/scripts/howtos/update-meta.sh create mode 100644 cad/scripts/scripts/machines/update-meta.sh create mode 100644 cad/scripts/scripts/moulds/update-meta.sh create mode 100644 cad/scripts/scripts/update-dir.sh create mode 100644 cad/scripts/scripts/update-machines.sh create mode 100644 cad/tasks/Gruntfile.ts create mode 100644 cad/tasks/compileOptions.ts create mode 100644 cad/tasks/component.ts create mode 100644 cad/tasks/constants.ts create mode 100644 cad/tasks/index.ts create mode 100644 cad/tasks/library.ts diff --git a/cad/package.json b/cad/package.json index acba847..14c30ed 100644 --- a/cad/package.json +++ b/cad/package.json @@ -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" } } diff --git a/cad/scripts/scripts/components/update-meta.sh b/cad/scripts/scripts/components/update-meta.sh new file mode 100644 index 0000000..02e6ed4 --- /dev/null +++ b/cad/scripts/scripts/components/update-meta.sh @@ -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 diff --git a/cad/scripts/scripts/howtos/update-meta.sh b/cad/scripts/scripts/howtos/update-meta.sh new file mode 100644 index 0000000..1abd82e --- /dev/null +++ b/cad/scripts/scripts/howtos/update-meta.sh @@ -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 \ No newline at end of file diff --git a/cad/scripts/scripts/machines/update-meta.sh b/cad/scripts/scripts/machines/update-meta.sh new file mode 100644 index 0000000..7e4bae4 --- /dev/null +++ b/cad/scripts/scripts/machines/update-meta.sh @@ -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)' \ No newline at end of file diff --git a/cad/scripts/scripts/moulds/update-meta.sh b/cad/scripts/scripts/moulds/update-meta.sh new file mode 100644 index 0000000..a90f2c7 --- /dev/null +++ b/cad/scripts/scripts/moulds/update-meta.sh @@ -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 \ No newline at end of file diff --git a/cad/scripts/scripts/update-dir.sh b/cad/scripts/scripts/update-dir.sh new file mode 100644 index 0000000..b5bd573 --- /dev/null +++ b/cad/scripts/scripts/update-dir.sh @@ -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 \ No newline at end of file diff --git a/cad/scripts/scripts/update-machines.sh b/cad/scripts/scripts/update-machines.sh new file mode 100644 index 0000000..023f227 --- /dev/null +++ b/cad/scripts/scripts/update-machines.sh @@ -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 + diff --git a/cad/tasks/Gruntfile.ts b/cad/tasks/Gruntfile.ts new file mode 100644 index 0000000..a5d413d --- /dev/null +++ b/cad/tasks/Gruntfile.ts @@ -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 \ No newline at end of file diff --git a/cad/tasks/compileOptions.ts b/cad/tasks/compileOptions.ts new file mode 100644 index 0000000..707659f --- /dev/null +++ b/cad/tasks/compileOptions.ts @@ -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[]; +} diff --git a/cad/tasks/component.ts b/cad/tasks/component.ts new file mode 100644 index 0000000..ed483df --- /dev/null +++ b/cad/tasks/component.ts @@ -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) + +} \ No newline at end of file diff --git a/cad/tasks/constants.ts b/cad/tasks/constants.ts new file mode 100644 index 0000000..f64e83b --- /dev/null +++ b/cad/tasks/constants.ts @@ -0,0 +1 @@ +export const MODULE_NAME = `OSR-Machines` \ No newline at end of file diff --git a/cad/tasks/index.ts b/cad/tasks/index.ts new file mode 100644 index 0000000..20d109c --- /dev/null +++ b/cad/tasks/index.ts @@ -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); diff --git a/cad/tasks/library.ts b/cad/tasks/library.ts new file mode 100644 index 0000000..f4ce862 --- /dev/null +++ b/cad/tasks/library.ts @@ -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()