OSDN Git Service

add yarn-installer recipe to the nodejs_utils cookbook. nodejs_utils-0.2.0
authorwhitestar <whitestar@users.osdn.me>
Sun, 3 Mar 2019 09:25:49 +0000 (18:25 +0900)
committerwhitestar <whitestar@users.osdn.me>
Sun, 3 Mar 2019 09:25:49 +0000 (18:25 +0900)
12 files changed:
cookbooks/nodejs_utils/CHANGELOG.md
cookbooks/nodejs_utils/Gemfile.lock [new file with mode: 0644]
cookbooks/nodejs_utils/README.md
cookbooks/nodejs_utils/Rakefile
cookbooks/nodejs_utils/attributes/default.rb
cookbooks/nodejs_utils/chefignore [new file with mode: 0644]
cookbooks/nodejs_utils/concourse.yml
cookbooks/nodejs_utils/fly-vars.yml
cookbooks/nodejs_utils/recipes/yarn-installer.rb [new file with mode: 0644]
cookbooks/nodejs_utils/templates/default/usr/local/bin/yarn_install [new file with mode: 0644]
cookbooks/nodejs_utils/version
roles/nodejs-utils.rb [new file with mode: 0644]

index 0801015..9769554 100644 (file)
@@ -1,5 +1,9 @@
 # nodejs_utils CHANGELOG
 
+0.2.0
+-----
+- add yarn-installer recipe.
+
 0.1.0
 -----
 - Initial release.
diff --git a/cookbooks/nodejs_utils/Gemfile.lock b/cookbooks/nodejs_utils/Gemfile.lock
new file mode 100644 (file)
index 0000000..6fb9a3b
--- /dev/null
@@ -0,0 +1,22 @@
+GEM
+  remote: https://rubygems.org/
+  specs:
+    chef-api (0.8.0)
+      logify (~> 0.1)
+      mime-types
+    logify (0.2.0)
+    mime-types (3.2.2)
+      mime-types-data (~> 3.2015)
+    mime-types-data (3.2018.0812)
+    stove (6.0.0)
+      chef-api (~> 0.5)
+      logify (~> 0.2)
+
+PLATFORMS
+  ruby
+
+DEPENDENCIES
+  stove
+
+BUNDLED WITH
+   1.16.0
index 2b3a5c0..67a2e17 100644 (file)
@@ -1,7 +1,7 @@
 nodejs_utils Cookbook
 =====================
 
-This cookbook installs `n`, `nvm` (Node.js Version Managers) setup scripts.
+This cookbook installs `n`, `nvm` (Node.js Version Managers) and `yarn` setup scripts.
 
 ## Contents
 
