WIP: Use scss instead of css #158

Closed
deblan wants to merge 6 commits from feature/issue152 into develop
11 changed files with 136 additions and 77 deletions

1
.gitignore vendored
View file

@ -1,4 +1,5 @@
/js /js
/assets
/node_modules /node_modules
/l10n/* /l10n/*
/releases /releases

View file

@ -8,13 +8,13 @@ use OC\User\User;
use OCA\SideMenu\Service\AppRepository; use OCA\SideMenu\Service\AppRepository;
use OCA\SideMenu\Service\CategoryRepository; use OCA\SideMenu\Service\CategoryRepository;
use OCA\SideMenu\Service\ConfigProxy; use OCA\SideMenu\Service\ConfigProxy;
use OCA\SideMenu\Util\AssetUtil;
use OCP\AppFramework\App; use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext; use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext; use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\IUserSession; use OCP\IUserSession;
use OCP\Util; use OCP\Util;
use Psr\Container\ContainerInterface;
/** /**
* class Application. * class Application.
@ -72,21 +72,27 @@ class Application extends App implements IBootstrap
protected function addAssets() protected function addAssets()
{ {
Util::addScript(self::APP_ID, 'sideMenu'); AssetUtil::getInstance()
Util::addStyle(self::APP_ID, 'sideMenu'); // Add runtime.js
->addEntrypointAsset('menu', 'js', 0)
// Add menu.js
->addEntrypointAsset('menu', 'js', 1)
// Add menu.css
->addEntrypointAsset('menu', 'css', 0)
;
$assets = [ $assets = [
'stylesheet' => [ [
'route' => 'side_menu.Css.stylesheet',
'type' => 'link', 'type' => 'link',
'route' => 'side_menu.Css.stylesheet',
'route_attr' => 'href', 'route_attr' => 'href',
'attr' => [ 'attr' => [
'rel' => 'stylesheet', 'rel' => 'stylesheet',
], ],
], ],
'script' => [ [
'route' => 'side_menu.Js.script',
'type' => 'script', 'type' => 'script',
'route' => 'side_menu.Js.script',
'route_attr' => 'src', 'route_attr' => 'src',
'attr' => [ 'attr' => [
'nonce' => $this->cspnm->getNonce(), 'nonce' => $this->cspnm->getNonce(),
@ -99,7 +105,6 @@ class Application extends App implements IBootstrap
foreach ($assets as $value) { foreach ($assets as $value) {
$route = OC::$server->getURLGenerator()->linkToRoute($value['route'], ['v' => $cache]); $route = OC::$server->getURLGenerator()->linkToRoute($value['route'], ['v' => $cache]);
$value['attr'][$value['route_attr']] = $route; $value['attr'][$value['route_attr']] = $route;
Util::addHeader($value['type'], $value['attr'], ''); Util::addHeader($value['type'], $value['attr'], '');
} }
} }

64
lib/Util/AssetUtil.php Normal file
View file

@ -0,0 +1,64 @@
<?php
namespace OCA\SideMenu\Util;
use OC_Util;
use OCA\SideMenu\AppInfo\Application;
/**
* class AssetUtil.
*
* @author Simon Vieille <simon@deblan.fr>
*/
class AssetUtil
{
protected array $entrypoints;
protected static ?AssetUtil $instance = null;
public function __construct()
{
$this->entrypoints = json_decode(
file_get_contents(__DIR__.'/../../assets/entrypoints.json'),
true
)['entrypoints'];
}
public static function getInstance(): self
{
if (null === self::$instance) {
self::$instance = new self();
}
return self::$instance;
}
public function addEntrypointAsset($entry, $type, $key): self
{
$file = basename($this->entrypoints[$entry][$type][$key]);
$path = $this->generatePath('assets', $file);
return $this->addAsset($type, $path);
}
public function addAsset($type, $path): self
{
$path = preg_replace('/\.(css|js)$/', '', $path);
if ('css' === $type) {
OC_Util::$styles[] = $path;
} elseif ('js' === $type) {
OC_Util::$scripts[] = $path;
}
return $this;
}
public function generatePath($directory, $file): string
{
return implode('/', [
Application::APP_ID,
$directory,
$file,
]);
}
}

View file

