Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/publish-prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ jobs:
env:
DISPLAY: ':99.0'

- name: Set preview to true
run: npm run set-preview:true

- name: Package extension (pre-release)
run: npm run vsce:package:prerelease

Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ jobs:
env:
DISPLAY: ':99.0'

- name: Set preview to false
run: npm run set-preview:false

- name: Package extension
run: npm run vsce:package

Expand Down
42 changes: 36 additions & 6 deletions docs/publishing.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,15 @@ Before you can use the publishing workflow, you need to set up the following:
1. **Checkout**: Gets the latest code
2. **Setup**: Installs Node.js and dependencies
3. **Quality Checks**: Runs linting and tests
4. **Version Bump**: Automatically increments the version number
5. **Build**: Compiles the TypeScript code
6. **Package**: Creates a `.vsix` file
7. **Publish**: (if not dry run) Publishes to VS Code Marketplace
8. **Git Operations**: (if not dry run) Commits version bump and creates a tag
9. **GitHub Release**: (if not dry run) Creates a GitHub release with the `.vsix` file
4. **Preview Control**: Sets the `preview` field in `package.json` appropriately:
- **Pre-release workflow**: Sets `preview: true`
- **Release workflow**: Sets `preview: false`
5. **Version Bump**: Automatically increments the version number
6. **Build**: Compiles the TypeScript code
7. **Package**: Creates a `.vsix` file
8. **Publish**: (if not dry run) Publishes to VS Code Marketplace
9. **Git Operations**: (if not dry run) Commits version bump and creates a tag
10. **GitHub Release**: (if not dry run) Creates a GitHub release with the `.vsix` file

### Dry Run Mode

Expand All @@ -81,6 +84,33 @@ The workflow automatically manages version numbers:
- Creates a Git tag
- Commits the changes back to the main branch

## Preview Control

The extension supports both preview and stable releases through the `preview` field in `package.json`:

- **Preview releases** (pre-release workflow): Extensions marked as preview appear with a "Preview" badge in the marketplace
- **Stable releases** (release workflow): Extensions without the preview flag are considered stable

### Manual Preview Control

You can also manually control the preview setting using npm scripts:

```bash
# Set preview to true
npm run set-preview:true

# Set preview to false
npm run set-preview:false

# Or pass the value directly
npm run set-preview true
npm run set-preview false
```

The workflows automatically set this value:
- **Pre-release workflow**: Sets `preview: true` before packaging
- **Release workflow**: Sets `preview: false` before packaging

## Troubleshooting

### Common Issues
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"publisher": "guidozam",
"license": "MIT",
"icon": "assets/icon.png",
"preview": false,
"galleryBanner": {
"color": "#186968",
"textColor": "#ffffff",
Expand Down Expand Up @@ -57,6 +58,9 @@
"lint": "npx eslint src --ext ts",
"test": "node ./out/test/runTest.js",
"test:ci": "xvfb-run -a node ./out/test/runTest.js",
"set-preview": "node scripts/set-preview.js",
"set-preview:true": "node scripts/set-preview.js true",
"set-preview:false": "node scripts/set-preview.js false",
"vsce:package": "vsce package",
"vsce:package:prerelease": "vsce package --pre-release",
"vsce:publish": "vsce publish",
Expand All @@ -83,4 +87,4 @@
"dependencies": {
"semver": "^7.5.4"
}
}
}
53 changes: 53 additions & 0 deletions scripts/set-preview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env node

const fs = require('fs');
const path = require('path');

/**
* Script to set the 'preview' field in package.json
* Usage: node set-preview.js [true|false]
*/

function setPreview(value) {
const packageJsonPath = path.join(process.cwd(), 'package.json');

if (!fs.existsSync(packageJsonPath)) {
console.error('Error: package.json not found in current directory');
process.exit(1);
}

try {
// Read package.json
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));

// Set preview value
packageJson.preview = value;

// Write back to package.json with proper formatting
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, '\t') + '\n');

console.log(`Successfully set preview to ${value} in package.json`);
} catch (error) {
console.error(`Error updating package.json: ${error.message}`);
process.exit(1);
}
}

// Parse command line arguments
const args = process.argv.slice(2);

if (args.length !== 1) {
console.error('Usage: node set-preview.js [true|false]');
process.exit(1);
}

const previewValue = args[0].toLowerCase();

if (previewValue === 'true') {
setPreview(true);
} else if (previewValue === 'false') {
setPreview(false);
} else {
console.error('Error: Argument must be either "true" or "false"');
process.exit(1);
}