├── .editorconfig
├── .gitattributes
├── .github
└── workflows
│ └── main.yml
├── .gitignore
├── fixture.html
├── fixture.js
├── index.js
├── license
├── package.json
└── readme.md
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | indent_style = tab
5 | end_of_line = lf
6 | charset = utf-8
7 | trim_trailing_whitespace = true
8 | insert_final_newline = true
9 |
10 | [{package.json,*.yml}]
11 | indent_style = space
12 | indent_size = 2
13 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | * text=auto
2 | *.js text eol=lf
3 |
--------------------------------------------------------------------------------
/.github/workflows/main.yml:
--------------------------------------------------------------------------------
1 | name: CI
2 | on:
3 | - push
4 | - pull_request
5 | jobs:
6 | test:
7 | name: Node.js ${{ matrix.node-version }}
8 | runs-on: ubuntu-latest
9 | strategy:
10 | fail-fast: false
11 | matrix:
12 | node-version: []
13 | steps:
14 | - uses: actions/checkout@v2
15 | - uses: actions/setup-node@v1
16 | with:
17 | node-version: ${{ matrix.node-version }}
18 | - run: npm install
19 | - run: npm test
20 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 |
--------------------------------------------------------------------------------
/fixture.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | test
5 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/fixture.js:
--------------------------------------------------------------------------------
1 | if (true) {
2 | console.log('foo');
3 | }
4 |
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | /** @babel */
2 | import {CompositeDisposable} from 'atom';
3 | import {allowUnsafeNewFunction} from 'loophole';
4 |
5 | let uglify;
6 | allowUnsafeNewFunction(() => {
7 | uglify = require('uglify-js');
8 | });
9 |
10 | function init(editor) {
11 | const selectedText = editor.getSelectedText();
12 | const text = selectedText || editor.getText();
13 | let retText = '';
14 |
15 | try {
16 | allowUnsafeNewFunction(() => {
17 | retText = uglify.minify(text, {
18 | fromString: true,
19 | mangle: atom.config.get('uglify.mangle')
20 | }).code;
21 | });
22 | } catch (err) {
23 | console.error(err);
24 | atom.notifications.addError('Uglify', {detail: err.message});
25 | return;
26 | }
27 |
28 | const cursorPosition = editor.getCursorBufferPosition();
29 | const line = atom.views.getView(editor).getFirstVisibleScreenRow() +
30 | editor.getVerticalScrollMargin();
31 |
32 | if (selectedText) {
33 | editor.setTextInBufferRange(editor.getSelectedBufferRange(), retText);
34 | } else {
35 | editor.getBuffer().setTextViaDiff(retText);
36 | }
37 |
38 | editor.setCursorBufferPosition(cursorPosition);
39 |
40 | if (editor.getScreenLineCount() > line) {
41 | editor.scrollToScreenPosition([line, 0]);
42 | }
43 | }
44 |
45 | export const config = {
46 | mangle: {
47 | type: 'boolean',
48 | default: true
49 | }
50 | };
51 |
52 | export function deactivate() {
53 | this.subscriptions.dispose();
54 | }
55 |
56 | export function activate() {
57 | this.subscriptions = new CompositeDisposable();
58 |
59 | this.subscriptions.add(atom.commands.add('atom-workspace', 'uglify', () => {
60 | const editor = atom.workspace.getActiveTextEditor();
61 |
62 | if (editor) {
63 | init(editor);
64 | }
65 | }));
66 | }
67 |
--------------------------------------------------------------------------------
/license:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) Sindre Sorhus (sindresorhus.com)
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | THE SOFTWARE.
22 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "uglify",
3 | "version": "1.3.1",
4 | "description": "Minify JavaScript",
5 | "license": "MIT",
6 | "repository": "sindresorhus/atom-uglify",
7 | "author": {
8 | "name": "Sindre Sorhus",
9 | "email": "sindresorhus@gmail.com",
10 | "url": "sindresorhus.com"
11 | },
12 | "private": true,
13 | "engines": {
14 | "atom": ">=1.13.0"
15 | },
16 | "scripts": {
17 | "test": "xo"
18 | },
19 | "keywords": [
20 | "javascript",
21 | "minify",
22 | "compress",
23 | "uglify"
24 | ],
25 | "dependencies": {
26 | "loophole": "^1.1.0",
27 | "uglify-js": "^2.5.0"
28 | },
29 | "devDependencies": {
30 | "xo": "*"
31 | },
32 | "activationCommands": {
33 | "atom-workspace": "uglify"
34 | },
35 | "xo": {
36 | "esnext": true,
37 | "globals": [
38 | "atom"
39 | ]
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | # Uglify
2 |
3 | > Minify JavaScript with [Uglify](https://github.com/mishoo/UglifyJS2)
4 |
5 |
6 | ## Install
7 |
8 | ```
9 | $ apm install uglify
10 | ```
11 |
12 | Or Settings → Install → Search for `uglify`
13 |
14 |
15 | ## Usage
16 |
17 | Open the Command Palette, and type `uglify`.
18 |
19 | Can also minify just a selection. For example the code in a `