@ -2,9 +2,9 @@
"license": "agpl", "license": "agpl",
"private": true, "private": true,
"scripts": { "scripts": {
"build": "NODE_ENV=production ./node_modules/.bin/webpack-cli --progress --config webpack.js", "build": "./node_modules/.bin/encore prod",
"dev": "NODE_ENV=development ./node_modules/.bin/webpack-cli --progress --config webpack.js", "dev": "./node_modules/.bin/encore dev",
"watch": "NODE_ENV=development ./node_modules/.bin/webpack-cli --progress --watch --config webpack.js", "watch": "./node_modules/.bin/encore dev --watch",
"lint": "./node_modules/.bin/eslint --ext .js,.vue src", "lint": "./node_modules/.bin/eslint --ext .js,.vue src",
"lint:fix": "./node_modules/.bin/eslint --ext .js,.vue src --fix", "lint:fix": "./node_modules/.bin/eslint --ext .js,.vue src --fix",
"stylelint": "./node_modules/.bin/stylelint src", "stylelint": "./node_modules/.bin/stylelint src",
@ -12,7 +12,6 @@
}, },
"dependencies": { "dependencies": {
"axios": "^0.24.0", "axios": "^0.24.0",
"trim": "^1.0.1",
"vue": "^2.6.11" "vue": "^2.6.11"
}, },
"browserslist": [ "browserslist": [
@ -24,13 +23,16 @@
"devDependencies": { "devDependencies": {
"@babel/core": "^7.9.0", "@babel/core": "^7.9.0",
"@babel/plugin-syntax-dynamic-import": "^7.8.3", "@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/plugin-transform-runtime": "^7.19.6",
"@babel/preset-env": "^7.9.0", "@babel/preset-env": "^7.9.0",
"@babel/runtime": "^7.20.0",
"@nextcloud/axios": "^1.8.0", "@nextcloud/axios": "^1.8.0",
"@nextcloud/browserslist-config": "^1.0.0", "@nextcloud/browserslist-config": "^1.0.0",
"@nextcloud/eslint-config": "^8.1.2", "@nextcloud/eslint-config": "^8.1.2",
"@nextcloud/initial-state": "^2.0.0", "@nextcloud/initial-state": "^2.0.0",
"@nextcloud/l10n": "^1.6.0", "@nextcloud/l10n": "^1.6.0",
"@nextcloud/vue": "^7.0.0", "@nextcloud/vue": "^7.0.0",
"@symfony/webpack-encore": "^4.1.1",
"babel-eslint": "^10.1.0", "babel-eslint": "^10.1.0",
"babel-loader": "^8.1.0", "babel-loader": "^8.1.0",
"css-loader": "^3.4.2", "css-loader": "^3.4.2",
@ -45,8 +47,8 @@
"eslint-plugin-vue": "^9.0.0", "eslint-plugin-vue": "^9.0.0",
"eslint-webpack-plugin": "^3.0.0", "eslint-webpack-plugin": "^3.0.0",
"file-loader": "^6.0.0", "file-loader": "^6.0.0",
"sass": "^1.49.9", "sass": "^1.55.0",
"sass-loader": "^13.0.2", "sass-loader": "^13.1.0",
"stylelint": "^14.0.0", "stylelint": "^14.0.0",
"stylelint-config-recommended-scss": "^7.0.0", "stylelint-config-recommended-scss": "^7.0.0",
"stylelint-scss": "^4.0.0", "stylelint-scss": "^4.0.0",
@ -55,7 +57,7 @@
"vue-loader": "^15", "vue-loader": "^15",
"vue-style-loader": "^4.1.3", "vue-style-loader": "^4.1.3",
"vue-template-compiler": "^2.7.13", "vue-template-compiler": "^2.7.13",
"webpack": "^5.0.0", "webpack": "^5.74.0",
"webpack-cli": "^4.0.0", "webpack-cli": "^4.0.0",
"webpack-merge": "^4.2.2", "webpack-merge": "^4.2.2",
"webpack-node-externals": "^1.7.2" "webpack-node-externals": "^1.7.2"

View file

@ -53,7 +53,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
</template> </template>
<script> <script>
import trim from 'trim'
import axios from 'axios' import axios from 'axios'
import OpenerButton from './OpenerButton' import OpenerButton from './OpenerButton'
import SettingsButton from './SettingsButton' import SettingsButton from './SettingsButton'

View file

@ -15,6 +15,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
import 'regenerator-runtime/runtime'
import './css/admin.scss'
import AdminCategoriesCustom from './AdminCategoriesCustom.vue' import AdminCategoriesCustom from './AdminCategoriesCustom.vue'
import Vue from 'vue' import Vue from 'vue'

View file

@ -73,7 +73,7 @@
} }
.side-menu-opener { .side-menu-opener {
background: var(--side-menu-opener, url('../img/side-menu-opener.svg')); background: var(--side-menu-opener, url('../../img/side-menu-opener.svg'));
background-color: transparent !important; background-color: transparent !important;
height: 40px !important; height: 40px !important;
width: 40px !important; width: 40px !important;
@ -90,7 +90,7 @@
} }
.side-menu-closer { .side-menu-closer {
background: url('../img/side-menu-opener-closer.svg'); background: url('../../img/side-menu-opener-closer.svg');
display: none; display: none;
} }
@ -113,7 +113,7 @@
vertical-align: middle; vertical-align: middle;
margin-top: -4px; margin-top: -4px;
margin-right: 10px; margin-right: 10px;
filter: invert(var(--side-menu-icon-invert-filter, 0%)); /*filter: invert(var(--side-menu-icon-invert-filter, 0%));*/
opacity: var(--side-menu-icon-opacity, 1); opacity: var(--side-menu-icon-opacity, 1);
} }

