Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor of ImportExcel project #1535

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
10 changes: 10 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM mcr.microsoft.com/powershell:lts-debian-11

SHELL [ "pwsh", "-NoLogo", "-NoProfile", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue'; " ]
RUN apt update && apt install -y --no-install-recommends libc6-dev python3-pip mkdocs; \
pip install mkdocs-material mkdocs-awesome-pages-plugin -q --no-input; \
Install-Module Pester -RequiredVersion 5.5.0 -Force; \
Install-Module psake -RequiredVersion 4.9.0 -Force; \
Install-Module PSReadLine -RequiredVersion 2.3.4 -Force; \
Install-Module PSScriptAnalyzer -RequiredVersion 1.21.0 -Force; \
Install-Module platyPS -RequiredVersion 0.14.2 -Force;
27 changes: 27 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "PowerShell",
"dockerFile": "Dockerfile",
"features": {
"ghcr.io/devcontainers/features/common-utils:2": {
"installZsh": "true",
"username": "vscode",
"upgradePackages": "false",
"nonFreePackages": "true"
}
},
"postCreateCommand": "sudo chsh vscode -s \"$(which pwsh)\"",
"customizations": {
"vscode": {
"settings": {
"powershell.powerShellDefaultVersion": "PowerShell",
"terminal.integrated.defaultProfile.linux": "pwsh"
},
"extensions": [
"ms-vscode.powershell",
"redhat.vscode-yaml",
"eamodio.gitlens"
]
}
},
"forwardPorts": [8000]
}
15 changes: 8 additions & 7 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@
* text=auto

# Custom for Visual Studio
*.cs diff=csharp
*.ps1 text eol=crlf
*.cs diff=csharp
*.ps1 text eol=crlf
*.psm1 text eol=crlf
*.md text eol=crlf

# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain
40 changes: 27 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,41 @@
on:
workflow_dispatch:
push:
branches:
- master
- Set-up-GHA-CI/CD

pull_request:

jobs:
validate:
build:
name: Build and Test
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
steps:
- uses: actions/checkout@v1
- name: Run Continuous Integration
shell: pwsh
run : |
if($PSVersionTable.Platform -eq 'Win32NT') {
$null = mkdir ./ace
Invoke-Restmethod https://download.microsoft.com/download/3/5/C/35C84C36-661A-44E6-9324-8786B8DBE231/accessdatabaseengine_X64.exe -OutFile ./ace/ace.exe
Start-Process ./ace/ace.exe -Wait -ArgumentList "/quiet /passive /norestart"
}
- uses: actions/checkout@v4

- name: Build
id: build
shell: pwsh
run: |
$result = ./build.ps1
"ManifestPath=$($result.Output.ManifestPath)" | Add-Content "$($env:GITHUB_OUTPUT)"

- name: Test
shell: pwsh
run: |
if($PSVersionTable.Platform -eq 'Win32NT') {
$null = mkdir ./ace
Invoke-Restmethod https://download.microsoft.com/download/3/5/C/35C84C36-661A-44E6-9324-8786B8DBE231/accessdatabaseengine_X64.exe -OutFile ./ace/ace.exe
Start-Process ./ace/ace.exe -Wait -ArgumentList "/quiet /passive /norestart"
}
./RunTests.ps1 -ModulePath ${{ steps.build.outputs.ManifestPath }} -NoIsolation

cd ./__tests__
Invoke-Pester -Output Detailed
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action/composite@v2
if: always()
with:
files: |
Output/testResults.xml
31 changes: 31 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Publish Docs
on:
workflow_dispatch:
push:
branches:
- master
paths:
- ".github/workflows/docs.yml"
- "docs/**"
- "mkdocs.yml"

permissions:
contents: write

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: 3.x
- run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
- uses: actions/cache@v3
with:
key: mkdocs-material-${{ env.cache_id }}
path: .cache
restore-keys: |
mkdocs-material-
- run: pip install mkdocs-material mkdocs-awesome-pages-plugin
- run: mkdocs gh-deploy --force
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Build artifacts
[O|o]utput/
.cache/

# Windows image file caches
Thumbs.db
ehthumbs.db
Expand Down
18 changes: 18 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "PowerShell: Debug Module",
"type": "PowerShell",
"request": "launch",
"script": "Import-Module -Force ${workspaceFolder}/ImportExcel/ImportExcel.psd1",
},
{
"name": "PowerShell: Launch Current File",
"type": "PowerShell",
"request": "launch",
"script": "if ($null -eq (Get-Module ImportExcel)) { Import-Module ${workspaceFolder}/ImportExcel/ImportExcel.psd1 }; ${file}",
"cwd": "${cwd}"
}
]
}
31 changes: 31 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "${workspaceFolder}\\build.ps1 | Out-Null",
"type": "shell",
"args": [],
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"reveal": "silent"
}
},
{
"label": "test",
"command": "${workspaceFolder}\\RunTests.ps1",
"type": "shell",
"args": ["-NoIsolation"],
"group": {
"kind": "test",
"isDefault": true
},
"presentation": {
"reveal": "always"
}
}
]
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
25 changes: 6 additions & 19 deletions ImportExcel.psd1 → ImportExcel/ImportExcel.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ Check out the How To Videos https://www.youtube.com/watch?v=U3Ne_yX4tYo&list=PL5
'Enable-ExcelAutofit',
'Expand-NumberFormat',
'Export-Excel',
'Export-ExcelSheet',
'Export-ExcelSheet',
'Get-ExcelColumnName',
'Get-ExcelFileSchema',
'Get-ExcelFileSummary',
'Get-ExcelSheetDimensionAddress',
'Get-ExcelFileSummary',
'Get-ExcelSheetDimensionAddress',
'Get-ExcelSheetInfo',
'Get-ExcelWorkbookInfo',
'Get-HtmlTable',
Expand Down Expand Up @@ -118,22 +118,9 @@ Check out the How To Videos https://www.youtube.com/watch?v=U3Ne_yX4tYo&list=PL5
CmdletsToExport = @()

