create-a-theme-checklist.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. const theme = process.argv[ 2 ];
  2. if ( ! theme ) {
  3. console.error( '\x1b[41m', 'You must specify a theme!' );
  4. return;
  5. }
  6. /**
  7. * We need a Github personal access token to continue.
  8. *
  9. * The most robust way is to add an environment variable to your ~/.bashrc or ~/.zshrc depending on the shell you're using. To check which shell you're using, run `echo $SHELL` in a terminal.
  10. *
  11. * The environment variable in your shell rc should look like this:
  12. * export THEME_GITHUB_TOKEN=<insert your token>
  13. *
  14. * Alternatively, you can replace `PUT YOUR ACCESS TOKEN HERE` with the actual access token value.
  15. */
  16. const octokit = new Octokit( {
  17. auth: process.env.THEME_GITHUB_TOKEN || `PUT YOUR ACCESS TOKEN HERE`,
  18. } );
  19. function sleep( ms ) {
  20. return new Promise( ( resolve ) => {
  21. setTimeout( resolve, ms );
  22. } );
  23. }
  24. async function createLabel() {
  25. try {
  26. await sleep( 1000 );
  27. return await octokit.request( 'POST /repos/Automattic/themes/labels', {
  28. name: '[Theme] ' + theme,
  29. color: 'c1f4a1',
  30. description: 'Automatically generated label for ' + theme + '.',
  31. } );
  32. } catch ( error ) {
  33. console.log( error );
  34. }
  35. }
  36. async function createMilestone() {
  37. try {
  38. await sleep( 1000 );
  39. return await octokit.request(
  40. 'POST /repos/Automattic/themes/milestones',
  41. {
  42. title: theme,
  43. description:
  44. 'Automatically generated milestone for ' + theme + '.',
  45. }
  46. );
  47. } catch ( error ) {
  48. console.error( '\x1b[41m', 'Milestone already created.' );
  49. }
  50. }
  51. async function createIssues( milestoneNumber ) {
  52. const issues = [
  53. 'Block Patterns',
  54. 'Create Base Theme',
  55. 'Styles: Colors',
  56. 'Styles: Typography — Fonts & Weights',
  57. 'Styles: Typography — Sizes & Line Height',
  58. 'Styles: Links',
  59. 'Styles: Buttons',
  60. 'Styles: Layout',
  61. 'Styles: Comments',
  62. 'Styles: Navigation',
  63. 'Styles: Quote',
  64. 'Styles: Variations',
  65. 'Templates: Search, Category, Tag',
  66. 'Templates: 404',
  67. 'Templates: Single',
  68. 'Templates: Page',
  69. 'Templates: Index',
  70. 'Templates: Header template part',
  71. 'Templates: Footer template part',
  72. 'Pre-launch: Screenshot, readme.txt & description',
  73. 'Pre-launch: Demo Site',
  74. 'Pre-launch: Showcase Entry',
  75. 'Pre-launch: Headstart Annotation',
  76. ];
  77. issues.forEach( async ( issue ) => {
  78. try {
  79. await sleep( 1000 );
  80. return await octokit.request(
  81. 'POST /repos/Automattic/themes/issues',
  82. {
  83. title: theme + ': ' + issue,
  84. labels: [ '[Theme] ' + theme ],
  85. milestone: milestoneNumber,
  86. }
  87. );
  88. // If you want to automatically add this to the Theme Dev Board, uncomment this.
  89. // .then( ( issueData ) => {
  90. // addIssueToProject( issueData );
  91. // } );
  92. } catch ( error ) {
  93. console.log( error );
  94. }
  95. } );
  96. }
  97. async function addIssueToProject( issueData ) {
  98. try {
  99. await sleep( 1000 );
  100. return await octokit.request( 'POST /projects/columns/11021541/cards', {
  101. note: null,
  102. content_id: issueData.data.id,
  103. content_url: issueData.data.url,
  104. content_type: 'Issue',
  105. mediaType: {
  106. previews: [ 'inertia' ],
  107. },
  108. } );
  109. } catch ( error ) {
  110. console.log( error );
  111. }
  112. }
  113. createLabel().then( () => {
  114. createMilestone().then( ( milestoneData ) => {
  115. const milestoneNumber = milestoneData.data.number;
  116. createIssues( milestoneNumber );
  117. } );
  118. } );