Permalink
Browse files

Add clean command

  • Loading branch information...
abraham committed Jan 8, 2018
1 parent 7ffdf57 commit 61cbdd391e0fa0d365cf510f0053053c0427c57e
Showing with 27 additions and 10 deletions.
  1. +3 −0 bin/nutmeg-clean
  2. +1 −2 element-template/package.json
  3. +1 −0 package.json
  4. +17 −0 src/clean.ts
  5. +4 −3 src/main.ts
  6. +0 −5 src/watch.ts
  7. +1 −0 webpack.config.js
@@ -0,0 +1,3 @@
#!/usr/bin/env node
require('../dist/clean');
@@ -19,8 +19,7 @@
"license": "MIT",
"scripts": {
"build": "npx nutmeg build .",
"clean": "rm -rf dist/*",
"prebuild": "npm run clean",
"prebuild": "npx nutmeg clean .",
"prepare": "npm run build",
"pretest": "npm run build",
"serve": "npx nutmeg serve .",
@@ -6,6 +6,7 @@
"types": "dist/cli.d.ts",
"bin": {
"nutmeg-build": "bin/nutmeg-build",
"nutmeg-clean": "bin/nutmeg-clean",
"nutmeg-new": "bin/nutmeg-new",
"nutmeg-serve": "bin/nutmeg-serve",
"nutmeg-test": "bin/nutmeg-test",
@@ -0,0 +1,17 @@
import path = require('path');
import program = require('commander');
import shell = require("shelljs");
import { isNutmegComponent, exit } from './utils';
program.command('clean [path]', "clean a Web Component's compiled files")
.parse(process.argv);
const nutmegDir = path.resolve(process.argv[1], '../..');
const workingDir = path.resolve(program.args[0]);
const distDir = path.resolve(workingDir, './dist');
exit("Directory doesn't have a package.json with @nutmeg/element as a dependancy.", !isNutmegComponent(workingDir));
console.log(`Cleaning ${distDir}`);
shell.exec(`rm -rf ${distDir}`);
@@ -4,10 +4,11 @@ const version = require('../package.json')['version'];
program
.version(version)
.usage('new <name> [property:type...]')
.command('new <name> [property:type...]', 'generate a Web Component')
.command('build [path]', 'compile a Web Component')
.command('watch [path]', 'run build on file changes')
.command('clean [path]', "clean a Web Component's compiled files")
.command('new <name> [property:type...]', 'generate a Web Component')
.command('serve [path]', 'start and open a dev server')
.command('test [path]', 'test a Web Component');
.command('test [path]', 'test a Web Component')
.command('watch [path]', 'run build on file changes');
program.parse(process.argv);
@@ -9,17 +9,12 @@ program.command('build [path]', 'compile a Web Component')
const nutmegDir = path.resolve(process.argv[1], '../..');
const workingDir = path.resolve(program.args[0]);
const distDir = path.resolve(workingDir, './dist');
const typescriptConfigFile = path.resolve(workingDir, 'tsconfig.json');
const webpackConfigFile = path.resolve(nutmegDir, 'webpack.component.config.js');
const tag = workingDir.split('/')[workingDir.split('/').length - 1];
const tscCmd = `tsc --project ${typescriptConfigFile} --watch`;
const webpackCmd = `webpack --config ${webpackConfigFile} --env.tag=${tag} --env.workingDir=${workingDir} --watch`;
console.log('webpackCmd', webpackCmd);
console.log('nutmegDir', nutmegDir, 'workingDir', workingDir);
exit("Directory doesn't have a package.json with @nutmeg/element as a dependancy.", !isNutmegComponent(workingDir));
shell.exec(`rm -rf ${distDir}`);
shell.exec(`npx ${tscCmd} & npx ${webpackCmd}`);
@@ -4,6 +4,7 @@ module.exports = {
target: 'node',
entry: {
build: './src/build.ts',
clean: './src/clean.ts',
main: './src/main.ts',
new: './src/new.ts',
serve: './src/serve.ts',

0 comments on commit 61cbdd3

Please sign in to comment.