Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node

import { writeFileSync, readFileSync, readdirSync, statSync, copyFileSync } from 'node:fs'
import { writeFileSync, readFileSync, readdirSync, statSync, copyFileSync, mkdirSync } from 'node:fs'
import path from 'node:path'

const cwd = process.cwd() + path.sep;
Expand Down Expand Up @@ -78,9 +78,11 @@ function copyFiles(baseDir: string) {
continue;
}
let targetFilepath = filepath.replace(sourceDir, commonjsDir);
mkdirSync(path.dirname(targetFilepath), { recursive: true });
copyFileSync(filepath, targetFilepath);
console.log('Copy %s to %s', filepath.replace(cwd, ''), targetFilepath.replace(cwd, ''));
targetFilepath = filepath.replace(sourceDir, esmDir);
mkdirSync(path.dirname(targetFilepath), { recursive: true });
copyFileSync(filepath, targetFilepath);
console.log('Copy %s to %s', filepath.replace(cwd, ''), targetFilepath.replace(cwd, ''));
}
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/demo/src/templates/bar.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello world
1 change: 1 addition & 0 deletions test/fixtures/demo/src/templates/foo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello world
9 changes: 9 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ describe('test/index.test.ts', () => {
jsonFile = path.join(cwd, 'dist/esm/bar.json');
assert.equal(fs.statSync(jsonFile).isFile(), true);

let htmlFile = path.join(cwd, 'dist/commonjs/templates/foo.html');
assert.equal(fs.statSync(htmlFile).isFile(), true);
htmlFile = path.join(cwd, 'dist/esm/templates/foo.html');
assert.equal(fs.statSync(htmlFile).isFile(), true);
htmlFile = path.join(cwd, 'dist/commonjs/templates/bar.html');
assert.equal(fs.statSync(htmlFile).isFile(), true);
htmlFile = path.join(cwd, 'dist/esm/templates/bar.html');
assert.equal(fs.statSync(htmlFile).isFile(), true);

// should dist/package.json exists, include name and version
const distPackageFile = path.join(cwd, 'dist/package.json');
const distPkg = JSON.parse(fs.readFileSync(distPackageFile, 'utf-8'));
Expand Down