mirror of https://github.com/Requarks/wiki.git
10 changed files with 178 additions and 1093 deletions
Unified View
Diff Options
-
2client/js/app.js
-
21dev/config/tsconfig.json
-
178dev/fuse/index.js
-
125dev/fuse/tasks.js
-
56dev/tasks/localization.js
-
19package.json
-
8server/extensions/storage/disk.js
-
8server/extensions/storage/git.js
-
8server/master.js
-
846yarn.lock
@ -1,21 +0,0 @@ |
|||||
{ |
|
||||
"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" |
|
||||
] |
|
||||
} |
|
@ -1,178 +0,0 @@ |
|||||
'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 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.')) |
|
||||
return true |
|
||||
}).catch(err => { |
|
||||
console.error(colors.red(' X Bundle compilation failed! ' + err.message)) |
|
||||
process.exit(1) |
|
||||
}) |
|
||||
}) |
|
@ -1,125 +0,0 @@ |
|||||
/* 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 = { |
|
||||
/** |
|
||||
* Fetch Localization Resources from Lokalise |
|
||||
*/ |
|
||||
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' || _.includes(item.key, '::')) { return } |
|
||||
let keyParts = item.key.split(':') |
|
||||
let keyNamespace = (keyParts.length > 1) ? _.head(keyParts) : 'common' |
|
||||
let keyString = _.last(keyParts) |
|
||||
_.set(lang, `${keyNamespace}.${keyString}`, item.translation) |
|
||||
langTotal++ |
|
||||
}) |
|
||||
_.forOwn(lang, (langObject, langNamespace) => { |
|
||||
let langYaml = yaml.safeDump(langObject, { |
|
||||
indent: 2, |
|
||||
sortKeys: true, |
|
||||
lineWidth: 2048 |
|
||||
}) |
|
||||
fs.outputFileSync(path.join(process.cwd(), `server/locales/${langKey}/${langNamespace}.yml`), langYaml, 'utf8') |
|
||||
}) |
|
||||
console.info(colors.white(` ${langKey} - ${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') |
|
||||
} |
|
||||
} |
|
@ -0,0 +1,56 @@ |
|||||
|
const Promise = require('bluebird') |
||||
|
const colors = require('colors/safe') |
||||
|
const fs = Promise.promisifyAll(require('fs-extra')) |
||||
|
const path = require('path') |
||||
|
const request = require('request-promise') |
||||
|
const yaml = require('js-yaml') |
||||
|
const _ = require('lodash') |
||||
|
|
||||
|
const config = yaml.safeLoad(fs.readFileSync(path.join(process.cwd(), 'dev/config/config.yml'), 'utf8')) |
||||
|
|
||||
|
/** |
||||
|
* Fetch Localization Resources from Lokalise |
||||
|
*/ |
||||
|
const fetchLocalizationResources = async () => { |
||||
|
console.info(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' || _.includes(item.key, '::')) { return } |
||||
|
let keyParts = item.key.split(':') |
||||
|
let keyNamespace = (keyParts.length > 1) ? _.head(keyParts) : 'common' |
||||
|
let keyString = _.last(keyParts) |
||||
|
_.set(lang, `${keyNamespace}.${keyString}`, item.translation) |
||||
|
langTotal++ |
||||
|
}) |
||||
|
_.forOwn(lang, (langObject, langNamespace) => { |
||||
|
let langYaml = yaml.safeDump(langObject, { |
||||
|
indent: 2, |
||||
|
sortKeys: true, |
||||
|
lineWidth: 2048 |
||||
|
}) |
||||
|
fs.outputFileSync(path.join(process.cwd(), `server/locales/${langKey}/${langNamespace}.yml`), langYaml, 'utf8') |
||||
|
}) |
||||
|
console.info(colors.grey(`└─ ${langKey} - ${langTotal} keys written`)) |
||||
|
}) |
||||
|
} else { |
||||
|
throw new Error('Failed to fetch language list from Lokalise API.') |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
try { |
||||
|
fetchLocalizationResources() |
||||
|
} catch (err) { |
||||
|
console.error(colors.red(err)) |
||||
|
} |
@ -0,0 +1,8 @@ |
|||||
|
module.exports = { |
||||
|
activate() { |
||||
|
|
||||
|
}, |
||||
|
deactivate() { |
||||
|
|
||||
|
} |
||||
|
} |
@ -0,0 +1,8 @@ |
|||||
|
module.exports = { |
||||
|
activate() { |
||||
|
|
||||
|
}, |
||||
|
deactivate() { |
||||
|
|
||||
|
} |
||||
|
} |
846
yarn.lock
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
Write
Preview
Loading…
Cancel
Save