diff --git a/eslint.config.js b/eslint.config.js index 7beb01c..00359a8 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -1,6 +1,6 @@ -const arc = require('@architect/eslint-config') +import arc from '@architect/eslint-config' -module.exports = [ +const config = [ ...arc, { ignores: [ @@ -12,5 +12,10 @@ module.exports = [ 'src/http/get-index', 'types/', ], + languageOptions: { + sourceType: 'module', + }, }, ] + +export default config diff --git a/package.json b/package.json index 0b1a62e..641fb81 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "0.1.2", "description": "TypeScript workflow integration for Enhance", "main": "src/index.js", + "type": "module", "scripts": { "lint": "eslint . --fix", "test": "npm run lint" diff --git a/src/cli.js b/src/cli.js index ff4478a..6f5a0e1 100644 --- a/src/cli.js +++ b/src/cli.js @@ -1,10 +1,10 @@ -const { spawn } = require('child_process') +import { spawn } from 'child_process' /** * Spawns the TypeScript Compiler in watcher mode, for use during local development. * Returns the process handle. */ -exports.startWatcher = function startTypeScriptCompiler (inputPath, outputPath, options = {}) { +function startWatcher (inputPath, outputPath, options = {}) { const { update } = options const watcherProcess = spawn( 'npx', @@ -22,3 +22,5 @@ exports.startWatcher = function startTypeScriptCompiler (inputPath, outputPath, }) return watcherProcess } + +export { startWatcher } diff --git a/src/index.js b/src/index.js index 7dcbe54..d5b44df 100644 --- a/src/index.js +++ b/src/index.js @@ -1,39 +1,40 @@ -const { updater } = require('@architect/utils') -const { join } = require('path') -const tsc = require('./cli') -const utils = require('./utils') +import { updater } from '@architect/utils' +import { join } from 'path' +import { startWatcher } from './cli.js' +import { copyProject, copyFile } from './utils.js' let watcherProcess const update = updater('TypeScriptCompiler') -module.exports = { - deploy: { - start: async () => { - // copy initial project files - utils.copyProject() - }, +const deploy = { + start: async () => { + // copy initial project files + copyProject() }, - sandbox: { - start: async () => { - // copy initial project files - utils.copyProject() - // start tsc watcher - update.start('Starting watcher...') - watcherProcess = await tsc.startWatcher() - update.done('Started watcher') - }, - end: () => { - update.start('Stopping watcher...') - watcherProcess.kill() - update.done('Stopped watcher') - }, - watcher: async function (params) { - let { filename, /* event, */ inventory } = params - let tsDir = join(inventory.inv._project.cwd, 'ts') - if (filename.startsWith(tsDir) && !filename.endsWith('.ts') && !filename.endsWith('.tsx') && !filename.endsWith('.mts')) { - utils.copyFile(filename) - update.done(`${filename} updated`) - } - }, +} + +const sandbox = { + start: async () => { + // copy initial project files + copyProject() + // start tsc watcher + update.start('Starting watcher...') + watcherProcess = await startWatcher() + update.done('Started watcher') + }, + end: () => { + update.start('Stopping watcher...') + watcherProcess.kill() + update.done('Stopped watcher') + }, + watcher: async function (params) { + let { filename, /* event, */ inventory } = params + let tsDir = join(inventory.inv._project.cwd, 'ts') + if (filename.startsWith(tsDir) && !filename.endsWith('.ts') && !filename.endsWith('.tsx') && !filename.endsWith('.mts')) { + copyFile(filename) + update.done(`${filename} updated`) + } }, } + +export { deploy, sandbox } diff --git a/src/utils.js b/src/utils.js index dfbfc24..ef66cdc 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1,17 +1,17 @@ -const { copyFileSync, mkdirSync, statSync } = require('fs') -const { globSync } = require('glob') +import { copyFileSync, mkdirSync, statSync } from 'fs' +import { globSync } from 'glob' const SRC_DIR = 'ts' const DEST_DIR = 'app' -function copyAllFiles () { - const files = [ 'ts', ...globSync('ts/**/*', { 'ignore': [ 'ts/**/*.mts', 'ts/**/*.ts', 'ts/**/*.tsx' ] }) ] +function copyProject () { + const files = globSync('ts/**/*', { 'ignore': [ 'ts/**/*.mts', 'ts/**/*.ts', 'ts/**/*.tsx' ] }) files.forEach((srcPath) => { - copyOneFile(srcPath) + copyFile(srcPath) }) } -function copyOneFile (srcPath) { +function copyFile (srcPath) { const destPath = srcPath.replace(SRC_DIR, DEST_DIR) const stats = statSync(srcPath) if (stats.isDirectory()) { @@ -22,5 +22,4 @@ function copyOneFile (srcPath) { } } -exports.copyProject = copyAllFiles -exports.copyFile = copyOneFile +export { copyProject, copyFile }