Skip to content

Commit

Permalink
compile and download
Browse files Browse the repository at this point in the history
  • Loading branch information
Javey committed Aug 6, 2019
1 parent 2c54cc8 commit 7ac4afd
Show file tree
Hide file tree
Showing 8 changed files with 188 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
node_modules/
dist/
*.log
data/
data/themes/!(material)
.vscode/
28 changes: 27 additions & 1 deletion app/controllers/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const Fs = require('fs');
const fsExtra = require('fs-extra');
const shortId = require('shortid');
const getStylusVariables = require('../utils/getStylusVariables');
const Archiver = require('archiver');

const fs = Fs.promises;
const {Utils} = Advanced;
Expand Down Expand Up @@ -56,7 +57,7 @@ module.exports = Advanced.Controller.extend({
this._writeExtraStylus(`${component}.styl`, themePath, code),
]);

await this._compileToCss(id);
await this._compileToCss(_id);
},

async getCss() {
Expand All @@ -74,6 +75,31 @@ module.exports = Advanced.Controller.extend({
this._success({variables, code});
},

async download() {
const {id} = this.req.query;
if (!id) return this._error('theme id is required');

const path = `${Utils.c('theme')}/${id}`;
if (!await fsExtra.pathExists(path)) {
return this._error('theme id does not exist');
}

this.res.writeHead(200, {
'content-type': 'application/tar',
'content-disposition': `attachment; filename=${id}.tar`,
});

const tar = Archiver('tar');
tar.pipe(this.res);
tar.glob(`!(index).*`, {cwd: path})
.append(
(await fs.readFile(`${path}/index.styl`, 'utf-8'))
.replace('../../../node_modules/', '~'),
{name: 'index.styl'}
)
.finalize();
},

async _compileToCss(id) {
if (!id) return this._success({css: '', id});

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"license": "MIT",
"dependencies": {
"advanced": "^0.4.7",
"archiver": "^3.1.1",
"axios": "^0.19.0",
"fs-extra": "^8.1.0",
"happypack": "^5.0.1",
Expand Down
6 changes: 6 additions & 0 deletions src/pages/index/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import template from './index.vdt';
import './index.styl';
import components from '@/data/components';
import {api} from '@/request';
import Message from 'kpc/components/message';

window.qs = location.search.substring(1).split('&').reduce((acc, item) => {
const [key, value] = item.split('=');
Expand Down Expand Up @@ -93,6 +94,7 @@ export default class Index extends Intact {
if (id !== this.get('id')) {
history.pushState(null, null, `?id=${id}${location.hash}`);
this.set('id', id, {silent: true});
Message.success('主题已保存,请记住当前页面URL,以便下次修改');
}
this._dispachUpdateStyle(css);
});
Expand All @@ -103,4 +105,8 @@ export default class Index extends Intact {
const event = new CustomEvent('update:style', {detail: css});
window.dispatchEvent(event);
}

_download() {
window.open(`/api/download?id=${this.get('id')}`);
}
}
3 changes: 3 additions & 0 deletions src/pages/index/index.styl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ html
vertical-align middle
width 30px
margin-right 8px
.download
float right
margin-right 16px
.main-split
> .k-last
background #fff
Expand Down
6 changes: 6 additions & 0 deletions src/pages/index/index.vdt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ import CodePreview from '@/components/codePreview';
<img src={{ logo }} />
KPC主题定制工具
</div>
<div class="download">
<Button ghost circle ev-click={{ self._download }} disabled={{ !self.get('id') }}>
<Icon size="large" class="ion-ios-cloud-download-outline" />
下载主题
</Button>
</div>
</Header>
<Layout>
<Aside fixed>
Expand Down
3 changes: 2 additions & 1 deletion src/pages/opera/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import template from './index.vdt';
import './index.styl';
import {api} from '@/request';

const req = require.context('kpc-demo', true, /^\.\/components\/(?!(code|tabs))\w+\/demos\/.*index\.js$/);
const req = require.context('kpc-demo', true, /^\.\/components\/(?!(code))\w+\/demos\/.*index\.js$/);
const style = document.createElement('style');
document.head.appendChild(style);
const update = (css) => {
if (!css) return;
const stylesheet = document.getElementById('stylesheet');
if (stylesheet) {
stylesheet.parentNode.removeChild(stylesheet);
Expand Down
146 changes: 142 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,35 @@ aproba@^1.0.3, aproba@^1.1.1:
resolved "https://registry.yarnpkg.com/aproba/-/aproba-1.2.0.tgz#6802e6264efd18c790a1b0d517f0f2627bf2c94a"
integrity sha512-Y9J6ZjXtoYh8RnXVCMOU/ttDmk1aBjunq9vO0ta5x85WDQiQfUF9sIPBITdbiiIVcBo03Hi3jMxigBtsddlXRw==

archiver-utils@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/archiver-utils/-/archiver-utils-2.1.0.tgz#e8a460e94b693c3e3da182a098ca6285ba9249e2"
integrity sha512-bEL/yUb/fNNiNTuUz979Z0Yg5L+LzLxGJz8x79lYmR54fmTIb6ob/hNQgkQnIUDWIFjZVQwl9Xs356I6BAMHfw==
dependencies:
glob "^7.1.4"
graceful-fs "^4.2.0"
lazystream "^1.0.0"
lodash.defaults "^4.2.0"
lodash.difference "^4.5.0"
lodash.flatten "^4.4.0"
lodash.isplainobject "^4.0.6"
lodash.union "^4.6.0"
normalize-path "^3.0.0"
readable-stream "^2.0.0"

archiver@^3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/archiver/-/archiver-3.1.1.tgz#9db7819d4daf60aec10fe86b16cb9258ced66ea0"
integrity sha512-5Hxxcig7gw5Jod/8Gq0OneVgLYET+oNHcxgWItq4TbhOzRLKNAFUb9edAftiMKXvXfCB0vbGrJdZDNq0dWMsxg==
dependencies:
archiver-utils "^2.1.0"
async "^2.6.3"
buffer-crc32 "^0.2.1"
glob "^7.1.4"
readable-stream "^3.4.0"
tar-stream "^2.1.0"
zip-stream "^2.1.2"

are-we-there-yet@~1.1.2:
version "1.1.5"
resolved "https://registry.yarnpkg.com/are-we-there-yet/-/are-we-there-yet-1.1.5.tgz#4b35c2944f062a8bfcda66410760350fe9ddfc21"
Expand Down Expand Up @@ -1144,6 +1173,13 @@ async@^1.5.2:
resolved "https://registry.yarnpkg.com/async/-/async-1.5.2.tgz#ec6a61ae56480c0c3cb241c95618e20892f9672a"
integrity sha1-7GphrlZIDAw8skHJVhjiCJL5Zyo=

async@^2.6.3:
version "2.6.3"
resolved "https://registry.yarnpkg.com/async/-/async-2.6.3.tgz#d72625e2344a3656e3a3ad4fa749fa83299d82ff"
integrity sha512-zflvls11DCy+dQWzTW2dzuilv8Z5X/pjfmZOWba6TNIVDm+2UDaJmXSOXlasHKfNBs8oo3M0aT50fDEWfKZjXg==
dependencies:
lodash "^4.17.14"

asynckit@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"
Expand Down Expand Up @@ -1246,6 +1282,13 @@ binary-extensions@^1.0.0:
resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-1.13.1.tgz#598afe54755b2868a5330d2aff9d4ebb53209b65"
integrity sha512-Un7MIEDdUC5gNpcGDV97op1Ywk748MpHcFTHoYs6qnj1Z3j7I53VG3nwZhKzoBZmbdRNnb6WRdFlwl7tSDuZGw==

bl@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/bl/-/bl-3.0.0.tgz#3611ec00579fd18561754360b21e9f784500ff88"
integrity sha512-EUAyP5UHU5hxF8BPT0LKW8gjYLhq1DQIcneOX/pL/m2Alo+OYDQAJlHq+yseMP50Os2nHXOSic6Ss3vSQeyf4A==
dependencies:
readable-stream "^3.0.1"

bluebird@^2.9.25:
version "2.11.0"
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-2.11.0.tgz#534b9033c022c9579c56ba3b3e5a5caafbb650e1"
Expand Down Expand Up @@ -1391,6 +1434,11 @@ browserslist@^4.6.0, browserslist@^4.6.2:
electron-to-chromium "^1.3.191"
node-releases "^1.1.25"

buffer-crc32@^0.2.1, buffer-crc32@^0.2.13:
version "0.2.13"
resolved "https://registry.yarnpkg.com/buffer-crc32/-/buffer-crc32-0.2.13.tgz#0d333e3f00eac50aa1454abd30ef8c2a5d9a7242"
integrity sha1-DTM+PwDqxQqhRUq9MO+MKl2ackI=

buffer-from@^1.0.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.1.tgz#32713bc028f75c02fdb710d7c7bcec1f2c6070ef"
Expand All @@ -1415,6 +1463,14 @@ buffer@^4.3.0:
ieee754 "^1.1.4"
isarray "^1.0.0"

buffer@^5.1.0:
version "5.2.1"
resolved "https://registry.yarnpkg.com/buffer/-/buffer-5.2.1.tgz#dd57fa0f109ac59c602479044dca7b8b3d0b71d6"
integrity sha512-c+Ko0loDaFfuPWiL02ls9Xd3GO3cPVmUobQ6t3rXNUk304u6hGq+8N/kFi+QEIKhzK3uwolVhLzszmfLmMLnqg==
dependencies:
base64-js "^1.0.2"
ieee754 "^1.1.4"

builtin-status-codes@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/builtin-status-codes/-/builtin-status-codes-3.0.0.tgz#85982878e21b98e1c66425e03d0174788f569ee8"
Expand Down Expand Up @@ -1645,6 +1701,16 @@ component-emitter@^1.2.1:
resolved "https://registry.yarnpkg.com/component-emitter/-/component-emitter-1.3.0.tgz#16e4070fba8ae29b679f2215853ee181ab2eabc0"
integrity sha512-Rd3se6QB+sO1TwqZjscQrurpEPIfO0/yYnSin6Q/rD3mOutHvUrCAhJub3r90uNb+SESBuE0QYoB90YdfatsRg==

compress-commons@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/compress-commons/-/compress-commons-2.1.1.tgz#9410d9a534cf8435e3fbbb7c6ce48de2dc2f0610"
integrity sha512-eVw6n7CnEMFzc3duyFVrQEuY1BlHR3rYsSztyG32ibGMW722i3C6IizEGMFmfMU+A+fALvBIwxN3czffTcdA+Q==
dependencies:
buffer-crc32 "^0.2.13"
crc32-stream "^3.0.1"
normalize-path "^3.0.0"
readable-stream "^2.3.6"

compressible@~2.0.16:
version "2.0.17"
resolved "https://registry.yarnpkg.com/compressible/-/compressible-2.0.17.tgz#6e8c108a16ad58384a977f3a482ca20bff2f38c1"
Expand Down Expand Up @@ -1785,6 +1851,21 @@ [email protected], core-util-is@~1.0.0:
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
integrity sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=

crc32-stream@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/crc32-stream/-/crc32-stream-3.0.1.tgz#cae6eeed003b0e44d739d279de5ae63b171b4e85"
integrity sha512-mctvpXlbzsvK+6z8kJwSJ5crm7yBwrQMTybJzMw1O4lLGJqjlDCXY2Zw7KheiA6XBEcBmfLx1D88mjRGVJtY9w==
dependencies:
crc "^3.4.4"
readable-stream "^3.4.0"

crc@^3.4.4:
version "3.8.0"
resolved "https://registry.yarnpkg.com/crc/-/crc-3.8.0.tgz#ad60269c2c856f8c299e2c4cc0de4556914056c6"
integrity sha512-iX3mfgcTMIq3ZKLIsVFAbv7+Mc10kxabAGQb8HvjA1o3T1PIYprbakQ65d3I+2HGHt6nSKkM9PYjgoJO2KcFBQ==
dependencies:
buffer "^5.1.0"

create-ecdh@^4.0.0:
version "4.0.3"
resolved "https://registry.yarnpkg.com/create-ecdh/-/create-ecdh-4.0.3.tgz#c9111b6f33045c4697f144787f9254cdc77c45ff"
Expand Down Expand Up @@ -2281,7 +2362,7 @@ encodeurl@~1.0.2:
resolved "https://registry.yarnpkg.com/encodeurl/-/encodeurl-1.0.2.tgz#ad3ff4c86ec2d029322f5a02c3a9a606c95b3f59"
integrity sha1-rT/0yG7C0CkyL1oCw6mmBslbP1k=

end-of-stream@^1.0.0, end-of-stream@^1.1.0:
end-of-stream@^1.0.0, end-of-stream@^1.1.0, end-of-stream@^1.4.1:
version "1.4.1"
resolved "https://registry.yarnpkg.com/end-of-stream/-/end-of-stream-1.4.1.tgz#ed29634d19baba463b6ce6b80a37213eab71ec43"
integrity sha512-1MkrZNvWTKCaigbn+W15elq2BB/L22nqrSY5DKlo3X6+vclJm8Bb5djXJBmEX6fS3+zCh/F4VBK5Z2KxJt4s2Q==
Expand Down Expand Up @@ -2727,6 +2808,11 @@ from2@^2.1.0:
inherits "^2.0.1"
readable-stream "^2.0.0"

fs-constants@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/fs-constants/-/fs-constants-1.0.0.tgz#6be0de9be998ce16af8afc24497b9ee9b7ccd9ad"
integrity sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==

fs-extra@^0.26.7:
version "0.26.7"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-0.26.7.tgz#9ae1fdd94897798edab76d0918cf42d0c3184fa9"
Expand Down Expand Up @@ -3723,6 +3809,13 @@ kpc@^1.0.1:
monaco-editor "^0.17.0"
resize-observer-polyfill "^1.5.0"

lazystream@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/lazystream/-/lazystream-1.0.0.tgz#f6995fe0f820392f61396be89462407bb77168e4"
integrity sha1-9plf4PggOS9hOWvolGJAe7dxaOQ=
dependencies:
readable-stream "^2.0.5"

lcid@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/lcid/-/lcid-2.0.0.tgz#6ef5d2df60e52f82eb228a4c373e8d1f397253cf"
Expand Down Expand Up @@ -3784,12 +3877,37 @@ lodash.clonedeep@^4.5.0:
resolved "https://registry.yarnpkg.com/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz#e23f3f9c4f8fbdde872529c1071857a086e5ccef"
integrity sha1-4j8/nE+Pvd6HJSnBBxhXoIblzO8=

lodash.defaults@^4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/lodash.defaults/-/lodash.defaults-4.2.0.tgz#d09178716ffea4dde9e5fb7b37f6f0802274580c"
integrity sha1-0JF4cW/+pN3p5ft7N/bwgCJ0WAw=

lodash.difference@^4.5.0:
version "4.5.0"
resolved "https://registry.yarnpkg.com/lodash.difference/-/lodash.difference-4.5.0.tgz#9ccb4e505d486b91651345772885a2df27fd017c"
integrity sha1-nMtOUF1Ia5FlE0V3KIWi3yf9AXw=

lodash.flatten@^4.4.0:
version "4.4.0"
resolved "https://registry.yarnpkg.com/lodash.flatten/-/lodash.flatten-4.4.0.tgz#f31c22225a9632d2bbf8e4addbef240aa765a61f"
integrity sha1-8xwiIlqWMtK7+OSt2+8kCqdlph8=

lodash.isplainobject@^4.0.6:
version "4.0.6"
resolved "https://registry.yarnpkg.com/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz#7c526a52d89b45c45cc690b88163be0497f550cb"
integrity sha1-fFJqUtibRcRcxpC4gWO+BJf1UMs=

[email protected]:
version "4.0.1"
resolved "https://registry.yarnpkg.com/lodash.unescape/-/lodash.unescape-4.0.1.tgz#bf2249886ce514cda112fae9218cdc065211fc9c"
integrity sha1-vyJJiGzlFM2hEvrpIYzcBlIR/Jw=

lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.13, lodash@^4.17.15, lodash@^4.17.3:
lodash.union@^4.6.0:
version "4.6.0"
resolved "https://registry.yarnpkg.com/lodash.union/-/lodash.union-4.6.0.tgz#48bb5088409f16f1821666641c44dd1aaae3cd88"
integrity sha1-SLtQiECfFvGCFmZkHETdGqrjzYg=

lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.3:
version "4.17.15"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548"
integrity sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==
Expand Down Expand Up @@ -4985,7 +5103,7 @@ rc@^1.2.7:
minimist "^1.2.0"
strip-json-comments "~2.0.1"

"readable-stream@1 || 2", readable-stream@^2.0.0, readable-stream@^2.0.1, readable-stream@^2.0.2, readable-stream@^2.0.6, readable-stream@^2.1.5, readable-stream@^2.2.2, readable-stream@^2.3.3, readable-stream@^2.3.6, readable-stream@~2.3.6:
"readable-stream@1 || 2", readable-stream@^2.0.0, readable-stream@^2.0.1, readable-stream@^2.0.2, readable-stream@^2.0.5, readable-stream@^2.0.6, readable-stream@^2.1.5, readable-stream@^2.2.2, readable-stream@^2.3.3, readable-stream@^2.3.6, readable-stream@~2.3.6:
version "2.3.6"
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.3.6.tgz#b11c27d88b8ff1fbe070643cf94b0c79ae1b0aaf"
integrity sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==
Expand All @@ -4998,7 +5116,7 @@ rc@^1.2.7:
string_decoder "~1.1.1"
util-deprecate "~1.0.1"

readable-stream@^3.0.6, readable-stream@^3.1.1:
readable-stream@^3.0.1, readable-stream@^3.0.6, readable-stream@^3.1.1, readable-stream@^3.4.0:
version "3.4.0"
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-3.4.0.tgz#a51c26754658e0a3c21dbf59163bd45ba6f447fc"
integrity sha512-jItXPLmrSR8jmTRmRWJXCnGJsfy85mB3Wd/uINMXA65yrnFo0cPClFIUWzo2najVNSl+mx7/4W8ttlLWJe99pQ==
Expand Down Expand Up @@ -5798,6 +5916,17 @@ tapable@^1.0.0, tapable@^1.1.0:
resolved "https://registry.yarnpkg.com/tapable/-/tapable-1.1.3.tgz#a1fccc06b58db61fd7a45da2da44f5f3a3e67ba2"
integrity sha512-4WK/bYZmj8xLr+HUCODHGF1ZFzsYffasLUgEiMBY4fgtltdO6B4WJtlSbPaDTLpYTcGVwM2qLnFTICEcNxs3kA==

tar-stream@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/tar-stream/-/tar-stream-2.1.0.tgz#d1aaa3661f05b38b5acc9b7020efdca5179a2cc3"
integrity sha512-+DAn4Nb4+gz6WZigRzKEZl1QuJVOLtAwwF+WUxy1fJ6X63CaGaUAxJRD2KEn1OMfcbCjySTYpNC6WmfQoIEOdw==
dependencies:
bl "^3.0.0"
end-of-stream "^1.4.1"
fs-constants "^1.0.0"
inherits "^2.0.3"
readable-stream "^3.1.1"

tar@^4:
version "4.4.10"
resolved "https://registry.yarnpkg.com/tar/-/tar-4.4.10.tgz#946b2810b9a5e0b26140cf78bea6b0b0d689eba1"
Expand Down Expand Up @@ -6486,3 +6615,12 @@ [email protected]:
which-module "^2.0.0"
y18n "^4.0.0"
yargs-parser "^13.1.0"

zip-stream@^2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/zip-stream/-/zip-stream-2.1.2.tgz#841efd23214b602ff49c497cba1a85d8b5fbc39c"
integrity sha512-ykebHGa2+uzth/R4HZLkZh3XFJzivhVsjJt8bN3GvBzLaqqrUdRacu+c4QtnUgjkkQfsOuNE1JgLKMCPNmkKgg==
dependencies:
archiver-utils "^2.1.0"
compress-commons "^2.1.1"
readable-stream "^3.4.0"

0 comments on commit 7ac4afd

Please sign in to comment.