dev: refactoring + lokalise fetch + process

This commit is contained in:
NGPixel
2017-12-03 21:11:26 -05:00
parent 26e3e21005
commit e55c5805b4
95 changed files with 226 additions and 3344 deletions

15
dev/build/Dockerfile Normal file
View File

@@ -0,0 +1,15 @@
FROM node:8-alpine
LABEL maintainer="requarks.io"
RUN apk update && \
apk add bash curl git openssh supervisor --no-cache && \
mkdir -p /var/wiki
WORKDIR /var/wiki
COPY supervisord.conf /etc/supervisord.conf
COPY . /var/wiki
EXPOSE 3000
CMD ["supervisord", "--nodaemon", "-c", "/etc/supervisord.conf"]

View File

@@ -0,0 +1,23 @@
[unix_http_server]
file=/var/run/supervisor.sock
chmod=0700
[supervisord]
logfile=/logs/supervisord.log
pidfile=/var/run/supervisord.pid
childlogdir=/logs
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=unix:///var/run/supervisor.sock
[program:wikijs]
command = node server
autostart=true
autorestart=true
priority=5
directory=/var/wiki
stdout_logfile=/logs/wiki-stdout.log
stderr_logfile=/logs/wiki-stderr.log

View File

@@ -0,0 +1,16 @@
{
"disallowDuplicateAttributes": true,
"disallowIdAttributeWithStaticValue": true,
"disallowMultipleLineBreaks": true,
"requireClassLiteralsBeforeAttributes": true,
"requireIdLiteralsBeforeAttributes": true,
"requireLineFeedAtFileEnd": true,
"requireLowerCaseAttributes": true,
"requireLowerCaseTags": true,
"requireSpaceAfterCodeOperator": true,
"requireStrictEqualityOperators": true,
"validateAttributeQuoteMarks": "'",
"validateAttributeSeparator": ", ",
"validateDivTags": true,
"validateIndentation": 2
}

21
dev/config/tsconfig.json Normal file
View File

@@ -0,0 +1,21 @@
{
"compilerOptions": {
"allowJs": true,
"alwaysStrict": true,
"module": "commonjs",
"moduleResolution": "node",
"noImplicitAny": true,
"preserveConstEnums": true,
"removeComments": true,
"sourceMap": false,
"strictNullChecks": true,
"suppressImplicitAnyIndexErrors": true,
"target": "es5"
},
"exclude": [
".fusebox",
"data",
"node_modules",
"repo"
]
}

12
dev/docker/Dockerfile Normal file
View File

@@ -0,0 +1,12 @@
FROM requarks/wiki:latest
# Replace with your email address:
ENV WIKI_ADMIN_EMAIL admin@example.com
WORKDIR /var/wiki
# Replace your-config.yml with the path to your config file:
ADD your-config.yml config.yml
EXPOSE 3000
ENTRYPOINT [ "node", "server" ]

View File