@@ -15,6 +15,7 @@ This cookbook installs `n`, `nvm` (Node.js Version Managers) setup scripts.
         - [nodejs_utils::default](#nodejs_utilsdefault)
         - [nodejs_utils::n-installer](#nodejs_utilsn-installer)
         - [nodejs_utils::nvm-installer](#nodejs_utilsnvm-installer)
+        - [nodejs_utils::yarn-installer](#nodejs_utilsyarn-installer)
 - [License and Authors](#license-and-authors)
 
 ## Requirements
@@ -34,7 +35,8 @@ This cookbook installs `n`, `nvm` (Node.js Version Managers) setup scripts.
 
 |Key|Type|Description, example|Default|
 |:--|:--|:--|:--|
-|`['nodejs_utils']['nvm']['version']`|String|latest: 'master'|`'v0.33.6'`|
+|`['nodejs_utils']['nvm']['version']`|String|latest: 'master'|`'v0.33.11'`|
+|`['nodejs_utils']['yarn']['version']`|String||`'latest'`|
 
 ## Usage
 
@@ -52,12 +54,16 @@ This recipe installs the `n` setup script.
 
 This recipe installs the `nvm` setup script.
 
+#### nodejs_utils::nvm-installer
+
+This recipe installs the `yarn` setup script.
+
 ## License and Authors
 
 - Author:: whitestar at osdn.jp
 
 ```text
-Copyright 2017, whitestar
+Copyright 2017-2019, whitestar
 
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
index 8b85e6a..1ba86c6 100644 (file)
@@ -3,12 +3,58 @@ require 'rubocop/rake_task'
 require 'foodcritic'
 require 'stove/rake_task'
 
+tpl_cookbook = '00cookbook'
+cookbook_name = File.basename(Dir.pwd)
+
+desc 'Initialize project'
+task :init do
+  next if cookbook_name == tpl_cookbook
+
+  [
+    '.foodcritic',
+    '.rubocop.yml',
+    'Berksfile',
+    'chefignore',
+    'concourse.yml',
+    'fly-vars.yml',
+    'fly-vars.local.yml',
+    'Gemfile',
+    'Gemfile.lock',
+    'version',
+  ].each {|conf|
+    sh "cp ../#{tpl_cookbook}/#{conf} ./" unless File.exist?(conf)
+  }
+
+  ruby [
+    %(-pne '$_.gsub!(/^cookbook-name: .*$/, "cookbook-name: #{cookbook_name}")'),
+    '-i fly-vars.local.yml',
+  ].join(' ')
+end
+
+desc 'Update project'
+task :update do
+  next if cookbook_name == tpl_cookbook
+
+  [
+    'Rakefile',
+    'chefignore',
+    'concourse.yml',
+    'fly-vars.yml',
+    'Gemfile',
+    'Gemfile.lock',
+  ].each {|conf|
+    sh "cp ../#{tpl_cookbook}/#{conf} ./"
+  }
+end
+
+desc 'fly set-pipeline'
 task :'set-pipeline' do
   sh [
-    "fly -t $CC_TARGET sp -p #{File.basename(Dir.pwd)}-cookbook -c concourse.yml",
-    '-l fly-vars.yml -l ~/sec/credentials-prod.yml',
+    "fly -t $CC_TARGET sp -p #{cookbook_name}-cookbook -c concourse.yml",
+    '-l fly-vars.yml -l fly-vars.local.yml -l ~/sec/credentials-prod.yml',
   ].join(' ')
 end
+desc 'rake set-pipeline alias'
 task sp: 'set-pipeline'
 
 namespace :style do
index b5456fb..f176abb 100644 (file)
@@ -2,7 +2,7 @@
 # Cookbook Name:: nodejs_utils
 # Attributes:: default
 #
-# Copyright 2017, whitestar
+# Copyright 2017-2019, whitestar
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -17,4 +17,5 @@
 # limitations under the License.
 #
 
-default['nodejs_utils']['nvm']['version'] = 'v0.33.6'  # latest: 'master'
+default['nodejs_utils']['nvm']['version'] = 'v0.33.11'  # latest: 'master'
+default['nodejs_utils']['yarn']['version'] = 'latest'
diff --git a/cookbooks/nodejs_utils/chefignore b/cookbooks/nodejs_utils/chefignore
new file mode 100644 (file)
index 0000000..10e314a
--- /dev/null
@@ -0,0 +1,20 @@
+# Put files/directories that should be ignored in this file.
+# Lines that start with '# ' are comments.
+
+Berksfile.lock
+
+# concourse
+concourse.yml
+fly-vars.yml
+fly-vars.local.yml
+
+# emacs
+*~
+
+.rubocop_todo.yml
+
+# vim
+*.sw[a-z]
+
+# subversion
+*/.svn/*
index 72d436b..d373185 100644 (file)
@@ -1,5 +1,4 @@
 ---
-# $ fly -t $CC_TARGET sp -p nodejs_utils-cookbook -c concourse.yml -l fly-vars.yml -l ~/sec/credentials-prod.yml
 resources:
 - name: src-git
   type: git
index 949254d..76f2fcd 100644 (file)
@@ -1,3 +1,2 @@
 ---
-cookbook-name: nodejs_utils
 chefdk-version: 1.6.11
diff --git a/cookbooks/nodejs_utils/recipes/yarn-installer.rb b/cookbooks/nodejs_utils/recipes/yarn-installer.rb
new file mode 100644 (file)
index 0000000..6c9e712
--- /dev/null
@@ -0,0 +1,53 @@
+#
+# Cookbook Name:: nodejs_utils
+# Recipe:: yarn-installer
+#
+# Copyright 2019, whitestar
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+doc_url = 'https://yarnpkg.com/en/docs/'
+
+[
+  'curl',
+].each {|pkg|
+  resources(package: pkg) rescue package pkg do
+    action :install
+  end
+}
+
+[
+  'yarn_install',
+].each {|script|
+  template "/usr/local/bin/#{script}" do
+    source  "usr/local/bin/#{script}"
+    owner 'root'
+    group 'root'
+    mode '0755'
+    action :create
+  end
+}
+
+log 'yarn-installer post install message' do
+  message <<-"EOM"
+Note: You must execute the following command manually.
+    See #{doc_url}
+    * install yarn:
+      $ yarn_install
+      ...
+      $ source ~/.bashrc
+      $ yarn -v
+      1.13.0
+EOM
+end
diff --git a/cookbooks/nodejs_utils/templates/default/usr/local/bin/yarn_install b/cookbooks/nodejs_utils/templates/default/usr/local/bin/yarn_install
new file mode 100644 (file)
index 0000000..f4647a9
--- /dev/null
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+PATH=.:/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin
+
+<%
+yarn_ver = node['nodejs_utils']['yarn']['version']
+
+if yarn_ver == 'latest'
+-%>
+curl -o- -L https://yarnpkg.com/install.sh | bash
+<% else -%>
+curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version <%= yarn_ver %>
+<% end -%>
diff --git a/roles/nodejs-utils.rb b/roles/nodejs-utils.rb
new file mode 100644 (file)
index 0000000..c5caf24
--- /dev/null
@@ -0,0 +1,16 @@
+name 'nodejs-utils'
+description 'Node.js Setup Utilities'
+
+run_list(
+  'recipe[nodejs_utils::n-installer]',
+  'recipe[nodejs_utils::nvm-installer]',
+  'recipe[nodejs_utils::yarn-installer]',
+)
+
+#env_run_lists
+
+default_attributes(
+)
+
+override_attributes(
+)