View file

@ -15,6 +15,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
import 'regenerator-runtime/runtime'
import './css/menu.scss'
import Vue from 'vue' import Vue from 'vue'
import AppMenu from './AppMenu.vue' import AppMenu from './AppMenu.vue'
import SideMenu from './SideMenu.vue' import SideMenu from './SideMenu.vue'
@ -23,11 +25,15 @@ import SideMenuWithCategories from './SideMenuWithCategories.vue'
import PageLoader from './PageLoader' import PageLoader from './PageLoader'
import SMcreateElement from './lib/createElement' import SMcreateElement from './lib/createElement'
Vue.prototype.OC = OC setInterval(() => {
Vue.prototype.t = OC.L10N.translate console.log(window.OC)
}, 100)
window.SMcreateElement = SMcreateElement // Vue.prototype.OC = window.OC
window.PageLoader = PageLoader // Vue.prototype.t = OC.L10N.translate
//
// window.SMcreateElement = SMcreateElement
// window.PageLoader = PageLoader
const mountSideMenuComponent = () => { const mountSideMenuComponent = () => {
const container = document.querySelector('#side-menu') const container = document.querySelector('#side-menu')

34
webpack.config.js Normal file
View file

@ -0,0 +1,34 @@
const Encore = require('@symfony/webpack-encore');
// Manually configure the runtime environment if not already configured yet by the "encore" command.
// It's useful when you use tools that rely on webpack.config.js file.
if (!Encore.isRuntimeEnvironmentConfigured()) {
Encore.configureRuntimeEnvironment(process.env.NODE_ENV || 'dev');
}
Encore
.setOutputPath('assets/')
.setPublicPath('./')
.addEntry('admin', './src/admin.js')
.addEntry('menu', './src/menu.js')
.setManifestKeyPrefix('./')
.enableSingleRuntimeChunk()
.cleanupOutputBeforeBuild()
.enableVueLoader()
.enableSourceMaps(!Encore.isProduction())
.enableVersioning(Encore.isProduction())
.configureBabel((config) => {
config.plugins.push('@babel/plugin-proposal-class-properties');
})
.configureBabelPresetEnv((config) => {
config.useBuiltIns = 'usage';
config.corejs = 3;
})
.copyFiles({
from: './img',
to: 'images/[path][name].[hash:8].[ext]'
})
.enableSassLoader()
;
module.exports = Encore.getWebpackConfig();

View file

@ -1,54 +0,0 @@
const path = require('path')
const { VueLoaderPlugin } = require('vue-loader')
const StyleLintPlugin = require('stylelint-webpack-plugin')
module.exports = {
devtool: "source-map",
entry: {
'admin': path.join(__dirname, 'src', 'admin.js'),
'sideMenu': path.join(__dirname, 'src', 'SideMenu.js'),
},
output: {
path: path.resolve(__dirname, './js'),
publicPath: '/js',
filename: '[name].js?v=[hash]',
chunkFilename: 'chunks/[name]-[hash].js',
},
module: {
rules: [
{
test: /\.css$/,
use: ['vue-style-loader', 'css-loader'],
},
{
test: /\.scss$/,
use: ['vue-style-loader', 'css-loader', 'sass-loader'],
},
{
test: /\.vue$/,
loader: 'vue-loader',
},
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/,
},
{
test: /\.(png|jpg|gif|svg)$/,
loader: 'url-loader',
options: {
name: '[name].[ext]?[hash]',
limit: 8192,
},
},
],
},
plugins: [
new VueLoaderPlugin(),
new StyleLintPlugin(),
],
resolve: {
extensions: ['*', '.js', '.vue'],
symlinks: false,
},
}