diff --git a/README.md b/README.md index c764eca..42f622a 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ See [Configuration Reference](https://cli.vuejs.org/config/). ## Theming -# Sticker short codes - To enable sticker short codes, follow there steps: -* set "useShortCodeStickers" to true in config.json. -* Add your sticker pack folders (containing stickers) to /src/assets/stickers/ -* Create file /src/assets/stickers/order.txt that lists the folders names in order, one folder name per line. \ No newline at end of file +# Sticker short codes - To enable sticker short codes, follow these steps: +* Run the "create sticker config" script using "npm run create-sticker-config " +* Insert the resulting config blob into the "shortCodeStickers" value of the config file (assets/config.json) +* Rearrange order of sticker packs by editing the config blob above. \ No newline at end of file diff --git a/create_sticker_config.js b/create_sticker_config.js new file mode 100644 index 0000000..652f79a --- /dev/null +++ b/create_sticker_config.js @@ -0,0 +1,45 @@ +if (!process.argv[2]) { + console.log('Insufficient number of arguments! Need a path to sticker packs...'); +} + +var path = require('path'), fs = require('fs'); + +function fromDir(startPath, filter, callback) { + + //console.log('Starting from dir '+startPath+'/'); + + if (!fs.existsSync(startPath)) { + console.log("no dir ", startPath); + return; + } + + var files = fs.readdirSync(startPath); + for (var i = 0; i < files.length; i++) { + var filename = path.join(startPath, files[i]); + var stat = fs.lstatSync(filename); + if (stat.isDirectory()) { + fromDir(filename, filter, callback); //recurse + } + else if (filter.test(filename)) callback(filename); + }; +}; + +var packs = []; + +fromDir(process.argv[2], /\.png$/, function (filename) { + let file = filename.substring(process.argv[2].length); + let parts = file.split("/"); + let pack = parts[1]; + let sticker = parts[2]; + if (!packs[pack]) { + packs[pack] = []; + } + packs[pack].push(sticker); +}); + +var result = { baseUrl: "", packs: [] }; +for (const pack of Object.keys(packs)) { + const stickers = packs[pack]; + result.packs.push({ name: pack, stickers: stickers }); +} +console.log(JSON.stringify(result, null, 2)); \ No newline at end of file diff --git a/package.json b/package.json index 1a427d9..1685688 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "scripts": { "serve": "vue-cli-service serve", "build": "vue-cli-service build", - "lint": "vue-cli-service lint" + "lint": "vue-cli-service lint", + "create-sticker-config": "node ./create_sticker_config.js $1" }, "dependencies": { "aes-js": "^3.1.2", @@ -85,4 +86,4 @@ "last 2 versions", "not dead" ] -} +} \ No newline at end of file diff --git a/src/App.vue b/src/App.vue index 66dbc1a..7d2bc12 100644 --- a/src/App.vue +++ b/src/App.vue @@ -33,6 +33,8 @@