Browse Source

Replaced the Gulp build system by PowerShell scripts

tags/v5.0.0
Cédric Belin 6 months ago
parent
commit
448f921684
16 changed files with 110 additions and 93 deletions
  1. +0
    -1
      .gitignore
  2. +0
    -5
      .gulp.json
  3. +1
    -4
      doc/installation.md
  4. +4
    -5
      package.json
  5. +18
    -0
      tool/build.ps1
  6. +11
    -0
      tool/clean.ps1
  7. +4
    -0
      tool/coverage.ps1
  8. +6
    -0
      tool/doc.ps1
  9. +4
    -0
      tool/fix.ps1
  10. +0
    -78
      tool/gulpfile.cjs
  11. +4
    -0
      tool/lint.ps1
  12. +6
    -0
      tool/publish.ps1
  13. +4
    -0
      tool/test.ps1
  14. +10
    -0
      tool/upgrade.ps1
  15. +11
    -0
      tool/version.ps1
  16. +27
    -0
      tool/watch.ps1

+ 0
- 1
.gitignore View File

@@ -14,4 +14,3 @@
/**/.DS_Store
/npm-debug.log
/package-lock.json
/share/*.private.env.json

+ 0
- 5
.gulp.json View File

@@ -1,5 +0,0 @@
{
"flags": {
"gulpfile": "tool/gulpfile.cjs"
}
}

+ 1
- 4
doc/installation.md View File

@@ -4,14 +4,11 @@
Before installing **Web Storage for Angular**, you need to make sure you have [Node.js](https://nodejs.org)
and [npm](https://www.npmjs.com), the Node.js package manager, up and running.

!!! warning
Web Storage for Angular requires Node.js >= **14.1.0**.

You can verify if you're already good to go with the following commands:

```shell
node --version
# v14.1.0
# v14.2.0

npm --version
# 6.14.4


+ 4
- 5
package.json View File

@@ -49,7 +49,7 @@
"zone.js": "^0.10.3"
},
"engines": {
"node": ">=14.1.0"
"node": ">=14.2.0"
},
"files": [
"lib/"
@@ -81,9 +81,8 @@
"url": "https://git.belin.io/cedx/ngx-webstorage.git"
},
"scripts": {
"coverage": "gulp coverage",
"prepack": "gulp",
"start": "gulp watch",
"test": "gulp test"
"coverage": "coveralls var/lcov.info",
"prepack": "pwsh tool/build.ps1",
"test": "ng test"
}
}

+ 18
- 0
tool/build.ps1 View File

@@ -0,0 +1,18 @@
#!/usr/bin/env pwsh
Set-StrictMode -Version Latest
Set-Location (Split-Path $PSScriptRoot)

node_modules/.bin/ng.ps1 build
if (-not (Test-Path lib)) { New-Item lib -ItemType Directory | Out-Null }

$regex = "(export|import)\s+(.+)\s+from\s+'((?!.*\.js)\.[^']+)'"
foreach ($item in Get-ChildItem build/esm2015 -File -Filter '*.js') {
$file = Get-Content $item -Raw
($file -replace $regex, '$1 $2 from ''$3.js''') -replace "`r?`n//# sourceMappingURL=.*$", '' | Out-File "lib/$($item.Name)"
}

foreach ($item in Get-ChildItem build -File -Filter '*.d.ts') {
Copy-Item $item "lib/$($item.Name)"
}

Remove-Item build -Recurse

+ 11
- 0
tool/clean.ps1 View File

@@ -0,0 +1,11 @@
#!/usr/bin/env pwsh
Set-StrictMode -Version Latest
Set-Location (Split-Path $PSScriptRoot)

foreach ($item in @('build', 'doc/api', 'lib', 'www')) {
if (Test-Path $item) { Remove-Item $item -Recurse }
}

foreach ($item in Get-ChildItem var -Exclude .gitkeep) {
Remove-Item $item -Recurse
}

+ 4
- 0
tool/coverage.ps1 View File

@@ -0,0 +1,4 @@
#!/usr/bin/env pwsh
Set-StrictMode -Version Latest
Set-Location (Split-Path $PSScriptRoot)
node_modules/.bin/coveralls.ps1 var/lcov.info

+ 6
- 0
tool/doc.ps1 View File

@@ -0,0 +1,6 @@
#!/usr/bin/env pwsh
Set-StrictMode -Version Latest
Set-Location (Split-Path $PSScriptRoot)

node_modules/.bin/compodoc.ps1 --config=etc/compodoc.yaml
mkdocs build --config-file=etc/mkdocs.yaml

+ 4
- 0
tool/fix.ps1 View File

@@ -0,0 +1,4 @@
#!/usr/bin/env pwsh
Set-StrictMode -Version Latest
Set-Location (Split-Path $PSScriptRoot)
node_modules/.bin/eslint.ps1 --config=etc/eslint.yaml --fix src/**/*.ts

+ 0
- 78
tool/gulpfile.cjs View File

@@ -1,78 +0,0 @@
const {spawn} = require('child_process');
const del = require('del');
const {dest, parallel, series, src, task, watch} = require('gulp');
const replace = require('gulp-replace');
const {delimiter, normalize, resolve} = require('path');

// Initialize the build system.
const _path = process.env.PATH ?? '';
const _vendor = resolve('node_modules/.bin');
if (!_path.includes(_vendor)) process.env.PATH = `${_vendor}${delimiter}${_path}`;

