mirror of
https://git.undefined-dev.fr/Blendman974/faceclaw.git
synced 2026-11-19 21:03:09 +00:00
33 lines
1.2 KiB
JavaScript
33 lines
1.2 KiB
JavaScript
// NativeScript runs hooks/<event>/*.js, but that directory is also managed by
|
|
// @nativescript/hook on package (re)installs and has been observed to lose our
|
|
// custom hook. The tracked copy under scripts/hooks/ is the source of truth;
|
|
// this restores it on `npm install` and before every build.
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
|
|
const root = path.resolve(__dirname, '..');
|
|
const hooks = [
|
|
{ source: 'scripts/hooks/faceclaw-kotlin.before-prepare.js', target: 'hooks/before-prepare/faceclaw-kotlin.js' },
|
|
{ source: 'scripts/hooks/faceclaw-watch.after-prepare.js', target: 'hooks/after-prepare/faceclaw-watch.js' },
|
|
];
|
|
|
|
function installHooks() {
|
|
const restored = [];
|
|
for (const { source, target } of hooks) {
|
|
const from = path.join(root, source);
|
|
const to = path.join(root, target);
|
|
const content = fs.readFileSync(from);
|
|
if (fs.existsSync(to) && fs.readFileSync(to).equals(content)) continue;
|
|
fs.mkdirSync(path.dirname(to), { recursive: true });
|
|
fs.writeFileSync(to, content);
|
|
restored.push(target);
|
|
}
|
|
return restored;
|
|
}
|
|
|
|
module.exports = { installHooks };
|
|
if (require.main === module) {
|
|
const restored = installHooks();
|
|
if (restored.length) console.log(`[hooks] restored ${restored.join(', ')}`);
|
|
}
|