From 097326e473619a7969a05de389037534130a2095 Mon Sep 17 00:00:00 2001 From: Sijie Date: Tue, 21 Nov 2023 15:40:21 +0800 Subject: [PATCH] =?UTF-8?q?[Feature]=20=E6=96=B0=E5=A2=9E=20less=20?= =?UTF-8?q?=E7=AD=89=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 + source/internal/file.ts | 125 ++++++++++++++++++++++ source/internal/index.ts | 24 +++++ source/internal/less.ts | 106 +++++++++++++++++++ source/internal/npm.ts | 83 +++++++++++++++ source/{internal.ts => internal/repo.ts} | 127 +++++------------------ source/internal/tsc.ts | 95 +++++++++++++++++ source/task.ts | 4 +- source/utils.ts | 9 +- test/task.spec.js | 61 +++++++++++ test/task/workspace-file/.test.config.js | 15 +++ test/task/workspace-file/run.js | 22 ++++ test/task/workspace-file/test/a-dist/a | 0 test/task/workspace-file/test/b | 0 test/task/workspace-less/.test.config.js | 8 ++ test/task/workspace-less/run.js | 22 ++++ test/task/workspace-less/test 3.less | 0 test/task/workspace-less/test-1.less | 1 + test/task/workspace-less/test-2.less | 1 + 19 files changed, 600 insertions(+), 104 deletions(-) create mode 100644 source/internal/file.ts create mode 100644 source/internal/index.ts create mode 100644 source/internal/less.ts create mode 100644 source/internal/npm.ts rename source/{internal.ts => internal/repo.ts} (71%) create mode 100644 source/internal/tsc.ts create mode 100644 test/task/workspace-file/.test.config.js create mode 100644 test/task/workspace-file/run.js create mode 100644 test/task/workspace-file/test/a-dist/a create mode 100644 test/task/workspace-file/test/b create mode 100644 test/task/workspace-less/.test.config.js create mode 100644 test/task/workspace-less/run.js create mode 100644 test/task/workspace-less/test 3.less create mode 100644 test/task/workspace-less/test-1.less create mode 100644 test/task/workspace-less/test-2.less diff --git a/package.json b/package.json index 859aed9..cbc9df7 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "eslint": "^8.53.0", "eslint-config-airbnb-base": "^15.0.0", "eslint-plugin-prettier": "^5.0.1", + "less": "^4.2.0", "typescript": "^5.2.2" }, "dependencies": { diff --git a/source/internal/file.ts b/source/internal/file.ts new file mode 100644 index 0000000..2813756 --- /dev/null +++ b/source/internal/file.ts @@ -0,0 +1,125 @@ +import { + join, + isAbsolute, + relative, +} from 'node:path'; +import { + existsSync, + statSync, + Stats, + copyFileSync, +} from 'node:fs'; + +import { green, italic } from 'chalk'; + +import { registerTask, Task, TaskState } from '../task'; +import { forEachFiles, makeDir } from '../utils'; + +export type FileConfig = { + source: string; + dist: string; + filter(file: string, stat: Stats): boolean; +}[]; + +export class FileTask extends Task { + static getMaxConcurrent() { + return 1; + } + + getTitle() { + return 'Copy files'; + } + + async execute(workspace: string, configArray: FileConfig): Promise { + let hasError = false; + + for (const config of configArray) { + // 将相对路径转成绝对路径 + const source = isAbsolute(config.source) + ? config.source + : join(workspace, config.source); + const dist = isAbsolute(config.dist) + ? config.dist + : join(workspace, config.dist); + + const dataItem = this.getCache(source); + + // 新的缓存数据 + const newDataItem: { + [key: string]: number; + } = {}; + + // 编译的文件是否有变化 + let changed = false; + const fileArray: { + source: string; + dist: string; + }[] = []; + + // 获取编译的文件列表 + try { + await forEachFiles(source, (file, stat) => { + const relativePath = relative(source, file); + const distFile = join(dist, relativePath); + if (config.filter && !config.filter(file, stat)) { + return; + } + if (stat.isDirectory()) { + return; + } + fileArray.push({ + source: file, + dist: distFile, + }); + }); + + this.print(`${italic(`${config.source} => ${config.dist}`)} Copy files: ${green(fileArray.length)}`); + + fileArray.forEach((item) => { + const stat = statSync(item.source); + const mtime = stat.mtime.getTime(); + if ( + !dataItem[item.source] + || mtime !== dataItem[item.source] + || !existsSync(item.dist) + ) { + changed = true; + } + newDataItem[item.source] = mtime; + }); + } catch (error) { + const err = error as Error; + this.print(err.message); + hasError = true; + } + + // 没有变化 + if (changed === false) { + continue; + } + + // 实际拷贝 + try { + for (const item of fileArray) { + const baseDir = join(item.dist, '..'); + if (!existsSync(baseDir)) { + await makeDir(baseDir); + } + if (existsSync(item.source) && !existsSync(item.dist)) { + copyFileSync(item.source, item.dist); + } + } + + // 有变化的时候,更新缓存 + this.setCache(source, newDataItem); + } catch (error) { + const err = error as Error; + this.print(err.message); + hasError = true; + } + } + + return hasError ? TaskState.error : TaskState.success; + } +} +registerTask('file', FileTask); diff --git a/source/internal/index.ts b/source/internal/index.ts new file mode 100644 index 0000000..ae6a9bd --- /dev/null +++ b/source/internal/index.ts @@ -0,0 +1,24 @@ +import { TscConfig, TscTask } from './tsc'; +import { RepoConfig, RepoTask } from './repo'; +import { LessConfig, LessTask } from './less'; +import { FileConfig, FileTask } from './file'; + +/** + * 任务配置 + */ +export type ConfigType = { + tsc: TscConfig, + repo: RepoConfig, + less: LessConfig, + file: FileConfig, +}; + +/** + * 任务列表 + */ +export const Task = { + tsc: TscTask, + repo: RepoTask, + less: LessTask, + file: FileTask, +}; diff --git a/source/internal/less.ts b/source/internal/less.ts new file mode 100644 index 0000000..0d32fcd --- /dev/null +++ b/source/internal/less.ts @@ -0,0 +1,106 @@ +import { + join, isAbsolute, +} from 'node:path'; +import { + existsSync, + statSync, +} from 'node:fs'; +import { cpus } from 'node:os'; + +import { green, italic } from 'chalk'; + +import { registerTask, Task, TaskState } from '../task'; +import { bash } from '../utils'; + +export type LessConfig = { + source: string; + dist: string; + compress: boolean; +}[]; + +export class LessTask extends Task { + static getMaxConcurrent() { + return cpus().length; + } + + getTitle() { + return 'Compile with less'; + } + + async execute(workspace: string, configArray: LessConfig): Promise { + let hasError = false; + + for (const config of configArray) { + // 将相对路径转成绝对路径 + const path = isAbsolute(config.source) ? config.source : join(workspace, config.source); + + const dataItem = this.getCache(path); + + // 新的缓存数据 + const newDataItem: { + [key: string]: number; + } = {}; + + // 编译的文件是否有变化 + let changed = false; + + // 获取编译的文件列表 + try { + const fileArray: string[] = [ + path, + ]; + const out = './.less.cache.json'; + await bash('npx', ['lessc', '--depends', config.source, out], { + cwd: workspace, + }, (data) => { + let str = data.toString(); + if (str.startsWith(out)) { + str = str.substring(out.length + 2); + } + str.split(/\.less /).forEach((fileWithoutExt) => { + const file = `${fileWithoutExt}.less`; + if (existsSync(file)) { + fileArray.push(file); + } + }); + }); + this.print(`${italic(config.source)} Compile files: ${green(fileArray.length)}`); + + fileArray.forEach((file) => { + const stat = statSync(file); + const mtime = stat.mtime.getTime(); + if (!dataItem[file] || mtime !== dataItem[file]) { + changed = true; + } + newDataItem[file] = mtime; + }); + } catch (error) { + const err = error as Error; + this.print(err.message); + hasError = true; + } + + // 没有变化 + if (changed === false) { + continue; + } + + // 实际编译 + try { + await bash('npx', ['lessc', config.source, config.dist], { + cwd: workspace, + }); + + // 有变化的时候,更新缓存 + this.setCache(path, newDataItem); + } catch (error) { + const err = error as Error; + this.print(err.message); + hasError = true; + } + } + + return hasError ? TaskState.error : TaskState.success; + } +} +registerTask('less', LessTask); diff --git a/source/internal/npm.ts b/source/internal/npm.ts new file mode 100644 index 0000000..893da1e --- /dev/null +++ b/source/internal/npm.ts @@ -0,0 +1,83 @@ +import { + join, + isAbsolute, +} from 'node:path'; +import { + createWriteStream, + WriteStream, +} from 'node:fs'; + +import { italic } from 'chalk'; + +import { registerTask, Task, TaskState } from '../task'; +import { bash } from '../utils'; + +export type NPMConfig = { + // 安装的时候输出的信息 + message: string; + // 执行 NPM 命令的路径 + path: string; + // 执行的参数 + params: string[], + // 错误的时候输出的信息 + detail: string; + // 存放日志的路径,当没有设置的时候,会将日志输出到控制台 + logFile?: string, +}[]; + +export class FileTask extends Task { + static getMaxConcurrent() { + return 1; + } + + getTitle() { + return 'Run npm command'; + } + + async execute(workspace: string, configArray: NPMConfig): Promise { + let hasError = false; + + for (const config of configArray) { + // 将相对路径转成绝对路径 + const source = isAbsolute(config.path) + ? config.path + : join(workspace, config.path); + + this.print(italic(`npm ${config.params.join(' ')}`)); + if (config.message) { + this.print(italic(config.message)); + } + this.print(`Execution Path: ${config.path}`); + if (config.logFile) { + this.print(`Log file: ${config.logFile}`); + } + + // 执行命令 + try { + let writeStream: WriteStream | undefined; + if (config.logFile) { + writeStream = createWriteStream(config.logFile, { flags: 'a' }); + } + await bash('npm', config.params, { + cwd: source, + }, (data) => { + if (writeStream) { + writeStream.write(data.toString()); + } else { + this.print(data.toString()); + } + }); + if (writeStream) { + writeStream.close(); + } + } catch (error) { + const err = error as Error; + this.print(err.message); + hasError = true; + } + } + + return hasError ? TaskState.error : TaskState.success; + } +} +registerTask('file', FileTask); diff --git a/source/internal.ts b/source/internal/repo.ts similarity index 71% rename from source/internal.ts rename to source/internal/repo.ts index e16e1b1..e622fc7 100644 --- a/source/internal.ts +++ b/source/internal/repo.ts @@ -1,4 +1,3 @@ -/* eslint-disable max-classes-per-file */ import { join, isAbsolute, dirname, basename, } from 'node:path'; @@ -7,21 +6,13 @@ import { existsSync, mkdirSync, renameSync, - statSync, } from 'node:fs'; -import { yellow, green, italic } from 'chalk'; +import { yellow } from 'chalk'; -import { registerTask, Task, TaskState } from './task'; -import { bash } from './utils'; +import { registerTask, Task, TaskState } from '../task'; +import { bash, makeDir } from '../utils'; -const cmd = { - git: process.platform === 'win32' ? 'git' : 'git', - tsc: process.platform === 'win32' ? 'tsc.cmd' : 'tsc', - lessc: process.platform === 'win32' ? 'lessc.cmd' : 'lessc', -}; - -export type TscConfig = string[]; type repoConfigItem = { // 远端仓库信息 repo: { @@ -45,84 +36,12 @@ type repoConfigItem = { hard: boolean; // 是否跳过这个仓库 skip: boolean; + + // 任务执行前的钩子 + beforeExecute?: (config: repoConfigItem) => Promise; }; export type RepoConfig = repoConfigItem[]; -class TscTask extends Task { - getTitle() { - return 'Compile with tsc'; - } - - async execute(workspace: string, config: TscConfig): Promise { - let hasError = false; - - for (const relativePath of config) { - // 将相对路径转成绝对路径 - const path = isAbsolute(relativePath) ? relativePath : join(workspace, relativePath); - - const dataItem = this.getCache(path); - - // 新的缓存数据 - const newDataItem: { - [key: string]: number; - } = {}; - - // 编译的文件是否有变化 - let changed = false; - - // 获取编译的文件列表 - try { - const fileArray: string[] = []; - await bash('npx', [cmd.tsc, '--listFiles'], { - cwd: path, - }, (data) => { - data.toString().split(/\r|\n/).forEach((file) => { - if (existsSync(file)) { - fileArray.push(file); - } - }); - }); - this.print(`${italic(relativePath)} Compile files: ${green(fileArray.length)}`); - - fileArray.forEach((file) => { - const stat = statSync(file); - const mtime = stat.mtime.getTime(); - if (!dataItem[file] || mtime !== dataItem[file]) { - changed = true; - } - newDataItem[file] = mtime; - }); - } catch (error) { - const err = error as Error; - this.print(err.message); - hasError = true; - } - - // 没有变化 - if (changed === false) { - continue; - } - - // 有变化的时候,更新缓存 - this.setCache(path, newDataItem); - - // 实际编译 - try { - await bash('npx', [cmd.tsc], { - cwd: path, - }); - } catch (error) { - const err = error as Error; - this.print(err.message); - hasError = true; - } - } - - return hasError ? TaskState.error : TaskState.success; - } -} -registerTask('tsc', TscTask); - export const RepoTaskMethods = { /** * Clones a remote repository to a specified path. @@ -132,7 +51,9 @@ export const RepoTaskMethods = { * @return {Promise} A promise that resolves when the cloning is complete. */ async clone(remote: string, path: string) { - await bash(cmd.git, ['clone', remote, basename(path)], { + const dir = basename(path); + await makeDir(dir); + await bash('git', ['clone', remote, dir], { cwd: dirname(path), }); }, @@ -146,17 +67,17 @@ export const RepoTaskMethods = { */ async updateRemote(name: string, remote: string, path: string) { try { - await bash(cmd.git, ['remote', 'add', name, remote], { + await bash('git', ['remote', 'add', name, remote], { cwd: path, }, () => {}); - await bash(cmd.git, ['remote', 'set-url', name, remote], { + await bash('git', ['remote', 'set-url', name, remote], { cwd: path, }, () => {}); } catch (error) { /** ignore */ } }, }; -class RepoTask extends Task { +export class RepoTask extends Task { getTitle() { return 'Synchronize the Git repository'; } @@ -171,6 +92,10 @@ class RepoTask extends Task { const bsd = dirname(path); const bsn = basename(path); + if (config.beforeExecute) { + await config.beforeExecute(config); + } + task.print(yellow(`>> ${config.repo.url}`)); // 允许配置某些仓库跳过 @@ -205,7 +130,7 @@ class RepoTask extends Task { // 同步远端 let fetchError: Error | undefined; try { - const code = await bash(cmd.git, ['fetch', config.repo.name], { + const code = await bash('git', ['fetch', config.repo.name], { cwd: path, }); if (code !== 0) { @@ -226,7 +151,7 @@ class RepoTask extends Task { // 获取远端 commit id if (config.repo.targetType === 'branch') { try { - await bash(cmd.git, ['rev-parse', `${config.repo.name}/${config.repo.targetValue}`], { + await bash('git', ['rev-parse', `${config.repo.name}/${config.repo.targetValue}`], { cwd: path, }, (chunk) => { const log = `${chunk}`; @@ -240,7 +165,7 @@ class RepoTask extends Task { } } else if (config.repo.targetType === 'tag') { try { - await bash(cmd.git, ['rev-parse', `tags/${config.repo.targetValue}`], { + await bash('git', ['rev-parse', `tags/${config.repo.targetValue}`], { cwd: path, }, (chunk) => { const log = `${chunk}`; @@ -259,7 +184,7 @@ class RepoTask extends Task { // 获取本地 commit id try { - await bash(cmd.git, ['rev-parse', 'HEAD'], { + await bash('git', ['rev-parse', 'HEAD'], { cwd: path, }, (chunk) => { const log = `${chunk}`; @@ -283,7 +208,7 @@ class RepoTask extends Task { // 检查是否有修改 let isDirty = false; - await bash(cmd.git, ['status', '-uno'], { + await bash('git', ['status', '-uno'], { cwd: path, }, (chunk) => { const info = `${chunk}`; @@ -298,7 +223,7 @@ class RepoTask extends Task { } task.print('Repository has modifications, stash changes'); try { - await bash(cmd.git, ['stash'], { + await bash('git', ['stash'], { cwd: path, }); } catch (error) { @@ -312,7 +237,7 @@ class RepoTask extends Task { // 检查当前分支 let isEditorBranch = false; try { - await bash(cmd.git, ['branch', '--show-current'], { + await bash('git', ['branch', '--show-current'], { cwd: path, }, (chunk) => { const log = `${chunk}`; @@ -332,21 +257,21 @@ class RepoTask extends Task { } try { // 从当前位置切出分支,如果有则忽略 - await bash(cmd.git, ['checkout', '-b', config.repo.local], { + await bash('git', ['checkout', '-b', config.repo.local], { cwd: path, }, () => {}); } catch (error) { /** ignore */ } try { // 从当前位置切出分支,如果有则忽略 - await bash(cmd.git, ['checkout', config.repo.local], { + await bash('git', ['checkout', config.repo.local], { cwd: path, }, () => {}); } catch (error) { /** ignore */ } try { let info = ''; - await bash(cmd.git, ['reset', '--hard', remoteID], { + await bash('git', ['reset', '--hard', remoteID], { cwd: path, }, (chunk) => { info += chunk; diff --git a/source/internal/tsc.ts b/source/internal/tsc.ts new file mode 100644 index 0000000..920acd3 --- /dev/null +++ b/source/internal/tsc.ts @@ -0,0 +1,95 @@ +import { + join, isAbsolute, +} from 'node:path'; + +import { + existsSync, + statSync, +} from 'node:fs'; +import { cpus } from 'node:os'; + +import { green, italic } from 'chalk'; + +import { registerTask, Task, TaskState } from '../task'; +import { bash } from '../utils'; + +export type TscConfig = string[]; + +export class TscTask extends Task { + static getMaxConcurrent() { + return cpus().length; + } + + getTitle() { + return 'Compile with tsc'; + } + + async execute(workspace: string, config: TscConfig): Promise { + let hasError = false; + + for (const relativePath of config) { + // 将相对路径转成绝对路径 + const path = isAbsolute(relativePath) ? relativePath : join(workspace, relativePath); + + const dataItem = this.getCache(path); + + // 新的缓存数据 + const newDataItem: { + [key: string]: number; + } = {}; + + // 编译的文件是否有变化 + let changed = false; + + // 获取编译的文件列表 + try { + const fileArray: string[] = []; + await bash('npx', ['tsc', '--listFiles'], { + cwd: path, + }, (data) => { + data.toString().split(/\r|\n/).forEach((file) => { + if (existsSync(file)) { + fileArray.push(file); + } + }); + }); + this.print(`${italic(relativePath)} Compile files: ${green(fileArray.length)}`); + + fileArray.forEach((file) => { + const stat = statSync(file); + const mtime = stat.mtime.getTime(); + if (!dataItem[file] || mtime !== dataItem[file]) { + changed = true; + } + newDataItem[file] = mtime; + }); + } catch (error) { + const err = error as Error; + this.print(err.message); + hasError = true; + } + + // 没有变化 + if (changed === false) { + continue; + } + + // 实际编译 + try { + await bash('npx', ['tsc'], { + cwd: path, + }); + + // 有变化的时候,更新缓存 + this.setCache(path, newDataItem); + } catch (error) { + const err = error as Error; + this.print(err.message); + hasError = true; + } + } + + return hasError ? TaskState.error : TaskState.success; + } +} +registerTask('tsc', TscTask); diff --git a/source/task.ts b/source/task.ts index 8edd96a..f7a19bc 100644 --- a/source/task.ts +++ b/source/task.ts @@ -160,7 +160,7 @@ export async function executeTask(taskNameList: string[]) { for (const taskName of taskNameList) { const taskStartTime = Date.now(); // 开始任务的分割线 - console.log(magenta(`${split} ${taskName} ${split}`)); + console.log(magenta(`${split} ${taskName} ${split} Parallelism Count: ${Task.getMaxConcurrent()}`)); const CacheTask = TaskMap.get(taskName); if (!CacheTask) { @@ -253,7 +253,7 @@ export async function executeTask(taskNameList: string[]) { manager.start(); manager.addListener('finish', () => { const taskEndTime = Date.now(); - console.log(magenta(`${split} ${taskName}(${formatTime(taskEndTime - taskStartTime)}) ${split}`)); + console.log(magenta(`${split} ${taskName} ${split} Consumed Time: ${formatTime(taskEndTime - taskStartTime)}`)); resolve(undefined); }); }); diff --git a/source/utils.ts b/source/utils.ts index dc594c9..534bb77 100644 --- a/source/utils.ts +++ b/source/utils.ts @@ -3,7 +3,7 @@ import { MakeDirectoryOptions, } from 'fs'; import { join } from 'path'; -import { spawn, SpawnOptionsWithoutStdio } from 'child_process'; +import { spawn, SpawnOptionsWithoutStdio, spawnSync } from 'child_process'; /** * 循环传入的文件/文件夹里所有的文件/文件夹 @@ -51,6 +51,13 @@ export async function bash( handle?: (data: Buffer) => void, ) { return new Promise((resolve, reject) => { + if (process.platform === 'win32' && !cmd.endsWith('.cmd')) { + const str = spawnSync('where', [cmd], { stdio: 'inherit' }).toString(); + if (str.includes('.cmd')) { + // eslint-disable-next-line no-param-reassign + cmd += '.cmd'; + } + } if (options.cwd && !existsSync(options.cwd)) { mkdirSync(options.cwd); } diff --git a/test/task.spec.js b/test/task.spec.js index 3e13db6..1900d9d 100644 --- a/test/task.spec.js +++ b/test/task.spec.js @@ -113,4 +113,65 @@ describe('task', () => { }, cacheJSON); }); }); + + describe('less', () => { + const baseDir = join(__dirname, './task/workspace-less'); + const PATH = { + cache: join(baseDir, './.dist/cache.json'), + result: join(baseDir, './.dist/result.json'), + }; + + before(() => { + spawnSync('node', [join(baseDir, './run.js')]); + }); + + it('检查缓存信息', async () => { + const cacheStr = readFileSync(PATH.cache, 'utf8'); + const cacheJSON = JSON.parse(cacheStr); + equal(true, !!cacheJSON.less); + }); + + it('检查运行结果', async () => { + const cacheStr = readFileSync(PATH.result, 'utf8'); + const cacheJSON = JSON.parse(cacheStr); + deepEqual({ + less: ['success'], + }, cacheJSON); + equal(true, existsSync(join(baseDir, './.dist/test.css'))); + }); + }); + + describe('file', () => { + const baseDir = join(__dirname, './task/workspace-file'); + const PATH = { + cache: join(baseDir, './.dist/cache.json'), + result: join(baseDir, './.dist/result.json'), + }; + + before(() => { + spawnSync('node', [join(baseDir, './run.js')]); + }); + + it('检查缓存信息', async () => { + const cacheStr = readFileSync(PATH.cache, 'utf8'); + const cacheJSON = JSON.parse(cacheStr); + equal(true, !!cacheJSON.file); + }); + + it('检查运行结果', async () => { + const cacheStr = readFileSync(PATH.result, 'utf8'); + const cacheJSON = JSON.parse(cacheStr); + deepEqual({ + file: ['success'], + }, cacheJSON); + equal(true, existsSync(join(baseDir, './.dist/test-1'))); + equal(true, existsSync(join(baseDir, './.dist/test-1/a-dist'))); + equal(true, existsSync(join(baseDir, './.dist/test-1/a-dist/a'))); + equal(true, existsSync(join(baseDir, './.dist/test-1/b'))); + equal(true, existsSync(join(baseDir, './.dist/test-2'))); + equal(false, existsSync(join(baseDir, './.dist/test-2/a-dist'))); + equal(false, existsSync(join(baseDir, './.dist/test-2/a-dist/a'))); + equal(true, existsSync(join(baseDir, './.dist/test-2/b'))); + }); + }); }); diff --git a/test/task/workspace-file/.test.config.js b/test/task/workspace-file/.test.config.js new file mode 100644 index 0000000..27d1e35 --- /dev/null +++ b/test/task/workspace-file/.test.config.js @@ -0,0 +1,15 @@ +exports.file = function(params) { + return [ + { + source: './test', + dist: './.dist/test-1', + }, + { + source: './test', + dist: './.dist/test-2', + filter(file) { + return file.endsWith('b'); + }, + }, + ]; +} diff --git a/test/task/workspace-file/run.js b/test/task/workspace-file/run.js new file mode 100644 index 0000000..6f5eee7 --- /dev/null +++ b/test/task/workspace-file/run.js @@ -0,0 +1,22 @@ +const { writeFileSync } = require('node:fs'); +const { join } = require('node:path'); + +const { + initWorkflow, + executeTask, +} = require('../../../dist/task'); +require('../../../dist/internal'); + +initWorkflow({ + entry: '.test.config.js', + params: {}, + cacheFile: join(__dirname, './.dist/cache.json'), + cacheDir: join(__dirname, './.dist/files'), + workspaces: [ + __dirname, + ], +}); + +executeTask(['file']).then((results) => { + writeFileSync(join(__dirname, '.dist/result.json'), JSON.stringify(results, null, 2)); +}); diff --git a/test/task/workspace-file/test/a-dist/a b/test/task/workspace-file/test/a-dist/a new file mode 100644 index 0000000..e69de29 diff --git a/test/task/workspace-file/test/b b/test/task/workspace-file/test/b new file mode 100644 index 0000000..e69de29 diff --git a/test/task/workspace-less/.test.config.js b/test/task/workspace-less/.test.config.js new file mode 100644 index 0000000..1def9db --- /dev/null +++ b/test/task/workspace-less/.test.config.js @@ -0,0 +1,8 @@ +exports.less = function(params) { + return [ + { + source: './test-1.less', + dist: './.dist/test.css', + }, + ]; +} diff --git a/test/task/workspace-less/run.js b/test/task/workspace-less/run.js new file mode 100644 index 0000000..94121f8 --- /dev/null +++ b/test/task/workspace-less/run.js @@ -0,0 +1,22 @@ +const { writeFileSync } = require('node:fs'); +const { join } = require('node:path'); + +const { + initWorkflow, + executeTask, +} = require('../../../dist/task'); +require('../../../dist/internal'); + +initWorkflow({ + entry: '.test.config.js', + params: {}, + cacheFile: join(__dirname, './.dist/cache.json'), + cacheDir: join(__dirname, './.dist/files'), + workspaces: [ + __dirname, + ], +}); + +executeTask(['less']).then((results) => { + writeFileSync(join(__dirname, '.dist/result.json'), JSON.stringify(results, null, 2)); +}); diff --git a/test/task/workspace-less/test 3.less b/test/task/workspace-less/test 3.less new file mode 100644 index 0000000..e69de29 diff --git a/test/task/workspace-less/test-1.less b/test/task/workspace-less/test-1.less new file mode 100644 index 0000000..dcebbd1 --- /dev/null +++ b/test/task/workspace-less/test-1.less @@ -0,0 +1 @@ +@import './test-2.less'; \ No newline at end of file diff --git a/test/task/workspace-less/test-2.less b/test/task/workspace-less/test-2.less new file mode 100644 index 0000000..7ad0021 --- /dev/null +++ b/test/task/workspace-less/test-2.less @@ -0,0 +1 @@ +@import './test 3.less'; \ No newline at end of file