Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Yasin Kocak committed May 5, 2019
0 parents commit 26ba315
Show file tree
Hide file tree
Showing 14 changed files with 381 additions and 0 deletions.
25 changes: 25 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "yasinkocak/laravel-angular-preset",
"description": "Laravel Angular preset",
"keywords": [
"laravel",
"preset",
"angular"
],
"license": "MIT",
"require": {
"laravel/framework": "5.8.*"
},
"autoload": {
"psr-4": {
"YasinKocak\\AngularPreset\\": "src/"
}
},
"extra": {
"laravel": {
"providers": [
"YasinKocak\\AngularPreset\\AngularPresetServiceProvider"
]
}
}
}
27 changes: 27 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Laravel Angular Preset

A simple and easy Angular 7 scaffolding so you can quickly get started creating your next app idea with Laravel Mix.

## Installation

Add the package in your composer.json by executing the command.

```
composer require yasinkocak/laravel-angular-preset
```

## Usage

The Angular preset command can be initialized through Artisan:

```
php artisan preset angular
```

After running, this will replace out the Vue.js scaffolding with Angular. This includes the default Mix configuration, components, and any other related files

Please run command to compile your fresh scaffolding:

```
npm install && npm run dev
```
92 changes: 92 additions & 0 deletions src/AngularPreset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php

namespace YasinKocak\AngularPreset;

use Illuminate\Filesystem\Filesystem;
use Illuminate\Foundation\Console\Presets\Preset;
use Illuminate\Support\Arr;

class AngularPreset extends Preset
{
/**
* Install the preset.
*
* @return void
*/
public static function install()
{
static::updatePackages();
static::updateWebpackConfiguration();

tap(new Filesystem, function ($filesystem) {
$filesystem->deleteDirectory(resource_path('js/components'));
$filesystem->makeDirectory(resource_path('ts'));
$filesystem->makeDirectory(resource_path('ts/app'));
$filesystem->makeDirectory(resource_path('ts/environments'));
});

static::removeNodeModules();
static::updateAngular();
}

/**
* Update the given package array.
*
* @param array $packages
* @return array
*/
protected static function updatePackageArray(array $packages)
{
return [
'@angular/animations' => '^7.2.0',
'@angular/common' => '^7.2.0',
'@angular/compiler' => '^7.2.0',
'@angular/core' => '^7.2.0',
'@angular/forms' => '^7.2.0',
'@angular/http' => '^7.2.0',
'@angular/platform-browser' => '^7.2.0',
'@angular/platform-browser-dynamic' => '^7.2.0',
'@angular/router' => '^7.2.0',
'@types/node' => '^12.0.0',
'core-js' => '^2.5.4',
'rxjs' => '^6.3.3',
'ts-loader' => '^5.4.5',
'tslib'=> '^1.9.0',
'typescript' => '~3.2.2',
'zone.js' => '^0.8.26',
] + Arr::except($packages, [
'axios',
'jquery',
'vue-template-compiler',
'vue',
]);
}

/**
* Update the Webpack configuration.
*
* @return void
*/
protected static function updateWebpackConfiguration()
{
copy(__DIR__ . '/angular-stubs/webpack.mix.js', base_path('webpack.mix.js'));
}

/**
* Update the Angular files.
*
* @return void
*/
protected static function updateAngular()
{
copy(__DIR__ . '/angular-stubs/app/main.ts', resource_path('ts/main.ts'));
copy(__DIR__ . '/angular-stubs/app/app.module.ts', resource_path('ts/app/app.module.ts'));
copy(__DIR__ . '/angular-stubs/app/app.component.ts', resource_path('ts/app/app.component.ts'));
copy(__DIR__ . '/angular-stubs/app/environment.ts', resource_path('ts/environments/environment.ts'));
copy(__DIR__ . '/angular-stubs/app/tsconfig.json', resource_path('ts/tsconfig.json'));
copy(__DIR__ . '/angular-stubs/app/tslint.json', resource_path('ts/tslint.json'));
copy(__DIR__ . '/angular-stubs/polyfills.ts', resource_path('ts/polyfills.ts'));
copy(__DIR__ . '/angular-stubs/vendor.ts', resource_path('ts/vendor.ts'));
copy(__DIR__ . '/angular-stubs/tsconfig.json', base_path('tsconfig.json'));
}
}
23 changes: 23 additions & 0 deletions src/AngularPresetServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace YasinKocak\AngularPreset;

use Illuminate\Foundation\Console\PresetCommand;
use Illuminate\Support\ServiceProvider;

class AngularPresetServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
PresetCommand::macro('angular', function ($command) {
AngularPreset::install(false);
$command->info('Angular scaffolding installed successfully.');
$command->comment('Please run "npm install && npm run dev" to compile your fresh scaffolding.');
});
}
}
13 changes: 13 additions & 0 deletions src/angular-stubs/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Component } from '@angular/core';