/** Builds the project. */
const esmRegex = /(export|import)\s+(.+)\s+from\s+'((?!.*\.js)\.[^']+)'/g;
task('build:fix', () => src(['build/esm2015/**/*.js'])
.pipe(replace(esmRegex, "$1 $2 from '$3.js'"))
.pipe(replace(/\/\/# sourceMappingURL=.*$/g, ''))
.pipe(dest('lib')));

task('build:clean', () => del('build'));
task('build:js', () => _exec('ng', ['build']));
task('build:types', () => src('build/**/*.d.ts').pipe(dest('lib')));
task('build', series('build:js', parallel('build:fix', 'build:types'), 'build:clean'));

/** Deletes all generated files and reset any saved state. */
task('clean', () => del(['build', 'doc/api', 'lib', 'var/**/*', 'web']));

/** Uploads the results of the code coverage. */
task('coverage', () => _exec('coveralls', ['var/lcov.info']));

/** Builds the documentation. */
task('doc', async () => {
await _exec('compodoc', ['--config=etc/compodoc.yaml']);
return _exec('mkdocs', ['build', '--config-file=etc/mkdocs.yaml']);
});

/** Fixes the coding standards issues. */
task('fix', () => _exec('eslint', ['--config=etc/eslint.yaml', '--fix', 'src/**/*.ts']));

/** Performs the static analysis of source code. */
task('lint', () => _exec('eslint', ['--config=etc/eslint.yaml', 'src/**/*.ts']));

/** Publishes the package to the registry. */
task('publish:npm', () => _exec('npm', ['publish', '--registry=https://registry.npmjs.org']));
task('publish', series('clean', 'publish:npm'));

/** Runs the test suites. */
task('test', () => _exec('ng', ['test']));

/** Upgrades the project to the latest revision. */
task('upgrade', async () => {
await _exec('git', ['reset', '--hard']);
await _exec('git', ['fetch', '--all', '--prune']);
await _exec('git', ['pull', '--rebase']);
await _exec('npm', ['install', '--ignore-scripts', '--production=false']);
return _exec('npm', ['update', '--dev']);
});

/** Watches for file changes. */
task('watch', () => {
watch('src/**/*.ts', {ignoreInitial: false}, task('build'));
watch('test/**/*.ts', task('test'));
});

/** Runs the default tasks. */
task('default', task('build'));

/**
* Spawns a new process using the specified command.
* @param {string} command The command to run.
* @param {string[]} args The command arguments.
* @param {SpawnOptionsWithoutStdio} options The settings to customize how the process is spawned.
* @return {Promise<void>} Completes when the command is finally terminated.
*/
function _exec(command, args = [], options = {}) {
return new Promise((fulfill, reject) => spawn(normalize(command), args, {shell: true, stdio: 'inherit', ...options})
.on('close', code => code ? reject(new Error(`${command}: ${code}`)) : fulfill())
);
}

+ 4
- 0
tool/lint.ps1 View File

@@ -0,0 +1,4 @@
#!/usr/bin/env pwsh
Set-StrictMode -Version Latest
Set-Location (Split-Path $PSScriptRoot)
node_modules/.bin/eslint.ps1 --config=etc/eslint.yaml src/**/*.ts

+ 6
- 0
tool/publish.ps1 View File

@@ -0,0 +1,6 @@
#!/usr/bin/env pwsh
Set-StrictMode -Version Latest
Set-Location (Split-Path $PSScriptRoot)

tool/clean.ps1
npm publish --registry=https://registry.npmjs.org

+ 4
- 0
tool/test.ps1 View File

@@ -0,0 +1,4 @@
#!/usr/bin/env pwsh
Set-StrictMode -Version Latest
Set-Location (Split-Path $PSScriptRoot)
node_modules/.bin/ng.ps1 test

+ 10
- 0
tool/upgrade.ps1 View File

@@ -0,0 +1,10 @@
#!/usr/bin/env pwsh
Set-StrictMode -Version Latest
Set-Location (Split-Path $PSScriptRoot)

git reset --hard
git fetch --all --prune
git pull --rebase

npm install --ignore-scripts --production=false
npm update --dev

+ 11
- 0
tool/version.ps1 View File

@@ -0,0 +1,11 @@
#!/usr/bin/env pwsh
Set-StrictMode -Version Latest
Set-Location (Split-Path $PSScriptRoot)

$version = (Get-Content package.json | ConvertFrom-Json).version
$lines = @(
'/** The version number of the package. */',
"export const packageVersion: string = '$version';"
)

Set-Content src/cli/version.g.ts ($lines -join [Environment]::NewLine)

+ 27
- 0
tool/watch.ps1 View File

@@ -0,0 +1,27 @@
#!/usr/bin/env pwsh
Set-StrictMode -Version Latest
Set-Location (Split-Path $PSScriptRoot)
[Console]::TreatControlCAsInput = $true

$action = {
$changeType = [String] $EventArgs.ChangeType
Write-Host "'$($EventArgs.Name)' was $($changeType.ToLower()): starting a new build..."
$timeSpan = Measure-Command { tool/build.ps1 }
Write-Host "> Finished the build after $($timeSpan.TotalSeconds) seconds."
}

$watcher = New-Object System.IO.FileSystemWatcher (Resolve-Path src).Path
$watcher.EnableRaisingEvents = $true
$watcher.IncludeSubdirectories = $true

foreach ($event in @('Changed', 'Created', 'Deleted', 'Renamed')) {
Register-ObjectEvent $watcher $event -Action $action | Out-Null
}

$console = $Host.UI.RawUI;
while ($true) {
if ($console.KeyAvailable -and ($console.ReadKey('AllowCtrlC,IncludeKeyUp,NoEcho').Character -eq 3)) { break }
Start-Sleep -Milliseconds 200
}

Get-EventSubscriber | Unregister-Event

Loading…
Cancel
Save