Permalink
Browse files

Move component generation to create

  • Loading branch information...
abraham committed Oct 12, 2018
1 parent f4a7869 commit 9b238ad7993a3b352153f712dc84474d652b0633
Showing with 172 additions and 39 deletions.
  1. +2 −2 README.md
  2. +11 −11 package-lock.json
  3. +3 −1 packages/cli/bin/nutmeg-new
  4. +2 −1 packages/cli/package.json
  5. +1 −2 packages/cli/scripts/test.ts
  6. +1 −2 packages/cli/src/utils.ts
  7. +6 −2 packages/cli/tsconfig.json
  8. +1 −1 packages/create/bin/create-nutmeg
  9. 0 packages/{cli → create}/element-template/.circleci/config.yml
  10. 0 packages/{cli → create}/element-template/LICENSE.md
  11. 0 packages/{cli → create}/element-template/README.md
  12. 0 packages/{cli → create}/element-template/appveyor.yml
  13. 0 packages/{cli → create}/element-template/gitignore
  14. 0 packages/{cli → create}/element-template/index.html
  15. 0 packages/{cli → create}/element-template/package.json
  16. 0 packages/{cli → create}/element-template/partial/fixture.ts
  17. 0 packages/{cli → create}/element-template/partial/it.ts
  18. 0 packages/{cli → create}/element-template/partial/property.ts
  19. 0 packages/{cli → create}/element-template/renovate.json
  20. 0 packages/{cli → create}/element-template/src/element-template.ts
  21. 0 packages/{cli → create}/element-template/test/element-template.test.ts
  22. 0 packages/{cli → create}/element-template/travis.yml
  23. +2 −2 packages/{cli → create}/element-template/tsconfig.json
  24. +6 −2 packages/{cli → create}/element-template/tsconfig.production.json
  25. +16 −3 packages/create/package.json
  26. +11 −8 packages/create/scripts/test.ts
  27. +26 −0 packages/create/src/component.ts
  28. 0 packages/{cli → create}/src/generator.ts
  29. 0 packages/{cli/src/new.ts → create/src/index.ts}
  30. 0 packages/{cli → create}/src/properties.ts
  31. 0 packages/{cli/src/index.d.ts → create/src/recursive-copy.d.ts}
  32. +77 −0 packages/create/src/utils.ts
  33. +7 −2 packages/create/tsconfig.json