@Component({
selector: 'app-root',
template: '<h1>{{ title }}</h1>',
})
export class AppComponent {
title = 'Laravel & Angular';

ngOnInit(): void {
console.log('Bootstrapped' + this.title + ' with Laravel Mix ');
}
}
15 changes: 15 additions & 0 deletions src/angular-stubs/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppComponent } from './app.component';

@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule
],
bootstrap: [AppComponent]
})
export class AppModule { }
3 changes: 3 additions & 0 deletions src/angular-stubs/app/environment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const environment = {
production: false
};
12 changes: 12 additions & 0 deletions src/angular-stubs/app/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { AppModule } from './app/app.module';
import { environment } from './environments/environment';

if (environment.production) {
enableProdMode();
}

platformBrowserDynamic().bootstrapModule(AppModule)
.catch(err => console.log(err));
22 changes: 22 additions & 0 deletions src/angular-stubs/app/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"module": "es2015",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"importHelpers": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2018",
"dom"
]
}
}
75 changes: 75 additions & 0 deletions src/angular-stubs/app/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"extends": "tslint:recommended",
"rulesDirectory": [
"codelyzer"
],
"rules": {
"array-type": false,
"arrow-parens": false,
"deprecation": {
"severity": "warn"
},
"import-blacklist": [
true,
"rxjs/Rx"
],
"interface-name": false,
"max-classes-per-file": false,
"max-line-length": [
true,
140
],
"member-access": false,
"member-ordering": [
true,
{
"order": [
"static-field",
"instance-field",
"static-method",
"instance-method"
]
}
],
"no-consecutive-blank-lines": false,
"no-console": [
true,
"debug",
"info",
"time",
"timeEnd",
"trace"
],
"no-empty": false,
"no-inferrable-types": [
true,
"ignore-params"
],
"no-non-null-assertion": true,
"no-redundant-jsdoc": true,
"no-switch-case-fall-through": true,
"no-use-before-declare": true,
"no-var-requires": false,
"object-literal-key-quotes": [
true,
"as-needed"
],
"object-literal-sort-keys": false,
"ordered-imports": false,
"quotemark": [
true,
"single"
],
"trailing-comma": false,
"no-output-on-prefix": true,
"use-input-property-decorator": true,
"use-output-property-decorator": true,
"use-host-property-decorator": true,
"no-input-rename": true,
"no-output-rename": true,
"use-life-cycle-interface": true,
"use-pipe-transform-interface": true,
"component-class-suffix": true,
"directive-class-suffix": true
}
}
31 changes: 31 additions & 0 deletions src/angular-stubs/polyfills.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/** IE9, IE10 and IE11 requires all of the following polyfills. **/
import 'core-js/es6/symbol';
import 'core-js/es6/object';
import 'core-js/es6/function';
import 'core-js/es6/parse-int';
import 'core-js/es6/parse-float';
import 'core-js/es6/number';
import 'core-js/es6/math';
import 'core-js/es6/string';
import 'core-js/es6/date';
import 'core-js/es6/array';
import 'core-js/es6/regexp';
import 'core-js/es6/map';
import 'core-js/es6/weak-map';
import 'core-js/es6/set';

/** IE10 and IE11 requires the following for NgClass support on SVG elements */
// import 'classlist.js'; // Run `npm install --save classlist.js`.

/** IE10 and IE11 requires the following for the Reflect API. */
import 'core-js/es6/reflect';


/** Evergreen browsers require these. **/
// Used for reflect-metadata in JIT. If you use AOT (and only Angular decorators), you can remove.
import 'core-js/es7/reflect';

/***************************************************************************************************
* Zone JS is required by default for Angular itself.
*/
import 'zone.js/dist/zone'; // Included with Angular CLI.
9 changes: 9 additions & 0 deletions src/angular-stubs/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"noImplicitAny": false,
"sourceMap": false
},
"include": ["resources/ts/**/*"]
}
10 changes: 10 additions & 0 deletions src/angular-stubs/vendor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Angular
import '@angular/platform-browser';
import '@angular/platform-browser-dynamic';
import '@angular/core';
import '@angular/common';
import '@angular/http';
import '@angular/router';

// RxJS
import 'rxjs';
24 changes: 24 additions & 0 deletions src/angular-stubs/webpack.mix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const mix = require('laravel-mix');

/*
|--------------------------------------------------------------------------
| Mix Asset Management
|--------------------------------------------------------------------------
|
| Mix provides a clean, fluent API for defining some Webpack build steps
| for your Laravel application. By default, we are compiling the Sass
| file for the application as well as bundling up all the JS files.
|
*/
mix.ts([
'resources/js/app.js', // Can deleted if no needed
'resources/ts/vendor.ts',
'resources/ts/polyfills.ts',
], 'public/js/vendor.js');

mix.ts([
'resources/ts/main.ts'
], 'public/js/app.js').version();

mix.sass('resources/sass/app.scss', 'public/css');

0 comments on commit 26ba315

Please sign in to comment.