FileList = @(
'.\EPPlus.dll',
'.\Export-charts.ps1',
'.\GetExcelTable.ps1',
'.\ImportExcel.psd1',
'.\ImportExcel.psm1',
'.\LICENSE.txt',
'.\Plot.ps1',
'.\Private',
'.\Public',
'.\en\ImportExcel-help.xml',
'.\en\Strings.psd1',
'.\Charting\Charting.ps1',
'.\InferData\InferData.ps1',
'.\Pivot\Pivot.ps1',
'.\Examples',
'.\Testimonials'
'Localized/strings.psd1'
'EPPlus.dll',
'Plot.ps1'
)

# Private data to pass to the module specified in RootModule/ModuleToProcess
Expand Down
34 changes: 17 additions & 17 deletions ImportExcel.psm1 → ImportExcel/ImportExcel.psm1
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
#region import everything we need
$culture = $host.CurrentCulture.Name -replace '-\w*$', ''
Import-LocalizedData -UICulture $culture -BindingVariable Strings -FileName Strings -ErrorAction Ignore
if (-not $Strings) {
Import-LocalizedData -UICulture "en" -BindingVariable Strings -FileName Strings -ErrorAction Ignore
}
Import-LocalizedData -BindingVariable 'Strings' -FileName 'strings' -BaseDirectory "$PSScriptRoot/Localized"
try { [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") }
catch { Write-Warning -Message $Strings.SystemDrawingAvailable }

foreach ($directory in @('Private', 'Public', 'Charting', 'InferData', 'Pivot')) {
Get-ChildItem -Path "$PSScriptRoot\$directory\*.ps1" | ForEach-Object { . $_.FullName }
#region Dot-Sourced Functions
try {
$dotSources = Get-Content -Path $PSScriptRoot/dot-sources.txt -ErrorAction Stop | Where-Object {
$_ -notmatch '^\s*#' -and -not [string]::IsNullOrWhiteSpace($_)
}
foreach ($directory in $dotSources) {
$directory = $directory.Trim()
foreach ($file in Get-ChildItem -Path "$PSScriptRoot/$Directory/*.ps1") {
. $file.FullName
}
}
} catch {
throw
}
#endregion

if ($PSVersionTable.PSVersion.Major -ge 5) {
. $PSScriptRoot\Plot.ps1
Expand Down Expand Up @@ -40,18 +48,10 @@ if (($IsLinux -or $IsMacOS) -or $env:NoAutoSize) {
catch {
$env:NoAutoSize = $true
if ($IsLinux) {
$msg = @"
ImportExcel Module Cannot Autosize. Please run the following command to install dependencies:
apt-get -y update && apt-get install -y --no-install-recommends libgdiplus libc6-dev
"@
Write-Warning -Message $msg
Write-Warning -Message $Strings.NoAutoSizeLinux
}
if ($IsMacOS) {
$msg = @"
ImportExcel Module Cannot Autosize. Please run the following command to install dependencies:
brew install mono-libgdiplus
"@
Write-Warning -Message $msg
Write-Warning -Message $Strings.NoAutoSizeMacOS
}
}
finally {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 16 additions & 0 deletions ImportExcel/Localized/strings.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@{
SystemDrawingAvailable = 'System.Drawing could not be loaded. Color and font look-ups may not be available.'
PS5NeededForPlot = 'PowerShell 5 is required for plot.ps1'
ModuleReadyExceptPlot = 'The ImportExcel module is ready, except for that functionality'

NoAutoSizeLinux = @'
ImportExcel Module Cannot Autosize. Please run the following command to install dependencies:
apt-get -y update && apt-get install -y --no-install-recommends libgdiplus libc6-dev
'@

NoAutoSizeMacOS = @'
ImportExcel Module Cannot Autosize. Please run the following command to install dependencies:
brew install mono-libgdiplus
'@

}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 1 addition & 2 deletions Public/New-PSItem.ps1 → ImportExcel/Public/New-PSItem.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '', Scope='Function', Target='New*', Justification='Does not change system State')]
param()
function New-PSItem {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '', Justification='Does not change system State')]
param()
$totalArgs = $args.Count

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '', Scope='Function', Target='Set*', Justification='Does not change system state')]
param()

function Set-CellComment {
function Set-CellComment {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '', Justification='Does not change system state')]
[CmdletBinding(DefaultParameterSetName = "Range")]
param(
[Parameter(Mandatory = $True, ParameterSetName = "ColumnLetter")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '', Scope='Function', Target='Set*', Justification='Does not change system state')]
param()

function Set-CellStyle {
function Set-CellStyle {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '', Justification='Does not change system state')]
[CmdletBinding()]
param(
$Worksheet,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '', Scope='Function', Target='Update*', Justification='Does not change system state')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '', Scope='Function', Target='Update*', Justification='Property would be incorrect')]

param()

function Update-FirstObjectProperties {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '', Justification='Does not change system state')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '', Justification='Property would be incorrect')]
[CmdletBinding()]
param (
[Parameter(ValueFromPipeline=$true)]
Expand Down
11 changes: 11 additions & 0 deletions ImportExcel/dot-sources.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This file contains relative paths of folders to be dot-sourced during
# development, but embedded in the tested and published .PSM1 file.
#
# Entries will be processed in order, leading and trailing whitespace will be
# ignored, and lines beginning with "#" will be treated as a comment.

Private
Public
Charting
InferData
Pivot
Loading
Loading