80 lines
2.6 KiB
TypeScript
80 lines
2.6 KiB
TypeScript
import * as path from 'path'
|
|
import { sync as cp } from '@plastichub/fs/copy'
|
|
import { sync as exists } from '@plastichub/fs/exists'
|
|
import { sync as rm } from '@plastichub/fs/remove'
|
|
|
|
import { logger } from './'
|
|
|
|
const HTML_DEFAULT_PATH = 'resources/edrawings.html'
|
|
|
|
const debug = true
|
|
const verbose = true
|
|
|
|
|
|
export const productAllTask = (grunt, product, options: any = {}, product_tasks) => {
|
|
const slug = path.parse(product).base
|
|
grunt.registerTask(`product-${slug}`, `laser:product-${slug}`)
|
|
product_tasks.push(`laser:product-${slug}`)
|
|
grunt.registerTask(`products-laser`, product_tasks)
|
|
}
|
|
|
|
export const productLaserTask = (grunt, product, options: any = {}, product_laser_tasks) => {
|
|
const config = {}
|
|
const slug = path.parse(product).base
|
|
|
|
config[`product-${slug}`] = {
|
|
src: [product],
|
|
options: {
|
|
clear: true,
|
|
debug: true,
|
|
verbose
|
|
}
|
|
}
|
|
grunt.extendConfig({
|
|
laser: config
|
|
})
|
|
grunt.registerTask(`product-${slug}`, `laser:product-${slug}`)
|
|
|
|
product_laser_tasks.push(`laser:product-${slug}`)
|
|
|
|
grunt.registerTask(`products-laser`, product_laser_tasks)
|
|
}
|
|
|
|
export const productCADTask = (grunt, product, options: any = {}, product_cad_tasks) => {
|
|
const config = {}
|
|
const slug = path.parse(product).base
|
|
|
|
product = path.resolve(path.join(process.cwd(), product))
|
|
config[`product-${slug}`] = {
|
|
src: [`${product}/cad*/*Global*.+(SLDASM)`],
|
|
output: '${SRC_DIR}/${SRC_NAME}.+(json|html|step|x_t)',
|
|
options: {
|
|
debug,
|
|
verbose,
|
|
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) {
|
|
if (exists(path.join(product, HTML_DEFAULT_PATH))) {
|
|
rm(path.join(product, HTML_DEFAULT_PATH))
|
|
}
|
|
cp(data.target, path.join(product, HTML_DEFAULT_PATH), {})
|
|
}
|
|
} catch (error) {
|
|
logger.error(`Error copying ${data.src} to ${HTML_DEFAULT_PATH}`, error)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
grunt.extendConfig({
|
|
cad: config
|
|
})
|
|
grunt.registerTask(`product-${slug}`, `cad:product-${slug}`)
|
|
|
|
product_cad_tasks.push(`cad:product-${slug}`)
|
|
|
|
grunt.registerTask(`products-cad`, product_cad_tasks)
|
|
}
|