@@ -0,0 +1,19 @@
version: '3'
services:
wikidb:
image: mongo
expose:
- '27017'
command: '--smallfiles --logpath=/dev/null'
volumes:
- ./data/mongo:/data/db
wikijs:
image: 'requarks/wiki:latest'
links:
- wikidb
ports:
- '80:3000'
environment:
WIKI_ADMIN_EMAIL: admin@example.com
volumes:
- ./config.yml:/var/wiki/config.yml

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1 @@
{"version":3,"sources":["scss/app.scss"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":""}

189
dev/fuse/index.js Normal file
View File

@@ -0,0 +1,189 @@
'use strict'
/**
* FUSEBOX
*
* Client & Server compiler / bundler / watcher
*/
const Promise = require('bluebird')
const autoprefixer = require('autoprefixer')
const colors = require('colors/safe')
const fsbx = require('fuse-box')
const nodemon = require('nodemon')
const fs = require('fs-extra')
const yargs = require('yargs')
const yaml = require('js-yaml')
const path = require('path')
// -------------------------------------------------------
// PARSE CMD ARGUMENTS
// -------------------------------------------------------
const opts = yargs
.option('d', {
alias: 'dev',
describe: 'Start in Developer mode',
type: 'boolean'
})
.option('b', {
alias: 'build',
describe: 'Start in Build mode',
type: 'boolean'
})
.help('h')
.alias('h', 'help')
.argv
if (opts.dev) {
console.info(colors.bgWhite.black(' Starting Wiki.js in DEVELOPER mode... '))
} else if (opts.build) {
console.info(colors.bgWhite.black(' Starting Wiki.js in BUILD mode... '))
} else {
yargs.showHelp()
process.exit(0)
}
// -------------------------------------------------------
// GET CONFIG
// -------------------------------------------------------
try {
const config = yaml.safeLoad(fs.readFileSync(path.join(process.cwd(), 'dev/config/config.yml'), 'utf8'))
global.config = config
} catch (ex) {
console.error(ex)
process.exit(1)
}
// -------------------------------------------------------
// BUILD VARS
// -------------------------------------------------------
const ALIASES = {
'brace-ext-modelist': 'brace/ext/modelist.js',
'simplemde': 'simplemde/dist/simplemde.min.js',
'vue': (opts.dev) ? 'vue/dist/vue.js' : 'vue/dist/vue.min.js',
'vue-lodash': 'vue-lodash/dist/vue-lodash.min.js',
'vue-resource': (opts.dev) ? 'vue-resource/dist/vue-resource.js' : 'vue-resource/dist/vue-resource.es2015.js'
}
const SHIMS = {
diff2html: {
source: '../../node_modules/diff2html/dist/diff2html.min.js',
exports: 'Diff2Html'
},
diff2htmlui: {
source: '../../node_modules/diff2html/dist/diff2html-ui.min.js',
exports: 'Diff2HtmlUI'
}
}
// -------------------------------------------------------
// Tasks
// -------------------------------------------------------
console.info(colors.white('└── ') + colors.green('Running tasks...'))
let tasks = require('./tasks')
let tasksToRun = []
tasksToRun.push(tasks.cleanFuseboxCache)
tasksToRun.push(tasks.copySimpleMdeAssets)
tasksToRun.push(tasks.copyAceModes)
if (opts.build) {
tasksToRun.push(tasks.cleanTestResults)
tasksToRun.push(tasks.fetchLocalizationResources)
}
// -------------------------------------------------------
// FUSEBOX PRODUCER
// -------------------------------------------------------
const babelrc = fs.readJsonSync('.babelrc')
const scssChain = [
fsbx.SassPlugin({
includePaths: ['node_modules'],
outputStyle: opts.dev ? 'nested' : 'compressed'
}),
fsbx.PostCSS([
autoprefixer({
remove: false,
browsers: babelrc.presets[0][1].targets.browsers
})
]),
fsbx.CSSPlugin(opts.dev ? {} : {
group: 'bundle.css',
outFile: './assets/css/bundle.css',
inject: false
})
]
Promise.mapSeries(tasksToRun, fn => fn()).then(() => {
let fuse = fsbx.FuseBox.init({
homeDir: '../../client',
output: '../../assets/js/$name.js',
alias: ALIASES,
target: 'browser',
tsConfig: '../config/tsconfig.json',
plugins: [
fsbx.EnvPlugin({ NODE_ENV: (opts.dev) ? 'development' : 'production' }),
fsbx.VueComponentPlugin({
script: fsbx.BabelPlugin(babelrc),
template: fsbx.ConsolidatePlugin({
engine: 'pug'
}),
style: scssChain
}),
scssChain,
fsbx.RawPlugin(['.svg']),
fsbx.BabelPlugin(babelrc),
fsbx.JSONPlugin()
],
debug: false,
log: true
})
// -------------------------------------------------------
// FUSEBOX DEV
// -------------------------------------------------------
if (opts.dev) {
fuse.dev({
port: 5555,
httpServer: false
})
}
// -------------------------------------------------------
// FUSEBOX BUNDLES
// -------------------------------------------------------
if (opts.dev) {
fuse.bundle('libs').shim(SHIMS).instructions('~ index.js')
fuse.bundle('app').instructions('!> [index.js]').hmr({ reload: true }).watch()
} else {
fuse.bundle('bundle.min.js').shim(SHIMS).instructions('> index.js')
}
// -------------------------------------------------------
// FUSEBOX RUN
// -------------------------------------------------------
fuse.run().then(() => {
console.info(colors.green.bold('\nAssets compilation + bundling completed.'))
if (opts.dev) {
nodemon({
exec: 'node server',
ignore: ['assets/', 'client/', 'data/', 'dev/', 'node_modules/', 'repo/', 'test/', 'test-results/'],
ext: 'js json graphql',
watch: ['server'],
env: { 'NODE_ENV': 'development' }
})
}
return true
}).catch(err => {
console.error(colors.red(' X Bundle compilation failed! ' + err.message))
process.exit(1)
})
})

118
dev/fuse/tasks.js Normal file
View File

@@ -0,0 +1,118 @@
/* global config */
const Promise = require('bluebird')
const colors = require('colors/safe')
const fs = Promise.promisifyAll(require('fs-extra'))
const path = require('path')
const uglify = require('uglify-es')
const request = require('request-promise')
const yaml = require('js-yaml')
const _ = require('lodash')
module.exports = {
async fetchLocalizationResources () {
console.info(colors.white(' └── ') + colors.green('Fetching latest localization resources...'))
let langs = await request({
method: 'POST',
uri: `${config.lokalise.api}/string/list`,
form: {
api_token: config.lokalise.key,
id: config.lokalise.project
},
json: true
})
if (langs && langs.strings && _.isPlainObject(langs.strings)) {
_.forIn(langs.strings, (langData, langKey) => {
let lang = {}
let langTotal = 0
langData.forEach(item => {
if (item.is_archived === '1') { return }
item.key = _.replace(item.key, '::', '.')
_.set(lang, item.key, item.translation)
langTotal++
})
let langYaml = yaml.safeDump(lang, {
indent: 2,
sortKeys: true,
lineWidth: 2048
})
fs.writeFileSync(path.join(process.cwd(), `server/locales/${langKey}.yml`), langYaml, 'utf8')
console.info(colors.white(` ${langKey}.yml - ${langTotal} keys written`))
})
} else {
throw new Error('Failed to fetch language list from Lokalise API.')
}
return true
},
/**
* SimpleMDE
*/
copySimpleMdeAssets () {
return fs.accessAsync('./assets/js/simplemde').then(() => {
console.info(colors.white(' └── ') + colors.magenta('SimpleMDE directory already exists. Task skipped.'))
return true
}).catch(err => {
if (err.code === 'ENOENT') {
console.info(colors.white(' └── ') + colors.green('Copy + Minify SimpleMDE to assets...'))
return fs.copy('./node_modules/simplemde/dist/simplemde.min.js', './assets/js/simplemde/simplemde.min.js')
} else {
throw err
}
})
},
/**
* ACE Modes
*/
copyAceModes () {
return fs.accessAsync('./assets/js/ace').then(() => {
console.info(colors.white(' └── ') + colors.magenta('ACE modes directory already exists. Task skipped.'))
return true
}).catch(err => {
if (err.code === 'ENOENT') {
console.info(colors.white(' └── ') + colors.green('Copy + Minify ACE modes to assets...'))
return fs.ensureDirAsync('./assets/js/ace').then(() => {
return Promise.join(
// Core
Promise.all([
fs.readFileAsync('./node_modules/brace/index.js', 'utf8'),
fs.readFileAsync('./node_modules/brace/ext/modelist.js', 'utf8'),
fs.readFileAsync('./node_modules/brace/theme/dawn.js', 'utf8'),
fs.readFileAsync('./node_modules/brace/theme/tomorrow_night.js', 'utf8'),
fs.readFileAsync('./node_modules/brace/mode/markdown.js', 'utf8')
]).then(items => {
console.info(colors.white(' ace.js'))
let result = uglify.minify(items.join(';\n'), { output: { 'max_line_len': 1000000 } })
return fs.writeFileAsync('./assets/js/ace/ace.js', result.code)
}),
// Modes
fs.readdirAsync('./node_modules/brace/mode').then(modeList => {
return Promise.map(modeList, mdFile => {
return fs.readFileAsync(path.join('./node_modules/brace/mode', mdFile), 'utf8').then(modeCode => {
console.info(colors.white(' mode-' + mdFile))
let result = uglify.minify(modeCode, { output: { 'max_line_len': 1000000 } })
return fs.writeFileAsync(path.join('./assets/js/ace', 'mode-' + mdFile), result.code)
})
}, { concurrency: 3 })
})
)
})
} else {
throw err
}
})
},
/**
* Delete Fusebox cache
*/
cleanFuseboxCache () {
console.info(colors.white(' └── ') + colors.green('Clearing fuse-box cache...'))
return fs.emptyDirAsync('./.fusebox')
},
/**
* Delete Test Results
*/
cleanTestResults () {
console.info(colors.white(' └── ') + colors.green('Clearing test results...'))
return fs.remove('./test-results')
}
}