@@ -37,7 +37,7 @@ npm init @nutmeg hello-world name:string
This will create a `hello-world` directory, stub out a base Web Component class `HelloWorld` that extends the Nutmeg `Seed` base class, and install the default dependencies. You can use either `fullName` or `full-name` for multi-word properties and `full-name` will be used for HTML attributes and `fullName` will be used in JavaScript.
### 📌 Install
<!-- ### 📌 Install
Optionally you can install the full CLI.
@@ -49,7 +49,7 @@ Then generating a component is done with the `new` subcommand.
```bash
nutmeg new hello-world name:string
```
``` -->
_Note: Yarn is not supported but may work._

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -1,3 +1,5 @@
#!/usr/bin/env node
require('../dist/new');
// require('../dist/new');
console.log('Run `npm init @nutmeg <copmonent-name> [property:type...]` to generate a component.');
@@ -44,7 +44,8 @@
"build": "tsc",
"clean": "rimraf dist",
"prepare": "npm run build",
"test": "ts-node ./scripts/test.ts",
"test": "npm run build",
"xtest": "ts-node ./scripts/test.ts",
"watch": "tsc --watch"
},
"engines": {
@@ -12,13 +12,12 @@ const cliTgz = path.resolve(cliDir, cliTgzName);
const nutmegPath = path.resolve(cliDir, 'bin', 'nutmeg');
const sources = `--cli-source file:${cliTgz} --seed-source file:${seedDir}`;
const attributes = 'first:number second:string third:boolean';
const installCmd = `${nutmegPath} new ci-test ${attributes} ${sources}`;
const testDir = path.resolve(shell.tempdir(), 'nutmeg', 'cli');
setupForTests();
shell.cd(testDir);
shell.exec(installCmd);
shell.exec(`${nutmegPath} new ci-test ${attributes} ${sources}`);
shell.cd('ci-test');
shell.exec('npm test');
@@ -15,8 +15,7 @@ interface Pkg {
}
function tsconfigPath(workingDir: string): string {
const modernPath = path.resolve(workingDir, 'tsconfig.production.json');
return fs.existsSync(modernPath) ? modernPath : path.resolve(workingDir, 'tsconfig.json')
return path.resolve(workingDir, 'tsconfig.production.json');
}
function notifyOfUpdate() {
@@ -13,9 +13,13 @@
"skipLibCheck": true,
"sourceMap": false,
"strict": true,
"target": "esnext",
"target": "esnext"
},
"include": [
"src",
"src"
],
"exclude": [
"node_modules",
"dist"
]
}
@@ -1,3 +1,3 @@
#!/usr/bin/env node
require('@nutmeg/cli/dist/new');
require('../dist/index');
@@ -2,6 +2,6 @@
"extends": "./tsconfig.production",
"include": [
"src",
"test",
],
"test"
]
}
@@ -16,9 +16,13 @@
"sourceMap": true,
"sourceRoot": "src",
"strict": true,
"target": "esnext",
"target": "esnext"
},
"include": [
"src",
"src"
],
"exclude": [
"node_modules",
"dist"
]
}
@@ -21,7 +21,13 @@
],
"license": "MIT",
"scripts": {
"test": "ts-node ./scripts/test.ts"
"prebuild": "npm run clean",
"build": "tsc",
"clean": "rimraf dist",
"prepare": "npm run build",
"pretest": "npm run build",
"test": "ts-node ./scripts/test.ts",
"watch": "tsc --watch"
},
"author": {
"name": "Abraham Williams",
@@ -33,12 +39,19 @@
},
"homepage": "https://nutmeg.tools",
"dependencies": {
"@nutmeg/cli": "0.15.0"
"lodash.template": "^4.4.0",
"pascal-case": "^2.0.1",
"recursive-copy": "^2.0.9",
"shelljs": "0.8.2",
"through2": "^2.0.3",
"update-notifier": "^2.5.0"
},
"devDependencies": {
"@types/lodash.template": "^4.4.4",
"@types/node": "10.11.7",
"@types/shelljs": "0.8.0",
"shelljs": "0.8.2",
"@types/through2": "^2.0.34",
"@types/update-notifier": "^2.2.0",
"ts-node": "7.0.1",
"typescript": "3.1.3"
},
@@ -1,24 +1,25 @@
import * as path from 'path';
import * as shell from 'shelljs';
import { pkg } from '../../cli/src/utils';
import { pkg } from '../src/utils';
shell.config.verbose = process.env.DEBUG === 'true';
const cliTgzName = `nutmeg-cli-${pkg.version}.tgz`;
const seedTgzName = `nutmeg-seed-${pkg.version}.tgz`;
const pkgsDir = path.resolve('..');
const cliDir = path.resolve(pkgsDir, 'cli');
const seedDir = path.resolve(pkgsDir, 'seed');
const createDir = path.resolve(pkgsDir, 'create');
const cliTgz = path.resolve(cliDir, cliTgzName);
const nutmegPath = path.resolve(cliDir, 'bin', 'nutmeg');
const sources = `--cli-source file:${cliTgz} --seed-source file:${seedDir}`;
const seedTgz = path.resolve(seedDir, seedTgzName);
const sources = `--cli-source file:${cliTgz} --seed-source file:${seedTgz}`;
const attributes = 'first:number second:string third:boolean';
const installCmd = `${nutmegPath} new ci-test ${attributes} ${sources}`;
const testDir = path.resolve(shell.tempdir(), 'nutmeg', 'create');
setupForTests();
shell.cd(testDir);
shell.exec(installCmd);
shell.exec(`npx ${createDir} ci-test ${attributes} ${sources}`);
shell.cd('ci-test');
shell.exec('npm test');
@@ -27,11 +28,13 @@ removeTestFiles();
function setupForTests() {
removeTestFiles();
shell.mkdir('-p', testDir);
shell.cd(cliDir);
shell.exec('npm pack .', { silent: true });
[cliDir, seedDir].forEach(dir => {
shell.cd(dir);
shell.exec('npm pack .', { silent: true });
});
}
function removeTestFiles() {
shell.cd(cliDir);
shell.rm('-rf', [testDir, cliTgz]);
shell.rm('-rf', [testDir, cliTgz, seedTgz]);
}
@@ -0,0 +1,26 @@
import * as path from 'path';
import { loadPackageJson } from './utils';
import pascalCase = require('pascal-case');
export class Component {
public tag: string;
constructor(tag: string) {
this.tag = tag;
}
public static tagFromPackage(workingDir: string): string {
const { main } = loadPackageJson(workingDir);
return path.parse(main).name;
}
public get valid(): boolean {
return 0 < this.tag.indexOf('-')
&& this.tag.indexOf('-') < this.tag.length - 1
&& this.tag === this.tag.toLowerCase();
}
public get name(): string {
return pascalCase(this.tag);
}
}
File renamed without changes.
@@ -0,0 +1,77 @@
import * as fs from 'fs';
import * as path from 'path';
import * as shell from 'shelljs';
import * as updateNotifier from 'update-notifier';
const silent = true;
const nutmegDir = path.resolve(__dirname, '..');
const pkg = loadPackageJson(nutmegDir);
interface Pkg {
dependencies: { [index: string]: string };
main: string;
name: string;
version: string;
}
function tsconfigPath(workingDir: string): string {
return path.resolve(workingDir, 'tsconfig.production.json');
}
function notifyOfUpdate() {
updateNotifier({ pkg }).notify({ defer: true });
}
function isNutmegComponent(workingDir: string): boolean {
try {
const { dependencies } = loadPackageJson(workingDir);
return dependencies && dependencies.hasOwnProperty('@nutmeg/seed');
} catch(e) {
return false;
}
}
function loadPackageJson(dir: string): Pkg {
const packagePath = path.resolve(dir, 'package.json');
return JSON.parse(fs.readFileSync(packagePath).toString());
}
function exit(message: string, condition = true): void {
if (condition) {
console.error(message);
process.exit(1);
}
}
function commitToGit(): void {
shell.exec('git init', { silent });
shell.exec('git add .', { silent });
shell.exec('git commit -m "Initial commit from @nutmeg/cli"', { silent });
console.log('🗄️ Commiting files to initial Git repository');
}
function installDependencies(options: { withDependencies: boolean }): void {
if (!options.withDependencies) {
console.log('📦 Skipping dependencies');
} else {
console.log(`🎁 Installing dependencies`);
shell.exec('npm install', { silent });
}
}
/** Copied from @nutmeg/seed. Make changes there. */
export function attributeNameFromProperty(name :string): string {
return name.replace(/([a-zA-Z])(?=[A-Z])/g, '$1-').toLowerCase();
}
/** Copied from @nutmeg/seed. Make changes there. */
export function propertyNameFromAttribute(name :string): string {
if (name.includes('-')) {
return name.toLowerCase().replace(/-([a-z])/g, (g) => g[1].toUpperCase());
} else {
return name;
}
}
export { commitToGit, exit, installDependencies, isNutmegComponent, loadPackageJson, notifyOfUpdate, tsconfigPath, nutmegDir, pkg };
Oops, something went wrong.

0 comments on commit 9b238ad

Please sign in to comment.