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

feat(wip): components monorepo #1082

Merged
merged 4 commits into from Jun 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions .eslintignore
@@ -1,3 +1,2 @@
node_modules
packages/*/coverage
webpack.config.js
scripts
34 changes: 34 additions & 0 deletions .github/workflows/publish.yml
@@ -0,0 +1,34 @@
name: Publish

on:
push:
branches: [ main ]
workflow_dispatch:

jobs:
publish:
if: contains(github.event.head_commit.message, 'chore(release)') == false

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: actions/setup-node@v1
with:
node-version: '16.x'
registry-url: 'https://registry.npmjs.org'
- run: yarn install --pure-lockfile
- run: yarn build
- name: Setup git config
run: |
git config --global user.name "standardci"
git config --global user.email "ci@standardnotes.com"
- name: Import GPG key
uses: crazy-max/ghaction-import-gpg@v4
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.PASSPHRASE }}
git_user_signingkey: true
git_commit_gpgsign: true
- run: yarn version-bump
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -17,7 +17,7 @@ packages/web-server/vendor

packages/web/dist

/.sass-cache
.sass-cache

.env
.ssh
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
@@ -1,2 +1,3 @@
.github
codeqldb
CHANGELOG.md
7 changes: 7 additions & 0 deletions packages/components/dist/Checksums.json
@@ -0,0 +1,7 @@
{
"org.standardnotes.theme-autobiography": {
"version": "1.0.4",
"base64": "b1df118550bca4ef10b6f8eaeeeddb051cde8171212c5a73a577c834d331725f",
"binary": "8cf9b21daea61b41bde70bfd6a7a4fcb1a8cf5539da52a7f7bcd48f2faa1c748"
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
@@ -0,0 +1,26 @@
{
"name": "@standardnotes/autobiography-theme",
"version": "1.0.4",
"main": "dist/dist.css",
"devDependencies": {
"grunt": "^1.0.1",
"grunt-contrib-sass": "^1.0.0",
"grunt-contrib-watch": "^1.0.0",
"grunt-newer": "^1.2.0"
},
"scripts": {
"build": "grunt",
"prepublishOnly": "yarn run build"
},
"sn": {
"main": "dist/dist.css"
},
"repository": {
"type": "git",
"url": "git://github.com/standardnotes/autobiography-theme.git"
},
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org/"
}
}
4 changes: 4 additions & 0 deletions packages/components/lerna.json
@@ -0,0 +1,4 @@
{
"packages": ["src/*"],
"useWorkspaces": true
}
22 changes: 22 additions & 0 deletions packages/components/package.json
@@ -0,0 +1,22 @@
{
"name": "@standardnotes/components-meta",
"version": "0.0.1",
"private": true,
"workspaces": {
"packages": [
"src/*"
]
},
"scripts": {
"preversion": "lerna run build --parallel",
"version": "node scripts/package-components.mjs"
},
"dependencies": {
"@standardnotes/autobiography-theme": "1.0.4"
},
"devDependencies": {
"@standardnotes/deterministic-zip": "^1.2.0",
"@standardnotes/features": "^1.45.1",
"lerna": "*"
}
}
149 changes: 149 additions & 0 deletions packages/components/scripts/package-components.mjs
@@ -0,0 +1,149 @@
import fs from 'fs'
import path from 'path'
import crypto from 'crypto'
import { spawnSync as spawn } from 'child_process'
import { GetFeatures } from '@standardnotes/features/dist/Domain/Feature/Features.js'
import { GetDeprecatedFeatures } from '@standardnotes/features/dist/Domain/Feature/Lists/DeprecatedFeatures.js'
import zip from '@standardnotes/deterministic-zip'

console.log('Beginning packaging procedure...')

const specificFeatureIdentifier = process.argv[2]
if (specificFeatureIdentifier) {
console.log('Processing only', specificFeatureIdentifier)
}

const SOURCE_FILES_PATH = 'src'
const DistDir = path.join('dist')

const ChecksumsSrcPath = path.join(DistDir, 'Checksums.json')
const ChecksumsDistPath = path.join(DistDir, 'Checksums.json')
const Checksums = JSON.parse(fs.readFileSync(ChecksumsSrcPath).toString())
console.log('Loaded existing checksums from', ChecksumsSrcPath)

async function zipDirectory(sourceDir, outPath) {
return new Promise((resolve) => {
zip(sourceDir, outPath, { cwd: sourceDir }, (err) => {
console.log(`Zipped to ${outPath}`)
resolve(outPath)
})
})
}

const copyFileOrDir = (src, dest) => {
const isDir = fs.lstatSync(src).isDirectory()
if (isDir) {
ensureDirExists(dest)
const entries = fs.readdirSync(src, { withFileTypes: true })

for (const entry of entries) {
const srcPath = path.join(src, entry.name)
const destPath = path.join(dest, entry.name)

entry.isDirectory() ? copyFileOrDir(srcPath, destPath) : fs.copyFileSync(srcPath, destPath)
}
} else {
fs.copyFileSync(src, dest)
}
}

const doesDirExist = (dir) => {
return fs.existsSync(dir)
}

const ensureDirExists = (dir) => {
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true })
}
}

const emptyExistingDir = (dir) => {
if (fs.existsSync(dir)) {
fs.rmSync(dir, { recursive: true })
}
}

const copyToDist = async (feature) => {
const srcComponentPath = path.join(SOURCE_FILES_PATH, feature.identifier)

if (!doesDirExist(srcComponentPath)) {
return
}

const targetComponentPath = `${path.join(DistDir, feature.identifier)}`

emptyExistingDir(targetComponentPath)
ensureDirExists(targetComponentPath)

for (const file of feature.static_files) {
const srcFilePath = path.join(srcComponentPath, file)

if (!fs.existsSync(srcFilePath)) {
continue
}

const targetFilePath = path.join(targetComponentPath, file)
copyFileOrDir(srcFilePath, targetFilePath)
}

return targetComponentPath
}

const computeChecksum = async (zipPath, version) => {
const zipData = fs.readFileSync(zipPath, 'base64')
const base64 = crypto.createHash('sha256').update(zipData).digest('hex')
const checksumProcess = spawn('sha256sum', [zipPath])
const checksumString = checksumProcess.stdout.toString()
const binary = checksumString.split(' ')[0]
return {
version,
base64,
binary,
}
}

const zipAndChecksumFeature = async (feature) => {
console.log('Processing feature', feature.identifier, '...')

const distPath = await copyToDist(feature)

if (!distPath) {
return
}

const outZip = `${distPath}/${feature.identifier}.zip`
await zipDirectory(distPath, outZip)

const checksum = await computeChecksum(outZip, feature.version)
Checksums[feature.identifier] = checksum
console.log(`Computed checksums for ${feature.identifier}:`, checksum)
}

await (async () => {
const featuresToProcess = specificFeatureIdentifier
? [GetFeatures().find((feature) => feature.identifier === specificFeatureIdentifier)]
: GetFeatures().concat(GetDeprecatedFeatures())

let index = 0
for (const feature of featuresToProcess) {
if (index === 0) {
console.log('\n---\n')
}

if (feature.download_url) {
await zipAndChecksumFeature(feature)
} else {
console.log('Feature does not have download_url, not packaging', feature.identifier)
}

if (index !== featuresToProcess.length - 1) {
console.log('\n---\n')
}

index++
}

fs.writeFileSync(ChecksumsSrcPath, JSON.stringify(Checksums, undefined, 2))
console.log('Succesfully wrote checksums to', ChecksumsSrcPath)
copyFileOrDir(ChecksumsSrcPath, ChecksumsDistPath)
})()
@@ -0,0 +1 @@
dist
@@ -0,0 +1,31 @@
module.exports = function(grunt) {

grunt.initConfig({
watch: {
css: {
files: ['src/**/*.scss'],
tasks: ['sass'],
options: {
spawn: false,
},
}
},

sass: {
dist: {
options: {
style: 'expanded'
},
files: {
'dist/dist.css': 'src/main.scss'
}
}
},
});

grunt.loadNpmTasks('grunt-newer');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-sass');

grunt.registerTask('default', ['sass']);
};
@@ -0,0 +1 @@
# Autobiography Theme
@@ -0,0 +1,19 @@
{
"name": "@standardnotes/autobiography-theme",
"version": "1.0.4",
"main": "dist/dist.css",
"private": true,
"scripts": {
"build": "grunt",
"prepublishOnly": "yarn run build"
},
"sn": {
"main": "dist/dist.css"
},
"devDependencies": {
"grunt": "^1.0.1",
"grunt-contrib-sass": "^1.0.0",
"grunt-contrib-watch": "^1.0.0",
"grunt-newer": "^1.2.0"
}
}