AI-native design editor. Open-source Figma alternative.
Stabilize npm publishing workflow
Danila Poyarkove18c8660e3ed
diff --git a/.github/workflows/build.yml b/.github/workflows/build.ymlindex 8087ac0bf..051a589bb 100644--- a/.github/workflows/build.yml+++ b/.github/workflows/build.yml@@ -147,36 +147,81 @@ jobs:- run: bun install- - name: Resolve workspace dependencies- run: |- node -e "- const fs = require('fs');- const coreVersion = require('./packages/core/package.json').version;- for (const pkg of ['packages/cli', 'packages/mcp', 'packages/vue']) {- const path = pkg + '/package.json';- const json = JSON.parse(fs.readFileSync(path, 'utf8'));- for (const field of ['dependencies', 'devDependencies', 'peerDependencies']) {- if (!json[field]) continue;- for (const [name, version] of Object.entries(json[field])) {- if (typeof version === 'string' && version.startsWith('workspace:')) {- json[field][name] = '^' + coreVersion;- }- }- }- fs.writeFileSync(path, JSON.stringify(json, null, 2) + '\n');- console.log('Resolved workspace deps in', path, '→ ^' + coreVersion);- }- "-- name: Build packages for publishrun: |for dir in packages/core packages/mcp packages/vue; doif [ -f "$dir/package.json" ] && node -p "require('./$dir/package.json').scripts?.build" 2>/dev/null | grep -qv undefined; thenecho "Building $dir..."- cd "$dir" && bun run build && cd -+ (cd "$dir" && bun run build)fidone+ - name: Prepare publish directories+ run: |+ node - <<'NODE'+ const fs = require('fs')+ const path = require('path')++ const root = process.cwd()+ const outRoot = path.join(root, '.publish')+ const coreVersion = require('./packages/core/package.json').version++ fs.rmSync(outRoot, { recursive: true, force: true })+ fs.mkdirSync(outRoot, { recursive: true })++ const copyRecursive = (from, to) => {+ const stat = fs.statSync(from)+ if (stat.isDirectory()) {+ fs.mkdirSync(to, { recursive: true })+ for (const entry of fs.readdirSync(from)) {+ copyRecursive(path.join(from, entry), path.join(to, entry))+ }+ return+ }+ fs.mkdirSync(path.dirname(to), { recursive: true })+ fs.copyFileSync(from, to)+ }++ const packages = [+ { dir: 'packages/core', include: ['dist', 'src', 'assets'], extraFiles: [] },+ { dir: 'packages/cli', include: ['src'], extraFiles: [] },+ { dir: 'packages/mcp', include: ['dist'], extraFiles: [] },+ { dir: 'packages/vue', include: ['dist'], extraFiles: ['README.md'] }+ ]++ for (const pkg of packages) {+ const srcDir = path.join(root, pkg.dir)+ const destDir = path.join(outRoot, path.basename(pkg.dir))+ fs.mkdirSync(destDir, { recursive: true })++ for (const rel of pkg.include) {+ const from = path.join(srcDir, rel)+ if (fs.existsSync(from)) copyRecursive(from, path.join(destDir, rel))+ }++ for (const rel of pkg.extraFiles) {+ const from = path.join(srcDir, rel)+ if (fs.existsSync(from)) copyRecursive(from, path.join(destDir, rel))+ }++ const pkgJsonPath = path.join(srcDir, 'package.json')+ const json = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf8'))+ for (const field of ['dependencies', 'devDependencies', 'peerDependencies']) {+ if (!json[field]) continue+ for (const [name, version] of Object.entries(json[field])) {+ if (typeof version === 'string' && version.startsWith('workspace:')) {+ json[field][name] = '^' + coreVersion+ }+ }+ }+ delete json.scripts+ delete json.devDependencies+ fs.writeFileSync(path.join(destDir, 'package.json'), JSON.stringify(json, null, 2) + '\n')+ console.log(`Prepared ${destDir}`)+ }+ NODE+ find .publish -maxdepth 3 -type f | sort+- name: Pack packages for publishrun: |mkdir -p .npm-packages@@ -184,17 +229,21 @@ jobs:local dir=$1local name=$(node -p "require('./$dir/package.json').name")local version=$(node -p "require('./$dir/package.json').version")+ local publish_dir=".publish/$(basename "$dir")"if npm view "${name}@${version}" version 2>/dev/null; thenecho "${name}@${version} already published, skipping pack"else- (cd "$dir" && npm pack --pack-destination ../../.npm-packages)+ (cd "$publish_dir" && npm pack --pack-destination "$root_dir/.npm-packages")fi}+ root_dir="$PWD"pack_if_new packages/corepack_if_new packages/clipack_if_new packages/mcppack_if_new packages/vuels -la .npm-packages+ tar -tf .npm-packages/open-pencil-mcp-*.tgz | sed -n '1,40p' || true+ tar -tf .npm-packages/open-pencil-vue-*.tgz | sed -n '1,60p' || true- name: Publish packages to npmrun: |