This repository has been archived by the owner on Feb 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
mason.js
55 lines (48 loc) · 1.88 KB
/
mason.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const mason = require('@joomlatools/mason-tools-v1');
const path = require('path');
const fs = require('fs').promises;
const frameworkFolder = process.cwd();
const libraryAssetsPath = `${frameworkFolder}/code/resources/assets`;
const KUIPath = `${path.resolve(frameworkFolder, '..')}/kodekit-ui/dist`;
async function files() {
await mason.fs.copyFolderContents(`${KUIPath}/css`, `${libraryAssetsPath}/css`);
await mason.fs.copyFolderContents(`${KUIPath}/fonts`, `${libraryAssetsPath}/fonts`);
await mason.fs.copyFolderContents(`${KUIPath}/img`, `${libraryAssetsPath}/img`);
await mason.fs.copyFolderContents(`${KUIPath}/js`, `${libraryAssetsPath}/js`, {
rename: (targetName) => targetName.replace(/koowa\./, "kodekit.")
});
}
async function js() {
await fs.rename(`${libraryAssetsPath}/js/admin.kodekit.js`, `${libraryAssetsPath}/js/admin.js`);
await fs.rename(`${libraryAssetsPath}/js/admin.kodekit.min.js`, `${libraryAssetsPath}/js/admin.min.js`);
const append = [
`${libraryAssetsPath}/js/kodekit.js`,
`${libraryAssetsPath}/js/kodekit.min.js`,
`${libraryAssetsPath}/js/kodekit.select2.js`,
`${libraryAssetsPath}/js/kodekit.select2.min.js`
];
for (let file of append) {
let contents = await fs.readFile(file);
contents += "\nif(typeof Kodekit === 'undefined') { var Kodekit = Koowa; }\n";
await fs.writeFile(file, contents);
}
}
module.exports = {
version: '1.0',
tasks: {
files,
js,
watch: {
path: [`${libraryAssetsPath}/scss`, `${libraryAssetsPath}/js`],
callback: async (path) => {
if (path.endsWith('.scss')) {
await css();
}
else if (path.endsWith('.js')) {
await js();
}
},
},
default: ['files', 'js'],
},
};