Skip to content

Commit

Permalink
chore: update script library
Browse files Browse the repository at this point in the history
  • Loading branch information
Mercy811 committed Dec 19, 2024
1 parent 5b9dbe0 commit 74c5a03
Showing 1 changed file with 24 additions and 32 deletions.
56 changes: 24 additions & 32 deletions scripts/build/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,43 +55,36 @@ export const umd = {
],
};

const updateLibPrefix = (isUndo) => {
const path = 'src/lib-prefix.ts'
if (!fs.existsSync(path)) {
// Supported in rollup 4, we're currently rollup 2
// this.error(`File not found: ${path}`);
return;
}

let content = fs.readFileSync(path, 'utf-8');
let updatedContent;
if (isUndo) {
updatedContent = content.replace(/amplitude-ts-sdk-script/g, 'amplitude-ts');
} else {
updatedContent = content.replace(/amplitude-ts/g, 'amplitude-ts-sdk-script');
}

fs.writeFileSync(path, updatedContent, 'utf-8');
// this.info(`File updated: ${path}`);
}


const updateLibPrefix = () => {
const updateLibPrefixPlugin = (isUndo) => {
return {
name: 'update-lib-prefix',
buildStart() {
const path = 'src/lib-prefix.ts'
if (!fs.existsSync(path)) {
// Supported in rollup 4, we're currently rollup 2
// this.error(`File not found: ${path}`);
return;
}

let content = fs.readFileSync(path, 'utf-8');
const updatedContent = content.replace(/amplitude-ts/g, 'amplitude-ts-sdk-script');
fs.writeFileSync(path, updatedContent, 'utf-8');
// this.info(`File updated: ${path}`);
updateLibPrefix(false);
},
};
}

const undoLibPrefix = () => {
return {
name: 'undo-lib-prefix',
buildEnd() {
const path = 'src/lib-prefix.ts'
if (!fs.existsSync(path)) {
// Supported in rollup 4, we're currently rollup 2
// this.error(`File not found: ${path}`);
return;
}

let content = fs.readFileSync(path, 'utf-8');
const updatedContent = content.replace(/amplitude-ts-sdk-script/g, 'amplitude-ts');
fs.writeFileSync(path, updatedContent, 'utf-8');
// this.info(`File updated: ${path}`);
},
updateLibPrefix(true);
}
};
}

Expand All @@ -104,7 +97,7 @@ export const iife = {
sourcemap: true,
},
plugins: [
updateLibPrefix(),
updateLibPrefixPlugin(),
typescript({
module: 'es6',
noEmit: false,
Expand All @@ -121,7 +114,6 @@ export const iife = {
},
}),
gzip(),
undoLibPrefix(),
],
};

Expand Down

0 comments on commit 74c5a03

Please sign in to comment.