Skip to content

Commit e84f19d

Browse files
authored
Initial commit
0 parents  commit e84f19d

7 files changed

Lines changed: 234 additions & 0 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Publish extension to phcode.dev extension store
2+
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#release
3+
on:
4+
release:
5+
types:
6+
- edited
7+
- published
8+
9+
jobs:
10+
build-tasks:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Dump GitHub context
14+
id: github_context_step
15+
run: echo '${{ toJSON(github) }}'
16+
- name: release details
17+
run: |
18+
echo "$GITHUB_REF repo=${{github.event.repository.full_name}}"
19+
curl --fail-with-body https://publish.phcode.dev/publishGithubRelease?releaseRef=${{github.event.repository.full_name}}:$GITHUB_REF
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
Mainly used to setup repository default pacakge.json contents.
3+
You may delete this file after repo creation if not already deleted by the template setup scripts.
4+
*/
5+
6+
const fs = require('fs');
7+
let github, context, org, repoName;
8+
// Include fs module
9+
10+
function _isValidRepoInitEvent(){
11+
// create event is triggered whenever a new branch is created in the repo. so we do a hack that if the master branch
12+
// of the repo is created, we consider it as repo creation as master branch is created only on repo create. This
13+
// should work all the time on create from template and most of the time on external creation.
14+
if(context.eventName !== 'create'){
15+
return false;
16+
}
17+
if(!context.ref.endsWith(`/${context.payload.master_branch}`)){
18+
return false;
19+
}
20+
return true;
21+
}
22+
23+
function setupPackageJSON() {
24+
let data = JSON.parse(fs.readFileSync('./package.json', {encoding:'utf8', flag:'r'}));
25+
data.name = `gh-${org}-${repoName}`;
26+
data.description = context.payload.repository.description || "A simple phcode.dev extension/theme.";
27+
data.title = repoName;
28+
data.license = context.payload.repository.license && context.payload.repository.license.name || "unknown";
29+
data.author = `${context.payload.repository.owner.login}`;
30+
data.homepage = context.payload.repository.html_url;
31+
data.version = "0.0.1";
32+
33+
fs.writeFileSync('./package.json', JSON.stringify(data, null, 4));
34+
console.log("package.json file written successfully\n", data);
35+
}
36+
37+
async function verifyRepoIsPublic() {
38+
if(!context.payload.repository.private){
39+
console.log("Repository is public, all good.");
40+
return;
41+
}
42+
console.log("Repository must be public to publish",
43+
`Repository must be public to publish the extension to the extension store.\n
44+
If you want to create a private source extension, create another public repo just to create releases an publich the extension without making the source code public.`
45+
);
46+
}
47+
48+
async function initRepo(details){
49+
github = details.github;
50+
context = details.context;
51+
org = details.org;
52+
repoName = details.repoName;
53+
console.log("github: ", JSON.stringify(github, null, 4));
54+
console.log("context: ", JSON.stringify(context, null, 4));
55+
if(!_isValidRepoInitEvent()){
56+
console.log("Not a valid repo creation event. This task is only meant to be executed at repo creation. Exiting!");
57+
return;
58+
}
59+
setupPackageJSON();
60+
verifyRepoIsPublic();
61+
62+
// cleanup
63+
fs.unlinkSync('./.github/workflows/setupRepository.cjs');
64+
fs.unlinkSync('./.github/workflows/setupRepository.yml');
65+
}
66+
67+
module.exports.initRepo = initRepo;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Setup and Init repository after create from template.
2+
# only to be run once. You may delete this file after the repo is created from template
3+
4+
on:
5+
create:
6+
7+
jobs:
8+
setup_repository:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
# Give the default GITHUB_TOKEN write permission to commit and push the
12+
# added or changed files to the repository.
13+
contents: write
14+
steps:
15+
- uses: actions/checkout@v3
16+
- uses: actions/github-script@v6
17+
with:
18+
script: |
19+
console.log("Setting up the repository", context);
20+
const org = context.payload.repository.owner.login;
21+
const repoName = context.payload.repository.name;
22+
const setupScript = require('.github/workflows/setupRepository.cjs');
23+
setupScript.initRepo({github, context, org, repoName});
24+
- uses: stefanzweifel/git-auto-commit-action@v4

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Phoenix Code
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Extension Template
2+
3+
Quick start and create a new extension by using this template. Follow the below 4 steps:
4+
5+
Refer this [link](https://github.com/phcode-dev/phoenix/wiki/How-To-Write-Extensions-And-Themes) for detailed extension docs after following the below steps:
6+
7+
## step 1
8+
9+
Login with github: https://github.com/login
10+
11+
## step 2
12+
13+
Create a new repository using this template.
14+
![New extension from template](https://user-images.githubusercontent.com/5336369/223931565-2708e516-a422-4e7b-9d89-9ac48c919c3d.gif)
15+
16+
## step 3
17+
18+
* Clone your GitHub Repo created from `step 2`. See [this link](https://docs.github.com/en/repositories/creating-and-managing-repositories/cloning-a-repository) to lean how to clone a repository from GitHub.
19+
20+
## step 4
21+
22+
* Go to https://create.phcode.dev .This is a special development centric website of phcode.dev which shows non minified js/css files in the browser developer tools.
23+
* Open the cloned folder and select `Debug > Load Project As Extension`
24+
25+
![image](https://user-images.githubusercontent.com/5336369/224746152-0416a862-891a-4fe1-b9dd-09add25a6cc0.png)
26+
27+
28+
* You can now make code changes to your extension and select `Debug> Reload With Extensions` to test the new code changes.
29+
* When you are done developing the extension/theme, select `Debug> Unload Project As Extension` to unload the extension.
30+
31+
![image](https://user-images.githubusercontent.com/5336369/224747590-556dff1d-5b29-41c3-88a0-3ce72ab643d0.png)
32+
33+
# Detailed Documentation
34+
35+
Please go to https://github.com/phcode-dev/phoenix/wiki/How-To-Write-Extensions-And-Themes for more documentation/community support links.
36+
37+
# Publishing your extension to the repository
38+
39+
Once you have built your extension/theme, you can publish the extension to phcode.dev extension repository in a single step directly from this repo.
40+
Please see publish section in this link for more details: https://github.com/phcode-dev/phoenix/wiki/How-To-Write-Extensions-And-Themes

main.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*global define, brackets, $ */
2+
3+
// See detailed docs in https://github.com/phcode-dev/phoenix/wiki/How-To-Write-Extensions-And-Themes
4+
// A good place to look for code examples for extensions: https://github.com/phcode-dev/phoenix/tree/main/src/extensions/default
5+
6+
// A simple extension that adds an entry in "file menu> hello world"
7+
define(function (require, exports, module) {
8+
"use strict";
9+
10+
// Brackets modules
11+
const AppInit = brackets.getModule("utils/AppInit"),
12+
DefaultDialogs = brackets.getModule("widgets/DefaultDialogs"),
13+
Dialogs = brackets.getModule("widgets/Dialogs"),
14+
CommandManager = brackets.getModule("command/CommandManager"),
15+
Menus = brackets.getModule("command/Menus");
16+
17+
// Function to run when the menu item is clicked
18+
function handleHelloWorld() {
19+
Dialogs.showModalDialog(
20+
DefaultDialogs.DIALOG_ID_INFO,
21+
"hello",
22+
"world"
23+
);
24+
}
25+
26+
// First, register a command - a UI-less object associating an id to a handler
27+
var MY_COMMAND_ID = "helloworld.sayhello"; // package-style naming to avoid collisions
28+
CommandManager.register("Hello World", MY_COMMAND_ID, handleHelloWorld);
29+
30+
// Then create a menu item bound to the command
31+
// The label of the menu item is the name we gave the command (see above)
32+
var menu = Menus.getMenu(Menus.AppMenuBar.FILE_MENU);
33+
menu.addMenuItem(MY_COMMAND_ID);
34+
35+
// We could also add a key binding at the same time:
36+
//menu.addMenuItem(MY_COMMAND_ID, "Ctrl-Alt-W");
37+
// (Note: "Ctrl" is automatically mapped to "Cmd" on Mac)
38+
39+
// Initialize extension once shell is finished initializing.
40+
AppInit.appReady(function () {
41+
console.log("hello world");
42+
});
43+
});

package.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"title": "Name of the extension",
3+
"name": "github-<owner>-<repo>",
4+
"description": "A sample extension.",
5+
"version": "0.0.1",
6+
"license": "MIT",
7+
"author": "your name (https://github.com/<your github id>)",
8+
"homepage": "<project web page url or this github repo url if no website available>",
9+
"engines": {
10+
"brackets": ">=2.0.0"
11+
},
12+
"categories": "demo",
13+
"keywords": [
14+
"phcode", "extension", "demo"
15+
],
16+
"files": [
17+
"main.js"
18+
]
19+
}
20+

0 commit comments

Comments
 (0)