├── .editorconfig ├── .ember-cli ├── .gitignore ├── .travis.yml ├── LICENSE.md ├── README.md ├── addon └── .gitkeep ├── app └── .gitkeep ├── config ├── ember-try.js └── environment.js ├── ember-cli-build.js ├── index.js ├── lib ├── components.js └── config.js ├── package-lock.json ├── package.json ├── testem.js ├── tests ├── .eslintrc.js ├── dummy │ ├── app │ │ ├── app.js │ │ ├── components │ │ │ └── .gitkeep │ │ ├── controllers │ │ │ └── .gitkeep │ │ ├── helpers │ │ │ └── .gitkeep │ │ ├── index.html │ │ ├── models │ │ │ └── .gitkeep │ │ ├── resolver.js │ │ ├── router.js │ │ ├── routes │ │ │ └── .gitkeep │ │ ├── styles │ │ │ └── app.css │ │ └── templates │ │ │ ├── application.hbs │ │ │ └── components │ │ │ └── .gitkeep │ ├── config │ │ ├── environment.js │ │ └── targets.js │ └── public │ │ ├── crossdomain.xml │ │ └── robots.txt ├── helpers │ ├── destroy-app.js │ ├── module-for-acceptance.js │ ├── resolver.js │ └── start-app.js ├── index.html ├── integration │ └── .gitkeep ├── test-helper.js └── unit │ └── .gitkeep └── vendor └── .gitkeep /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig helps developers define and maintain consistent 2 | # coding styles between different editors and IDEs 3 | # editorconfig.org 4 | 5 | root = true 6 | 7 | 8 | [*] 9 | end_of_line = lf 10 | charset = utf-8 11 | trim_trailing_whitespace = true 12 | insert_final_newline = true 13 | indent_style = space 14 | indent_size = 2 15 | 16 | [*.hbs] 17 | insert_final_newline = false 18 | 19 | [*.{diff,md}] 20 | trim_trailing_whitespace = false 21 | -------------------------------------------------------------------------------- /.ember-cli: -------------------------------------------------------------------------------- 1 | { 2 | /** 3 | Ember CLI sends analytics information by default. The data is completely 4 | anonymous, but there are times when you might want to disable this behavior. 5 | 6 | Setting `disableAnalytics` to true will prevent any data from being sent. 7 | */ 8 | "disableAnalytics": false 9 | } 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | 7 | # dependencies 8 | /node_modules 9 | /bower_components 10 | 11 | # misc 12 | /.sass-cache 13 | /connect.lock 14 | /coverage/* 15 | /libpeerconnection.log 16 | npm-debug.log* 17 | yarn-error.log 18 | testem.log 19 | 20 | # ember-try 21 | .node_modules.ember-try/ 22 | bower.json.ember-try 23 | package.json.ember-try 24 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | language: node_js 3 | node_js: 4 | - "4" 5 | 6 | sudo: false 7 | 8 | cache: 9 | directories: 10 | - $HOME/.npm 11 | 12 | env: 13 | # we recommend testing LTS's and latest stable release (bonus points to beta/canary) 14 | - EMBER_TRY_SCENARIO=ember-lts-2.4 15 | - EMBER_TRY_SCENARIO=ember-lts-2.8 16 | - EMBER_TRY_SCENARIO=ember-release 17 | - EMBER_TRY_SCENARIO=ember-beta 18 | - EMBER_TRY_SCENARIO=ember-canary 19 | - EMBER_TRY_SCENARIO=ember-default 20 | 21 | matrix: 22 | fast_finish: true 23 | allow_failures: 24 | - env: EMBER_TRY_SCENARIO=ember-canary 25 | 26 | before_install: 27 | - npm config set spin false 28 | - npm install -g phantomjs-prebuilt 29 | - phantomjs --version 30 | 31 | install: 32 | - npm install 33 | 34 | script: 35 | # Usually, it's ok to finish the test scenario without reverting 36 | # to the addon's original dependency state, skipping "cleanup". 37 | - node_modules/.bin/ember try:one $EMBER_TRY_SCENARIO test --skip-cleanup 38 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ember-clean-project 2 | 3 | An ember addon to find unused components, css classes etc. 4 | 5 | ## Installation 6 | 7 | ember install ember-clean-project 8 | 9 | ## Running 10 | 11 | ```sh 12 | ember clear:components 13 | ``` 14 | 15 | You can add folowing parameters: 16 | - `--force-delete` - Deletes the unused components, but copies a backup in /ember-clean-project/backup-components folder (default: false) 17 | 18 | ## Config 19 | 20 | When running the ember clear command, it is checked whether a config is exept, if not one is created. 21 | 22 | ```javascript 23 | { 24 | "componentFolderPath": "./app/components" 25 | } 26 | ``` 27 | 28 | You can add folowing parameters: 29 | - `componentFolderPath` - Sets the component folder. If no pod structure is used the folder must be set by the comp-name.js data are set. 30 | 31 | ## Running Tests 32 | 33 | * `npm test` (Runs `ember try:each` to test your addon against multiple Ember versions) 34 | * `ember test` 35 | * `ember test --server` 36 | 37 | For more information on using ember-cli, visit [https://ember-cli.com/](https://ember-cli.com/). 38 | -------------------------------------------------------------------------------- /addon/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaxCodeDE/ember-clean-project/b2a9266c3baa607f0fe2b203213309d993563af4/addon/.gitkeep -------------------------------------------------------------------------------- /app/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaxCodeDE/ember-clean-project/b2a9266c3baa607f0fe2b203213309d993563af4/app/.gitkeep -------------------------------------------------------------------------------- /config/ember-try.js: -------------------------------------------------------------------------------- 1 | /* eslint-env node */ 2 | module.exports = { 3 | scenarios: [ 4 | { 5 | name: 'ember-lts-2.4', 6 | bower: { 7 | dependencies: { 8 | 'ember': 'components/ember#lts-2-4' 9 | }, 10 | resolutions: { 11 | 'ember': 'lts-2-4' 12 | } 13 | }, 14 | npm: { 15 | devDependencies: { 16 | 'ember-source': null 17 | } 18 | } 19 | }, 20 | { 21 | name: 'ember-lts-2.8', 22 | bower: { 23 | dependencies: { 24 | 'ember': 'components/ember#lts-2-8' 25 | }, 26 | resolutions: { 27 | 'ember': 'lts-2-8' 28 | } 29 | }, 30 | npm: { 31 | devDependencies: { 32 | 'ember-source': null 33 | } 34 | } 35 | }, 36 | { 37 | name: 'ember-release', 38 | bower: { 39 | dependencies: { 40 | 'ember': 'components/ember#release' 41 | }, 42 | resolutions: { 43 | 'ember': 'release' 44 | } 45 | }, 46 | npm: { 47 | devDependencies: { 48 | 'ember-source': null 49 | } 50 | } 51 | }, 52 | { 53 | name: 'ember-beta', 54 | bower: { 55 | dependencies: { 56 | 'ember': 'components/ember#beta' 57 | }, 58 | resolutions: { 59 | 'ember': 'beta' 60 | } 61 | }, 62 | npm: { 63 | devDependencies: { 64 | 'ember-source': null 65 | } 66 | } 67 | }, 68 | { 69 | name: 'ember-canary', 70 | bower: { 71 | dependencies: { 72 | 'ember': 'components/ember#canary' 73 | }, 74 | resolutions: { 75 | 'ember': 'canary' 76 | } 77 | }, 78 | npm: { 79 | devDependencies: { 80 | 'ember-source': null 81 | } 82 | } 83 | }, 84 | { 85 | name: 'ember-default', 86 | npm: { 87 | devDependencies: {} 88 | } 89 | } 90 | ] 91 | }; 92 | -------------------------------------------------------------------------------- /config/environment.js: -------------------------------------------------------------------------------- 1 | /* eslint-env node */ 2 | 'use strict'; 3 | 4 | module.exports = function(/* environment, appConfig */) { 5 | return { }; 6 | }; 7 | -------------------------------------------------------------------------------- /ember-cli-build.js: -------------------------------------------------------------------------------- 1 | /* eslint-env node */ 2 | 'use strict'; 3 | 4 | const EmberAddon = require('ember-cli/lib/broccoli/ember-addon'); 5 | 6 | module.exports = function(defaults) { 7 | let app = new EmberAddon(defaults, { 8 | // Add options here 9 | }); 10 | 11 | /* 12 | This build file specifies the options for the dummy test app of this 13 | addon, located in `/tests/dummy` 14 | This build file does *not* influence how the addon or the app using it 15 | behave. You most likely want to be modifying `./index.js` or app's build file 16 | */ 17 | 18 | return app.toTree(); 19 | }; 20 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /* eslint-env node */ 2 | 'use strict'; 3 | 4 | const component = require('./lib/components'); 5 | const config = require('./lib/config'); 6 | 7 | module.exports = { 8 | name: 'ember-clean-project', 9 | includedCommands: function() { 10 | return { 11 | cleanComponentsCommand: { 12 | name: 'clear:components', 13 | description: 'Shows unused components', 14 | run: function(commandOptions, rawArgs) { 15 | console.log('TEST ' + commandOptions.forceDelete); 16 | config.createConfig(); 17 | component.clearComponents(config, commandOptions.forceDelete); 18 | } 19 | }, 20 | cleanCssCommand: { 21 | name: 'clear:css', 22 | description: 'A test command that says hello', 23 | availableOptions: [{ 24 | name: 'format', 25 | type: String, 26 | default: 'lowercase', 27 | aliases: ['f'] 28 | }], 29 | run: function(commandOptions, rawArgs) { 30 | if (commandOptions.format === 'uppercase') { 31 | console.log('HELLO!'); 32 | } else { 33 | console.log('hello!'); 34 | } 35 | } 36 | } 37 | } 38 | } 39 | }; -------------------------------------------------------------------------------- /lib/components.js: -------------------------------------------------------------------------------- 1 | //const fs = require('fs'); 2 | const fs = require('fs-extra') 3 | const path = require('path'); 4 | const colors = require('colors'); 5 | 6 | var config = null; 7 | var appPath = "./app/"; 8 | var components = null; 9 | 10 | module.exports = { 11 | clearComponents(configModule, forceDelete) { 12 | config = configModule; 13 | console.log('Sart searching for unused components...'.green); 14 | console.log(' '); 15 | console.log(' '); 16 | // Setup Addon -> Get all components 17 | this.setup(); 18 | // Start searching 19 | this.checkUnusedComponents(appPath); 20 | // Log all unused components 21 | this.logUnusedComponentResult(components); 22 | if (forceDelete) { 23 | this.deleteUnusedComponents(components); 24 | } 25 | }, 26 | checkUnusedComponents(appPath) { 27 | var files = fs.readdirSync(appPath); 28 | files.forEach((item, index, array) => { 29 | var filename = path.join(appPath, files[index]); 30 | var stat = fs.lstatSync(filename); 31 | if (stat.isDirectory()) { 32 | this.checkUnusedComponents(filename); 33 | } else { 34 | if (filename.includes('.hbs') || filename.includes('.js')) { 35 | this.checkFileForComponent(filename); 36 | } 37 | } 38 | }); 39 | }, 40 | checkFileForComponent(filename) { 41 | var data = fs.readFileSync(filename, "utf8"); 42 | components.forEach((item, index) => { 43 | if (data.indexOf(item) >= 0) { 44 | //console.log(item + ' in ' + filename); 45 | delete components[index]; 46 | } 47 | }); 48 | }, 49 | setup() { 50 | components = fs.readdirSync(config.getConfigPropertyComponentFolderPath()); 51 | components.forEach((item, index, array) => { 52 | array[index] = item.replace('.hbs', ''); 53 | array[index] = item.replace('.js', ''); 54 | }); 55 | this.logComponents(components); 56 | }, 57 | logComponents(components) { 58 | console.log('Found components: '.grey + components.toString().grey); 59 | console.log(' '); 60 | }, 61 | logUnusedComponentResult(components) { 62 | components.forEach((item) => { 63 | console.log(`Unused component -> ${item}`.red); 64 | }); 65 | }, 66 | deleteUnusedComponents(components) { 67 | components.forEach((item) => { 68 | fs.copy(config.getConfigPropertyComponentFolderPath() + `/${item}`, config.getConfigPath() + `/backup-components/${item}`, (copyError) => { 69 | if (copyError) return console.error(copyError) 70 | fs.remove(config.getConfigPropertyComponentFolderPath() + `/${item}`, (removeError) => { 71 | if (removeError) return console.error(removeError); 72 | }) 73 | }); 74 | }); 75 | console.log('All unused components have been deleted!'.green); 76 | console.log('A backup of all deleted components is saved under ./ember-clean-project/backup-components'.gray); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /lib/config.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs'); 2 | const path = require('path'); 3 | const colors = require('colors'); 4 | 5 | const configPath = "./ember-clean-project/" 6 | const configFile = "config.json"; 7 | 8 | module.exports = { 9 | createConfig() { 10 | if (!fs.existsSync(configPath + configFile)) { 11 | fs.mkdirSync(configPath); 12 | fs.mkdirSync(configPath + "backup-components"); 13 | fs.writeFileSync(configPath + configFile, this.getDefaultConfig()); 14 | console.log("Config file created!".green); 15 | } 16 | }, 17 | getConfigPropertyComponentFolderPath() { 18 | var configJson = JSON.parse(fs.readFileSync('./ember-clean-project/config.json', 'utf8')); 19 | return configJson.componentFolderPath; 20 | }, 21 | getDefaultConfig() { 22 | return '{ \n "componentFolderPath": "./app/components" \n }'; 23 | }, 24 | getConfigPath() { 25 | return configPath; 26 | } 27 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ember-clean-project", 3 | "version": "1.0.1", 4 | "description": "An ember addon to find unused components, css classes etc.", 5 | "keywords": [ 6 | "ember-addon" 7 | ], 8 | "license": "MIT", 9 | "author": "MaxCode", 10 | "directories": { 11 | "doc": "doc", 12 | "test": "tests" 13 | }, 14 | "repository": "MaxCodeDE/ember-clean-project", 15 | "scripts": { 16 | "build": "ember build", 17 | "start": "ember server", 18 | "test": "ember try:each" 19 | }, 20 | "dependencies": { 21 | "colors": "^1.1.2", 22 | "ember-cli-babel": "^6.3.0", 23 | "fs-extra": "^4.0.2" 24 | }, 25 | "devDependencies": { 26 | "broccoli-asset-rev": "^2.4.5", 27 | "ember-ajax": "^3.0.0", 28 | "ember-cli": "~2.14.0", 29 | "ember-cli-dependency-checker": "^1.3.0", 30 | "ember-cli-htmlbars": "^2.0.1", 31 | "ember-cli-htmlbars-inline-precompile": "^0.4.3", 32 | "ember-cli-inject-live-reload": "^1.4.1", 33 | "ember-cli-qunit": "^4.0.0", 34 | "ember-cli-shims": "^1.1.0", 35 | "ember-cli-sri": "^2.1.0", 36 | "ember-cli-uglify": "^1.2.0", 37 | "ember-disable-prototype-extensions": "^1.1.2", 38 | "ember-export-application-global": "^2.0.0", 39 | "ember-load-initializers": "^1.0.0", 40 | "ember-resolver": "^4.0.0", 41 | "ember-source": "~2.14.0", 42 | "loader.js": "^4.2.3" 43 | }, 44 | "engines": { 45 | "node": "^4.5 || 6.* || >= 7.*" 46 | }, 47 | "ember-addon": { 48 | "configPath": "tests/dummy/config" 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /testem.js: -------------------------------------------------------------------------------- 1 | /* eslint-env node */ 2 | module.exports = { 3 | test_page: 'tests/index.html?hidepassed', 4 | disable_watching: true, 5 | launch_in_ci: [ 6 | 'PhantomJS' 7 | ], 8 | launch_in_dev: [ 9 | 'PhantomJS', 10 | 'Chrome' 11 | ] 12 | }; 13 | -------------------------------------------------------------------------------- /tests/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | env: { 3 | embertest: true 4 | } 5 | }; 6 | -------------------------------------------------------------------------------- /tests/dummy/app/app.js: -------------------------------------------------------------------------------- 1 | import Ember from 'ember'; 2 | import Resolver from './resolver'; 3 | import loadInitializers from 'ember-load-initializers'; 4 | import config from './config/environment'; 5 | 6 | let App; 7 | 8 | Ember.MODEL_FACTORY_INJECTIONS = true; 9 | 10 | App = Ember.Application.extend({ 11 | modulePrefix: config.modulePrefix, 12 | podModulePrefix: config.podModulePrefix, 13 | Resolver 14 | }); 15 | 16 | loadInitializers(App, config.modulePrefix); 17 | 18 | export default App; 19 | -------------------------------------------------------------------------------- /tests/dummy/app/components/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaxCodeDE/ember-clean-project/b2a9266c3baa607f0fe2b203213309d993563af4/tests/dummy/app/components/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/app/controllers/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaxCodeDE/ember-clean-project/b2a9266c3baa607f0fe2b203213309d993563af4/tests/dummy/app/controllers/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/app/helpers/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaxCodeDE/ember-clean-project/b2a9266c3baa607f0fe2b203213309d993563af4/tests/dummy/app/helpers/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/app/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 |