-
-
Notifications
You must be signed in to change notification settings - Fork 863
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(build): copy plugin to commonjs
- Loading branch information
Showing
7 changed files
with
169 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module.exports = { | ||
source: 'src', | ||
output: 'lib', | ||
targets: [ | ||
'commonjs', | ||
'module', | ||
'typescript', | ||
[ | ||
'custom', | ||
{ | ||
script: 'build:copy-plugin', | ||
}, | ||
], | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
|
||
const rootDir = path.resolve(__dirname, '..'); | ||
const destDir = path.resolve(rootDir, 'lib/commonjs'); | ||
const pluginDir = path.resolve(rootDir, 'plugin'); | ||
const appPluginFile = path.resolve(rootDir, 'app.plugin.js'); | ||
|
||
function copyFileSync(source: string, target: string) { | ||
let targetFile = target; | ||
|
||
// If target is a directory, a new file with the same name will be created | ||
if (fs.existsSync(target)) { | ||
if (fs.lstatSync(target).isDirectory()) { | ||
targetFile = path.join(target, path.basename(source)); | ||
} | ||
} | ||
|
||
fs.writeFileSync(targetFile, fs.readFileSync(source)); | ||
} | ||
|
||
function copyFolderRecursiveSync(source: string, target: string) { | ||
let files = []; | ||
|
||
// Check if folder needs to be created or integrated | ||
const targetFolder = path.join(target, path.basename(source)); | ||
if (!fs.existsSync(targetFolder)) { | ||
fs.mkdirSync(targetFolder); | ||
} | ||
|
||
// Copy | ||
if (fs.lstatSync(source).isDirectory()) { | ||
files = fs.readdirSync(source); | ||
files.forEach((file) => { | ||
const curSource = path.join(source, file); | ||
if (fs.lstatSync(curSource).isDirectory()) { | ||
copyFolderRecursiveSync(curSource, targetFolder); | ||
} else { | ||
copyFileSync(curSource, targetFolder); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
// Ensure destination directory exists | ||
if (!fs.existsSync(destDir)) { | ||
fs.mkdirSync(destDir, { recursive: true }); | ||
} | ||
|
||
// Copy app.plugin.js | ||
copyFileSync(appPluginFile, destDir); | ||
|
||
// Copy plugin folder | ||
copyFolderRecursiveSync(pluginDir, destDir); | ||
|
||
console.log('Files copied successfully.'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"compilerOptions": { | ||
}, | ||
"include": ["./copy-plugin.ts"], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.