-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcompile.js
executable file
·91 lines (74 loc) · 2.82 KB
/
compile.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env node
/**
* ______ __ __
* / ____/___ ____ / /__________ / /
* / / / __ \/ __ \/ __/ ___/ __ \/ /
* / /___/ /_/ / / / / /_/ / / /_/ / /
* \______________/_/\__/_/ \____/_/
* / | / / /_
* / /| | / / __/
* / ___ |/ / /_
* /_/ _|||_/\__/ __ __
* / __ \___ / /__ / /____
* / / / / _ \/ / _ \/ __/ _ \
* / /_/ / __/ / __/ /_/ __/
* /_____/\___/_/\___/\__/\___/
*
* This file loops over all themes, removes the tailwind.css file and then recompiles it. The deletion is to prevent
* Magento it from symlinking when in developer mode.
*/
const { readdirSync, unlinkSync, mkdirSync } = require('fs')
const resolve = require('path').resolve
const glob = require("glob")
const { spawn } = require("child_process")
const getMagentoBasePath = function (directory = '../') {
const hasBin = readdirSync(directory).includes('bin');
if ((directory.match(/\//g) || []).length > 5) {
throw 'bin/magento binary not found, unable to detect location'
}
if (!hasBin) {
return getMagentoBasePath(directory + '../');
}
if (!readdirSync(directory + 'bin/').includes('magento')) {
throw 'The bin folder is found but the Magento executable does not exist!?'
}
return resolve(directory);
}
const path = getMagentoBasePath();
glob(path + '/pub/static/frontend/*/*/*/ControlAltDelete_FullAhead/css/tailwind.css', (error, files) => {
files.forEach(file => {
unlinkSync(file);
if (process.argv.includes('--vebose')) {
console.log('Unlinked', file)
}
})
})
const getCommand = path => {
if (process.argv.includes('--production')) {
return {
executable: 'NODE_ENV=production node_modules/.bin/postcss',
arguments: ['tailwind.css', '--verbose', '--config postcss/production', '--output ' + path]
}
}
if (process.argv.includes('--watch')) {
return {
executable: 'TAILWIND_MODE=watch node_modules/.bin/postcss',
arguments: ['tailwind.css', '--verbose', '--config postcss/dev', '--output ' + path, '--watch']
}
}
return {
executable: 'node_modules/.bin/postcss',
arguments: ['tailwind.css', '--verbose', '--config postcss/dev', '--output ' + path]
}
}
glob(path + '/pub/static/frontend/*/*/*/', (error, files) => {
files.forEach(file => {
mkdirSync(file + '/ControlAltDelete_FullAhead/css', {recursive: true});
const cssPath = file + '/ControlAltDelete_FullAhead/css/tailwind.css'
const command = getCommand(cssPath);
if (process.argv.includes('--verbose')) {
console.info('Executing', command.executable + ' ' + command.arguments.join(' '));
}
spawn(command.executable, command.arguments, { shell: true, stdio: 'inherit' });
})
});